From 2bc8797fed3b44cd9d3c60eec718f5a46032ef61 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:11:59 -0500 Subject: [PATCH] refactor: NotificationPresenter::Create() returns a std::unique_ptr<> (#43806) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/electron_browser_client.cc | 5 ++--- .../notifications/linux/notification_presenter_linux.cc | 8 ++++---- .../notifications/mac/notification_presenter_mac.mm | 4 ++-- shell/browser/notifications/notification_presenter.h | 3 ++- .../notifications/win/notification_presenter_win.cc | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/shell/browser/electron_browser_client.cc b/shell/browser/electron_browser_client.cc index d24127895c1..3441ac66ba1 100644 --- a/shell/browser/electron_browser_client.cc +++ b/shell/browser/electron_browser_client.cc @@ -963,9 +963,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(); } diff --git a/shell/browser/notifications/linux/notification_presenter_linux.cc b/shell/browser/notifications/linux/notification_presenter_linux.cc index adcdb5f8a3b..96b04604bed 100644 --- a/shell/browser/notifications/linux/notification_presenter_linux.cc +++ b/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::Create() { + if (LibnotifyNotification::Initialize()) + return std::make_unique(); + return {}; } NotificationPresenterLinux::NotificationPresenterLinux() = default; diff --git a/shell/browser/notifications/mac/notification_presenter_mac.mm b/shell/browser/notifications/mac/notification_presenter_mac.mm index 3d735916708..88877ae3fa8 100644 --- a/shell/browser/notifications/mac/notification_presenter_mac.mm +++ b/shell/browser/notifications/mac/notification_presenter_mac.mm @@ -12,8 +12,8 @@ namespace electron { // static -NotificationPresenter* NotificationPresenter::Create() { - return new NotificationPresenterMac; +std::unique_ptr NotificationPresenter::Create() { + return std::make_unique(); } CocoaNotification* NotificationPresenterMac::GetNotification( diff --git a/shell/browser/notifications/notification_presenter.h b/shell/browser/notifications/notification_presenter.h index b29dd2a4dc8..6058a82c6f4 100644 --- a/shell/browser/notifications/notification_presenter.h +++ b/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 #include #include @@ -17,7 +18,7 @@ class NotificationDelegate; class NotificationPresenter { public: - static NotificationPresenter* Create(); + static std::unique_ptr Create(); virtual ~NotificationPresenter(); diff --git a/shell/browser/notifications/win/notification_presenter_win.cc b/shell/browser/notifications/win/notification_presenter_win.cc index 407250614d3..965ef45c9b2 100644 --- a/shell/browser/notifications/win/notification_presenter_win.cc +++ b/shell/browser/notifications/win/notification_presenter_win.cc @@ -46,17 +46,17 @@ bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { } // namespace // static -NotificationPresenter* NotificationPresenter::Create() { +std::unique_ptr NotificationPresenter::Create() { if (!WindowsToastNotification::Initialize()) - return nullptr; + return {}; auto presenter = std::make_unique(); if (!presenter->Init()) - return nullptr; + return {}; if (IsDebuggingNotifications()) LOG(INFO) << "Successfully created Windows notifications presenter"; - return presenter.release(); + return presenter; } NotificationPresenterWin::NotificationPresenterWin() = default;