Chromium Code Reviews| Index: chrome/browser/notifications/platform_notification_service_impl.cc |
| diff --git a/chrome/browser/notifications/platform_notification_service_impl.cc b/chrome/browser/notifications/platform_notification_service_impl.cc |
| index dc4cf994e758ec7dfa17e9e4813992c112de1eb4..4f65be7a16114f3435d80b46f53ede9ada436d6a 100644 |
| --- a/chrome/browser/notifications/platform_notification_service_impl.cc |
| +++ b/chrome/browser/notifications/platform_notification_service_impl.cc |
| @@ -16,6 +16,7 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| +#include "chrome/browser/notifications/notification_display_service_factory.h" |
| #include "chrome/browser/notifications/notification_object_proxy.h" |
| #include "chrome/browser/notifications/notification_ui_manager.h" |
| #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| @@ -89,9 +90,12 @@ void OnCloseEventDispatchComplete( |
| PERSISTENT_NOTIFICATION_STATUS_MAX); |
| } |
| -void CancelNotification(const std::string& id, ProfileID profile_id) { |
| - PlatformNotificationServiceImpl::GetInstance() |
| - ->GetNotificationUIManager()->CancelById(id, profile_id); |
| +void OnCloseEphimeralNotificationProfileLoaded( |
| + const std::string& notification_id, |
| + Profile* profile) { |
| + PlatformNotificationServiceImpl::GetInstance()->GetNotificationDisplayService( |
|
Peter Beverloo
2016/04/18 14:57:10
NotificationDisplayServiceFactory::GetForProfile(p
Miguel Garcia
2016/04/21 14:32:10
The follow up CL I noted does this.
https://codere
|
| + profile) |
| + ->Close(notification_id); |
| } |
| // Callback to run once the profile has been loaded in order to perform a |
| @@ -127,6 +131,17 @@ void ProfileLoadedCallback( |
| } |
| } |
| +// Callback used to close an ephimeral notification from blink. |
| +void CancelNotification(const std::string& notification_id, |
| + std::string profile_id, |
| + bool incognito) { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
|
Peter Beverloo
2016/04/18 14:57:10
To confirm, we imagine all of this moving to the N
Miguel Garcia
2016/04/21 14:32:10
Yes, once ids are generated in content.
|
| + DCHECK(profile_manager); |
| + profile_manager->LoadProfile( |
| + profile_id, incognito, |
| + base::Bind(&OnCloseEphimeralNotificationProfileLoaded, notification_id)); |
| +} |
| + |
| } // namespace |
| // static |
| @@ -136,9 +151,7 @@ PlatformNotificationServiceImpl::GetInstance() { |
| } |
| PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() |
| - : native_notification_ui_manager_( |
| - NotificationUIManager::CreateNativeNotificationManager()), |
| - notification_ui_manager_for_tests_(nullptr) {} |
| + : test_display_service_(nullptr) {} |
| PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
| @@ -329,13 +342,19 @@ void PlatformNotificationServiceImpl::DisplayNotification( |
| new NotificationObjectProxy(browser_context, std::move(delegate)); |
| Notification notification = CreateNotificationFromData( |
| profile, origin, notification_data, notification_resources, proxy); |
| - |
| - GetNotificationUIManager()->Add(notification, profile); |
| - if (cancel_callback) |
| + GetNotificationDisplayService(profile)->Display(notification.delegate_id(), |
| + notification); |
| + if (cancel_callback) { |
| +#if defined(OS_WIN) |
| + std::string profile_id = |
| + base::WideToUTF8(profile->GetPath().BaseName().value()); |
| +#elif defined(OS_POSIX) |
| + std::string profile_id = profile->GetPath().BaseName().value(); |
| +#endif |
| *cancel_callback = |
| - base::Bind(&CancelNotification, |
| - notification.delegate_id(), |
| - NotificationUIManager::GetProfileID(profile)); |
| + base::Bind(&CancelNotification, notification.delegate_id(), profile_id, |
| + profile->IsOffTheRecord()); |
| + } |
| HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( |
| origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| @@ -366,7 +385,9 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
| // the message_center::Notification objects. |
| persistent_notifications_[persistent_notification_id] = notification.id(); |
| - GetNotificationUIManager()->Add(notification, profile); |
| + GetNotificationDisplayService(profile)->Display( |
| + base::Int64ToString(delegate->persistent_notification_id()), |
| + notification); |
| content::RecordAction( |
| base::UserMetricsAction("Notifications.Persistent.Shown")); |
| @@ -387,23 +408,22 @@ void PlatformNotificationServiceImpl::ClosePersistentNotification( |
| #if defined(OS_ANDROID) |
| bool cancel_by_persistent_id = true; |
| #else |
| - bool cancel_by_persistent_id = (native_notification_ui_manager_ != nullptr); |
| + bool cancel_by_persistent_id = |
| + GetNotificationDisplayService(profile)->SupportsNotificationCenter(); |
| #endif |
| if (cancel_by_persistent_id) { |
| // TODO(peter): Remove this conversion when the notification ids are being |
| // generated by the caller of this method. |
| - GetNotificationUIManager()->CancelById( |
| - base::Int64ToString(persistent_notification_id), |
| - NotificationUIManager::GetProfileID(profile)); |
| + GetNotificationDisplayService(profile)->Close( |
| + base::Int64ToString(persistent_notification_id)); |
| } |
| auto iter = persistent_notifications_.find(persistent_notification_id); |
| if (iter == persistent_notifications_.end()) |
| return; |
| - GetNotificationUIManager()->CancelById( |
| - iter->second, NotificationUIManager::GetProfileID(profile)); |
| + GetNotificationDisplayService(profile)->Close(iter->second); |
| persistent_notifications_.erase(iter); |
| } |
| @@ -413,24 +433,13 @@ bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( |
| std::set<std::string>* displayed_notifications) { |
| DCHECK(displayed_notifications); |
| -#if !defined(OS_ANDROID) |
| Profile* profile = Profile::FromBrowserContext(browser_context); |
| if (!profile || profile->AsTestingProfile()) |
| return false; // Tests will not have a message center. |
| - NotificationUIManager* ui_manager = GetNotificationUIManager(); |
| - DCHECK(ui_manager); |
| - |
| // TODO(peter): Filter for persistent notifications only. |
| - *displayed_notifications = ui_manager->GetAllIdsByProfile( |
| - NotificationUIManager::GetProfileID(profile)); |
| - |
| - return true; |
| -#else |
| - // Android cannot reliably return the notifications that are currently being |
| - // displayed on the platform, see the comment in NotificationUIManagerAndroid. |
| - return false; |
| -#endif // !defined(OS_ANDROID) |
| + return GetNotificationDisplayService(profile)->GetDisplayed( |
| + displayed_notifications); |
| } |
| Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
| @@ -485,16 +494,12 @@ Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
| return notification; |
| } |
| -NotificationUIManager* |
| -PlatformNotificationServiceImpl::GetNotificationUIManager() const { |
| - if (notification_ui_manager_for_tests_) |
| - return notification_ui_manager_for_tests_; |
| - |
| - if (native_notification_ui_manager_) { |
| - return native_notification_ui_manager_.get(); |
| - } |
| - |
| - return g_browser_process->notification_ui_manager(); |
| +NotificationDisplayService* |
| +PlatformNotificationServiceImpl::GetNotificationDisplayService( |
| + Profile* profile) { |
| + if (test_display_service_ != nullptr) |
| + return test_display_service_; |
| + return NotificationDisplayServiceFactory::GetForProfile(profile); |
| } |
| void PlatformNotificationServiceImpl::OpenNotificationSettings( |
| @@ -518,11 +523,6 @@ void PlatformNotificationServiceImpl::OpenNotificationSettings( |
| #endif // defined(OS_ANDROID) |
| } |
| -void PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting( |
| - NotificationUIManager* manager) { |
| - notification_ui_manager_for_tests_ = manager; |
| -} |
| - |
| base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( |
| Profile* profile, |
| const GURL& origin) const { |
| @@ -540,3 +540,8 @@ base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( |
| return base::string16(); |
| } |
| + |
| +void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( |
| + NotificationDisplayService* display_service) { |
| + test_display_service_ = display_service; |
| +} |