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 <charles@charleskerr.com>
This commit is contained in:
		
					parent
					
						
							
								78ede09ecd
							
						
					
				
			
			
				commit
				
					
						3ee3844bdb
					
				
			
		
					 5 changed files with 14 additions and 14 deletions
				
			
		|  | @ -967,9 +967,8 @@ ElectronBrowserClient::CreateDevToolsManagerDelegate() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| NotificationPresenter* ElectronBrowserClient::GetNotificationPresenter() { | NotificationPresenter* ElectronBrowserClient::GetNotificationPresenter() { | ||||||
|   if (!notification_presenter_) { |   if (!notification_presenter_) | ||||||
|     notification_presenter_.reset(NotificationPresenter::Create()); |     notification_presenter_ = NotificationPresenter::Create(); | ||||||
|   } |  | ||||||
|   return notification_presenter_.get(); |   return notification_presenter_.get(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -10,10 +10,10 @@ | ||||||
| namespace electron { | namespace electron { | ||||||
| 
 | 
 | ||||||
| // static
 | // static
 | ||||||
| NotificationPresenter* NotificationPresenter::Create() { | std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() { | ||||||
|   if (!LibnotifyNotification::Initialize()) |   if (LibnotifyNotification::Initialize()) | ||||||
|     return nullptr; |     return std::make_unique<NotificationPresenterLinux>(); | ||||||
|   return new NotificationPresenterLinux; |   return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| NotificationPresenterLinux::NotificationPresenterLinux() = default; | NotificationPresenterLinux::NotificationPresenterLinux() = default; | ||||||
|  |  | ||||||
|  | @ -17,8 +17,8 @@ | ||||||
| namespace electron { | namespace electron { | ||||||
| 
 | 
 | ||||||
| // static | // static | ||||||
| NotificationPresenter* NotificationPresenter::Create() { | std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() { | ||||||
|   return new NotificationPresenterMac; |   return std::make_unique<NotificationPresenterMac>(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| CocoaNotification* NotificationPresenterMac::GetNotification( | CocoaNotification* NotificationPresenterMac::GetNotification( | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ | ||||||
| #ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_PRESENTER_H_ | #ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_PRESENTER_H_ | ||||||
| #define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_PRESENTER_H_ | #define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_PRESENTER_H_ | ||||||
| 
 | 
 | ||||||
|  | #include <memory> | ||||||
| #include <set> | #include <set> | ||||||
| #include <string> | #include <string> | ||||||
| 
 | 
 | ||||||
|  | @ -17,7 +18,7 @@ class NotificationDelegate; | ||||||
| 
 | 
 | ||||||
| class NotificationPresenter { | class NotificationPresenter { | ||||||
|  public: |  public: | ||||||
|   static NotificationPresenter* Create(); |   static std::unique_ptr<NotificationPresenter> Create(); | ||||||
| 
 | 
 | ||||||
|   virtual ~NotificationPresenter(); |   virtual ~NotificationPresenter(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -43,17 +43,17 @@ bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { | ||||||
| }  // namespace
 | }  // namespace
 | ||||||
| 
 | 
 | ||||||
| // static
 | // static
 | ||||||
| NotificationPresenter* NotificationPresenter::Create() { | std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() { | ||||||
|   if (!WindowsToastNotification::Initialize()) |   if (!WindowsToastNotification::Initialize()) | ||||||
|     return nullptr; |     return {}; | ||||||
|   auto presenter = std::make_unique<NotificationPresenterWin>(); |   auto presenter = std::make_unique<NotificationPresenterWin>(); | ||||||
|   if (!presenter->Init()) |   if (!presenter->Init()) | ||||||
|     return nullptr; |     return {}; | ||||||
| 
 | 
 | ||||||
|   if (IsDebuggingNotifications()) |   if (IsDebuggingNotifications()) | ||||||
|     LOG(INFO) << "Successfully created Windows notifications presenter"; |     LOG(INFO) << "Successfully created Windows notifications presenter"; | ||||||
| 
 | 
 | ||||||
|   return presenter.release(); |   return presenter; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| NotificationPresenterWin::NotificationPresenterWin() = default; | NotificationPresenterWin::NotificationPresenterWin() = default; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	![37223003+trop[bot]@users.noreply.github.com](/assets/img/avatar_default.png) trop[bot]
				trop[bot]