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 542f8b4ecf8e3e7deb1570c172a7823fb87441b8..db4a9620bce2954a9ce64739003574bd2edf808a 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,11 @@ void OnCloseEventDispatchComplete( |
PERSISTENT_NOTIFICATION_STATUS_MAX); |
} |
-void CancelNotification(const std::string& id, ProfileID profile_id) { |
- PlatformNotificationServiceImpl::GetInstance() |
- ->GetNotificationUIManager()->CancelById(id, profile_id); |
+void CancelNotification(const std::string& notification_id, |
+ std::string profile_id, |
+ bool incognito) { |
+ // We are going to need to load the profile from the id and call close |
+ // NotificationDisplayServiceFactory::GetForProfile(profile)->Close(id); |
} |
// Callback to run once the profile has been loaded in order to perform a |
@@ -143,10 +146,7 @@ PlatformNotificationServiceImpl::GetInstance() { |
return base::Singleton<PlatformNotificationServiceImpl>::get(); |
} |
-PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() |
- : native_notification_ui_manager_( |
- NotificationUIManager::CreateNativeNotificationManager()), |
- notification_ui_manager_for_tests_(nullptr) {} |
+PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} |
PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
@@ -352,13 +352,14 @@ void PlatformNotificationServiceImpl::DisplayNotification( |
new NotificationObjectProxy(browser_context, std::move(delegate)); |
Notification notification = CreateNotificationFromData( |
profile, origin, notification_data, notification_resources, proxy); |
+ NotificationDisplayServiceFactory::GetForProfile(profile)->Display( |
+ notification); |
- GetNotificationUIManager()->Add(notification, profile); |
if (cancel_callback) |
- *cancel_callback = |
- base::Bind(&CancelNotification, |
- notification.delegate_id(), |
- NotificationUIManager::GetProfileID(profile)); |
+ *cancel_callback = base::Bind( |
+ &CancelNotification, notification.delegate_id(), |
+ profile->GetPath().BaseName().value(), // This will fail on Windows |
+ profile->IsOffTheRecord()); |
HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( |
origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
@@ -389,7 +390,9 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
// the message_center::Notification objects. |
persistent_notifications_[persistent_notification_id] = notification.id(); |
- GetNotificationUIManager()->Add(notification, profile); |
+ NotificationDisplayServiceFactory::GetForProfile(profile)->Display( |
+ notification); |
+ |
content::RecordAction( |
base::UserMetricsAction("Notifications.Persistent.Shown")); |
@@ -410,23 +413,24 @@ 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 = |
+ NotificationDisplayServiceFactory::GetForProfile(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)); |
+ NotificationDisplayServiceFactory::GetForProfile(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)); |
+ NotificationDisplayServiceFactory::GetForProfile(profile)->Close( |
+ iter->second); |
persistent_notifications_.erase(iter); |
} |
@@ -441,16 +445,9 @@ bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( |
if (!profile || profile->AsTestingProfile()) |
return false; // Tests will not have a message center. |
- // There may not be a notification ui manager when another feature erroneously |
- // instantiates a storage partition when the browser process is shutting down. |
- // TODO(peter): Remove in favor of a DCHECK when crbug.com/546745 is fixed. |
- NotificationUIManager* ui_manager = GetNotificationUIManager(); |
- if (!ui_manager) |
- return false; |
- |
// TODO(peter): Filter for persistent notifications only. |
- *displayed_notifications = ui_manager->GetAllIdsByProfile( |
- NotificationUIManager::GetProfileID(profile)); |
+ *displayed_notifications = |
+ NotificationDisplayServiceFactory::GetForProfile(profile)->GetDisplayed(); |
return true; |
#else |
@@ -512,18 +509,6 @@ 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(); |
-} |
- |
void PlatformNotificationServiceImpl::OpenNotificationSettings( |
BrowserContext* browser_context) { |
#if defined(OS_ANDROID) |
@@ -545,11 +530,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 { |