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

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

Issue 4635007: When an extension is uninstalled, close all desktop notifications from that e... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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/desktop_notification_service.cc
===================================================================
--- chrome/browser/notifications/desktop_notification_service.cc (revision 66634)
+++ chrome/browser/notifications/desktop_notification_service.cc (working copy)
@@ -215,7 +215,7 @@
NotificationUIManager* ui_manager)
: profile_(profile),
ui_manager_(ui_manager) {
- registrar_.Init(profile_->GetPrefs());
+ prefs_registrar_.Init(profile_->GetPrefs());
InitPrefs();
StartObserving();
}
@@ -260,16 +260,24 @@
void DesktopNotificationService::StartObserving() {
if (!profile_->IsOffTheRecord()) {
- registrar_.Add(prefs::kDesktopNotificationDefaultContentSetting, this);
- registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this);
- registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this);
+ prefs_registrar_.Add(prefs::kDesktopNotificationDefaultContentSetting,
+ this);
+ prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this);
+ prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this);
+
+ notification_registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
+ NotificationService::AllSources());
}
+
+ notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
+ Source<Profile>(profile_));
}
void DesktopNotificationService::StopObserving() {
if (!profile_->IsOffTheRecord()) {
- registrar_.RemoveAll();
+ prefs_registrar_.RemoveAll();
}
+ notification_registrar_.RemoveAll();
}
void DesktopNotificationService::GrantPermission(const GURL& origin) {
@@ -299,11 +307,24 @@
void DesktopNotificationService::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- DCHECK(NotificationType::PREF_CHANGED == type);
+ if (NotificationType::PREF_CHANGED == type) {
+ const std::string& name = *Details<std::string>(details).ptr();
+ OnPrefsChanged(name);
+ } else if (NotificationType::EXTENSION_UNLOADED == type) {
+ // Remove all notifications currently shown or queued by the extension
+ // which was unloaded.
+ Extension* extension = Details<Extension>(details).ptr();
+ if (extension)
+ ui_manager_->CancelAllBySourceOrigin(extension->url());
+ } else if (NotificationType::PROFILE_DESTROYED == type) {
+ StopObserving();
+ }
+}
+
+void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) {
PrefService* prefs = profile_->GetPrefs();
- const std::string& name = *Details<std::string>(details).ptr();
- if (name == prefs::kDesktopNotificationAllowedOrigins) {
+ if (pref_name == prefs::kDesktopNotificationAllowedOrigins) {
NotificationService::current()->Notify(
NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
Source<DesktopNotificationService>(this),
@@ -317,7 +338,7 @@
prefs_cache_.get(),
&NotificationsPrefsCache::SetCacheAllowedOrigins,
allowed_origins));
- } else if (name == prefs::kDesktopNotificationDeniedOrigins) {
+ } else if (pref_name == prefs::kDesktopNotificationDeniedOrigins) {
NotificationService::current()->Notify(
NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
Source<DesktopNotificationService>(this),
@@ -331,7 +352,7 @@
prefs_cache_.get(),
&NotificationsPrefsCache::SetCacheDeniedOrigins,
denied_origins));
- } else if (name == prefs::kDesktopNotificationDefaultContentSetting) {
+ } else if (pref_name == prefs::kDesktopNotificationDefaultContentSetting) {
NotificationService::current()->Notify(
NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED,
Source<DesktopNotificationService>(this),
@@ -563,9 +584,7 @@
scoped_refptr<NotificationObjectProxy> proxy(
new NotificationObjectProxy(process_id, route_id, notification_id,
false));
- // TODO(johnnyg): clean up this "empty" notification.
- Notification notif(GURL(), GURL(), string16(), string16(), proxy);
- return ui_manager_->Cancel(notif);
+ return ui_manager_->CancelById(proxy->id());
}

Powered by Google App Engine
This is Rietveld 408576698