Browse Source

refactor: NotificationPresenter::Create() returns a std::unique_ptr<> (#43804)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <[email protected]>
trop[bot] 7 months ago
parent
commit
3ee3844bdb

+ 2 - 3
shell/browser/electron_browser_client.cc

@@ -967,9 +967,8 @@ ElectronBrowserClient::CreateDevToolsManagerDelegate() {
 }
 
 NotificationPresenter* ElectronBrowserClient::GetNotificationPresenter() {
-  if (!notification_presenter_) {
-    notification_presenter_.reset(NotificationPresenter::Create());
-  }
+  if (!notification_presenter_)
+    notification_presenter_ = NotificationPresenter::Create();
   return notification_presenter_.get();
 }
 

+ 4 - 4
shell/browser/notifications/linux/notification_presenter_linux.cc

@@ -10,10 +10,10 @@
 namespace electron {
 
 // static
-NotificationPresenter* NotificationPresenter::Create() {
-  if (!LibnotifyNotification::Initialize())
-    return nullptr;
-  return new NotificationPresenterLinux;
+std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() {
+  if (LibnotifyNotification::Initialize())
+    return std::make_unique<NotificationPresenterLinux>();
+  return {};
 }
 
 NotificationPresenterLinux::NotificationPresenterLinux() = default;

+ 2 - 2
shell/browser/notifications/mac/notification_presenter_mac.mm

@@ -17,8 +17,8 @@
 namespace electron {
 
 // static
-NotificationPresenter* NotificationPresenter::Create() {
-  return new NotificationPresenterMac;
+std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() {
+  return std::make_unique<NotificationPresenterMac>();
 }
 
 CocoaNotification* NotificationPresenterMac::GetNotification(

+ 2 - 1
shell/browser/notifications/notification_presenter.h

@@ -5,6 +5,7 @@
 #ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_PRESENTER_H_
 #define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_PRESENTER_H_
 
+#include <memory>
 #include <set>
 #include <string>
 
@@ -17,7 +18,7 @@ class NotificationDelegate;
 
 class NotificationPresenter {
  public:
-  static NotificationPresenter* Create();
+  static std::unique_ptr<NotificationPresenter> Create();
 
   virtual ~NotificationPresenter();
 

+ 4 - 4
shell/browser/notifications/win/notification_presenter_win.cc

@@ -43,17 +43,17 @@ bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) {
 }  // namespace
 
 // static
-NotificationPresenter* NotificationPresenter::Create() {
+std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() {
   if (!WindowsToastNotification::Initialize())
-    return nullptr;
+    return {};
   auto presenter = std::make_unique<NotificationPresenterWin>();
   if (!presenter->Init())
-    return nullptr;
+    return {};
 
   if (IsDebuggingNotifications())
     LOG(INFO) << "Successfully created Windows notifications presenter";
 
-  return presenter.release();
+  return presenter;
 }
 
 NotificationPresenterWin::NotificationPresenterWin() = default;