Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2107)

Unified Diff: chrome/browser/notifications/platform_notification_service_impl.cc

Issue 1814923002: Nuke NotificationUIManager from PlatformNotificationServiceImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@profile_manager_load
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f8f52edb6fe013507b17529b35d81625ac48452c..991615386a88bd7f8039048b4bbca2b8032f9d82 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) {
+void OnCloseNonPersistentNotificationProfileLoaded(
+ const std::string& notification_id,
+ Profile* profile) {
PlatformNotificationServiceImpl::GetInstance()
- ->GetNotificationUIManager()->CancelById(id, profile_id);
+ ->GetNotificationDisplayService(profile)
+ ->Close(notification_id);
}
// Callback to run once the profile has been loaded in order to perform a
@@ -127,6 +131,18 @@ void ProfileLoadedCallback(
}
}
+// Callback used to close an non-persistent notification from blink.
+void CancelNotification(const std::string& notification_id,
+ std::string profile_id,
+ bool incognito) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ DCHECK(profile_manager);
+ profile_manager->LoadProfile(
+ profile_id, incognito,
+ base::Bind(&OnCloseNonPersistentNotificationProfileLoaded,
+ notification_id));
+}
+
} // namespace
// static
@@ -136,9 +152,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 +343,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 +386,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 +409,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 +434,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 +495,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 +524,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 +541,8 @@ base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage(
return base::string16();
}
+
+void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting(
+ NotificationDisplayService* display_service) {
+ test_display_service_ = display_service;
+}

Powered by Google App Engine
This is Rietveld 408576698