Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/notifications/notification_display_service_proxy.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/notifications/message_center_display_service.h" | |
| 11 #include "chrome/browser/notifications/native_notification_display_service.h" | |
| 12 #include "chrome/browser/notifications/notification.h" | |
| 13 #include "chrome/browser/notifications/notification_platform_bridge_linux.h" | |
| 14 | |
| 15 NotificationDisplayServiceProxy::NotificationDisplayServiceProxy( | |
| 16 Profile* profile) | |
| 17 : profile_(profile) { | |
| 18 // TODO(thomasanderson): Add interface to avoid this cast? | |
| 19 auto* npbl = static_cast<NotificationPlatformBridgeLinux*>( | |
|
Peter Beverloo
2017/04/19 13:26:41
Here and elsewhere (impls, nds, etc) - Chromium st
Tom (Use chromium acct)
2017/04/20 01:43:46
Done.
| |
| 20 g_browser_process->notification_platform_bridge()); | |
| 21 npbl->IsConnected(base::Bind( | |
| 22 &NotificationDisplayServiceProxy::OnNotificationPlatformBridgeInitialized, | |
| 23 base::Unretained(this))); | |
|
Peter Beverloo
2017/04/19 13:26:41
There's two race conditions here:
(1) We can hi
Tom (Use chromium acct)
2017/04/20 01:43:46
Good catch, fixed!
| |
| 24 } | |
| 25 | |
| 26 NotificationDisplayServiceProxy::~NotificationDisplayServiceProxy() = default; | |
| 27 | |
| 28 NotificationDisplayService* | |
| 29 NotificationDisplayServiceProxy::GetNotificationDisplayService() const { | |
| 30 // Can't have both impls at once. | |
| 31 DCHECK(!native_notification_display_service_ || | |
| 32 !message_center_display_service_); | |
| 33 | |
| 34 if (native_notification_display_service_) { | |
| 35 return native_notification_display_service_.get(); | |
| 36 } else if (message_center_display_service_) { | |
| 37 return message_center_display_service_.get(); | |
| 38 } | |
| 39 | |
| 40 return nullptr; | |
| 41 } | |
| 42 | |
| 43 void NotificationDisplayServiceProxy::OnNotificationPlatformBridgeInitialized( | |
| 44 bool success) { | |
| 45 if (success) { | |
| 46 native_notification_display_service_ = | |
| 47 base::MakeUnique<NativeNotificationDisplayService>( | |
| 48 profile_, g_browser_process->notification_platform_bridge()); | |
| 49 } else { | |
| 50 // TODO(thomasanderson): clean up |g_browser_process->notification_bridge_|? | |
|
Peter Beverloo
2017/04/19 13:26:41
Can the NPBL just stop its own thread when it iden
Tom (Use chromium acct)
2017/04/20 01:43:46
Done.
| |
| 51 message_center_display_service_ = | |
| 52 base::MakeUnique<MessageCenterDisplayService>( | |
| 53 profile_, g_browser_process->notification_ui_manager()); | |
| 54 } | |
| 55 | |
| 56 NotificationDisplayService* nds = GetNotificationDisplayService(); | |
| 57 while (!actions_.empty()) { | |
| 58 actions_.front().Run(nds); | |
| 59 actions_.pop(); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 void NotificationDisplayServiceProxy::RunAction( | |
| 64 base::Callback<void(NotificationDisplayService*)> action) { | |
| 65 NotificationDisplayService* nds = GetNotificationDisplayService(); | |
| 66 if (nds) | |
| 67 action.Run(nds); | |
| 68 else | |
| 69 actions_.push(action); | |
| 70 } | |
| 71 | |
| 72 void NotificationDisplayServiceProxy::Display( | |
| 73 NotificationCommon::Type notification_type, | |
| 74 const std::string& notification_id, | |
| 75 const Notification& notification) { | |
| 76 RunAction(base::Bind( | |
| 77 [](NotificationCommon::Type notification_type, | |
| 78 const std::string& notification_id, const Notification& notification, | |
| 79 NotificationDisplayService* nds) { | |
| 80 nds->Display(notification_type, notification_id, notification); | |
| 81 }, | |
| 82 notification_type, notification_id, notification)); | |
|
Peter Beverloo
2017/04/19 13:26:41
Instead of this pattern, consider something like:
Tom (Use chromium acct)
2017/04/20 01:43:46
Done.
| |
| 83 } | |
| 84 | |
| 85 void NotificationDisplayServiceProxy::Close( | |
| 86 NotificationCommon::Type notification_type, | |
| 87 const std::string& notification_id) { | |
| 88 RunAction(base::Bind( | |
| 89 [](NotificationCommon::Type notification_type, | |
| 90 const std::string& notification_id, NotificationDisplayService* nds) { | |
| 91 nds->Close(notification_type, notification_id); | |
| 92 }, | |
| 93 notification_type, notification_id)); | |
| 94 } | |
| 95 | |
| 96 void NotificationDisplayServiceProxy::GetDisplayed( | |
| 97 const DisplayedNotificationsCallback& callback) { | |
| 98 RunAction(base::Bind( | |
| 99 [](const DisplayedNotificationsCallback& callback, | |
| 100 NotificationDisplayService* nds) { nds->GetDisplayed(callback); }, | |
| 101 callback)); | |
| 102 } | |
| OLD | NEW |