summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-04 19:56:49 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-04 19:56:49 +0000
commitc057ed7f234d1b02858fdeed7990ebff148f08b1 (patch)
treec1870082c456ed35b1bd7a549a894df98ab33cb9
parentb70f8522356988f608a2341dfcbcbe5166c79e08 (diff)
downloadchromium_src-c057ed7f234d1b02858fdeed7990ebff148f08b1.zip
chromium_src-c057ed7f234d1b02858fdeed7990ebff148f08b1.tar.gz
chromium_src-c057ed7f234d1b02858fdeed7990ebff148f08b1.tar.bz2
Profiles: Introduce AllBrowserContextsAndSources().
Eventually, we need to remove all current instances of AllSources(). One by one, they need to either changed to listen to a specific notification source, or (in very few cases where we actually are listening for a global notification) they need to work correctly in the presence of multiple profiles, in which case they'll be turned to AllBrowserContextsAndSources(). This patch, in addition: - Deletes more unused notifications. - Changes a few AllSources() calls to listen to specific objects. BUG=87457 TEST=none Review URL: http://codereview.chromium.org/7548022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95469 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/notifications/notification_exceptions_table_model.cc5
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc2
-rw-r--r--chrome/browser/task_manager/task_manager_resource_providers.cc48
-rw-r--r--chrome/browser/ui/browser.cc3
-rw-r--r--chrome/browser/ui/gtk/global_menu_bar.cc15
-rw-r--r--content/browser/renderer_host/render_widget_host.cc5
-rw-r--r--content/common/content_notification_types.h14
-rw-r--r--content/common/notification_service.h13
8 files changed, 52 insertions, 53 deletions
diff --git a/chrome/browser/notifications/notification_exceptions_table_model.cc b/chrome/browser/notifications/notification_exceptions_table_model.cc
index e4fd3ed..71ff312 100644
--- a/chrome/browser/notifications/notification_exceptions_table_model.cc
+++ b/chrome/browser/notifications/notification_exceptions_table_model.cc
@@ -30,7 +30,7 @@ NotificationExceptionsTableModel::NotificationExceptionsTableModel(
observer_(NULL) {
registrar_.Add(this,
chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
- NotificationService::AllSources());
+ Source<DesktopNotificationService>(service));
LoadEntries();
}
@@ -103,7 +103,8 @@ void NotificationExceptionsTableModel::Observe(
const NotificationSource& source,
const NotificationDetails& details) {
if (!updates_disabled_) {
- DCHECK(type == chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED);
+ DCHECK_EQ(type, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED);
+ DCHECK_EQ(Source<DesktopNotificationService>(source).ptr(), service_);
entries_.clear();
LoadEntries();
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index b4fc124..3134983 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -68,7 +68,7 @@ TabStripModel::TabStripModel(TabStripModelDelegate* delegate, Profile* profile)
DCHECK(delegate_);
registrar_.Add(this,
content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_UNLOADED,
Source<Profile>(profile_));
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc
index 006ce75..d95bebd 100644
--- a/chrome/browser/task_manager/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager/task_manager_resource_providers.cc
@@ -334,17 +334,17 @@ void TaskManagerTabContentsResourceProvider::StartUpdating() {
// Then we register for notifications to get new tabs.
registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
// TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a
// resource. This is an attempt at mitigating a crasher that seem to
// indicate a resource is still referencing a deleted TabContents
// (http://crbug.com/7321).
registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
}
void TaskManagerTabContentsResourceProvider::StopUpdating() {
@@ -353,13 +353,13 @@ void TaskManagerTabContentsResourceProvider::StopUpdating() {
// Then we unregister for notifications to get new tabs.
registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
// Delete all the resources.
STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
@@ -574,11 +574,11 @@ void TaskManagerBackgroundContentsResourceProvider::StartUpdating() {
// Then we register for notifications to get new BackgroundContents.
registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
}
void TaskManagerBackgroundContentsResourceProvider::StopUpdating() {
@@ -587,11 +587,11 @@ void TaskManagerBackgroundContentsResourceProvider::StopUpdating() {
// Unregister for notifications
registrar_.Remove(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
// Delete all the resources.
STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
@@ -858,9 +858,9 @@ void TaskManagerChildProcessResourceProvider::StartUpdating() {
// Register for notifications to get new child processes.
registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
// Get the existing child processes.
BrowserThread::PostTask(
@@ -876,10 +876,10 @@ void TaskManagerChildProcessResourceProvider::StopUpdating() {
// Unregister for notifications to get new plugin processes.
registrar_.Remove(this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(this,
content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
// Delete all the resources.
STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
@@ -1101,11 +1101,11 @@ void TaskManagerExtensionProcessResourceProvider::StartUpdating() {
// Register for notifications about extension process changes.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
}
void TaskManagerExtensionProcessResourceProvider::StopUpdating() {
@@ -1114,11 +1114,11 @@ void TaskManagerExtensionProcessResourceProvider::StopUpdating() {
// Unregister for notifications about extension process changes.
registrar_.Remove(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
- NotificationService::AllSources());
+ NotificationService::AllBrowserContextsAndSources());
// Delete all the resources.
STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index dd015aa..447257d 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -275,7 +275,7 @@ Browser::Browser(Type type, Profile* profile)
NotificationService::AllSources());
registrar_.Add(this,
chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
- NotificationService::AllSources());
+ Source<Profile>(profile_));
// Need to know when to alert the user of theme install delay.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_READY_FOR_INSTALL,
@@ -3739,6 +3739,7 @@ void Browser::Observe(int type,
break;
case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED:
+ DCHECK_EQ(Source<Profile>(source).ptr(), profile_);
UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE);
break;
diff --git a/chrome/browser/ui/gtk/global_menu_bar.cc b/chrome/browser/ui/gtk/global_menu_bar.cc
index 4fd937f..4bfd2bd 100644
--- a/chrome/browser/ui/gtk/global_menu_bar.cc
+++ b/chrome/browser/ui/gtk/global_menu_bar.cc
@@ -18,6 +18,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/common/notification_service.h"
+#include "content/common/notification_source.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/gtk_util.h"
@@ -213,12 +214,12 @@ GlobalMenuBar::GlobalMenuBar(Browser* browser)
}
// Listen for bookmark bar visibility changes and set the initial state.
+ Source<Profile> source(browser->profile());
registrar_.Add(this,
chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
- NotificationService::AllSources());
+ source);
Observe(chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
- NotificationService::AllSources(),
- NotificationService::NoDetails());
+ source, NotificationService::NoDetails());
}
GlobalMenuBar::~GlobalMenuBar() {
@@ -232,13 +233,14 @@ void GlobalMenuBar::Disable() {
browser_->command_updater()->RemoveCommandObserver(it->first, this);
}
id_to_menu_item_.clear();
+ Source<Profile> source(browser_->profile());
if (registrar_.IsRegistered(this,
chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
- NotificationService::AllSources())) {
+ source)) {
registrar_.Remove(
this,
chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
- NotificationService::AllSources());
+ source);
}
}
@@ -318,7 +320,8 @@ void GlobalMenuBar::EnabledStateChangedForCommand(int id, bool enabled) {
void GlobalMenuBar::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
- DCHECK(type == chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED);
+ DCHECK_EQ(type, chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED);
+ DCHECK_EQ(Source<Profile>(source).ptr(), browser_->profile());
CommandIDMenuItemMap::iterator it =
id_to_menu_item_.find(IDC_SHOW_BOOKMARK_BAR);
diff --git a/content/browser/renderer_host/render_widget_host.cc b/content/browser/renderer_host/render_widget_host.cc
index a5eb4b6..67c9151 100644
--- a/content/browser/renderer_host/render_widget_host.cc
+++ b/content/browser/renderer_host/render_widget_host.cc
@@ -868,11 +868,6 @@ void RenderWidgetHost::OnMsgUpdateRect(
TRACE_EVENT0("renderer_host", "RenderWidgetHost::OnMsgUpdateRect");
TimeTicks paint_start = TimeTicks::Now();
- NotificationService::current()->Notify(
- content::NOTIFICATION_RENDER_WIDGET_HOST_WILL_PAINT,
- Source<RenderWidgetHost>(this),
- NotificationService::NoDetails());
-
// Update our knowledge of the RenderWidget's size.
current_size_ = params.view_size;
// Update our knowledge of the RenderWidget's scroll offset.
diff --git a/content/common/content_notification_types.h b/content/common/content_notification_types.h
index f136878..3b1fe92 100644
--- a/content/common/content_notification_types.h
+++ b/content/common/content_notification_types.h
@@ -173,16 +173,6 @@ enum {
// selected (if any).
NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
- // Notification that a view was removed from a view hierarchy. The source
- // is the view, the details is the parent view.
- NOTIFICATION_VIEW_REMOVED,
-
- // This message is sent when the last window considered to be an
- // "application window" has been closed. Dependent/dialog/utility windows
- // can use this as a way to know that they should also close. No source or
- // details are passed.
- NOTIFICATION_ALL_APPWINDOWS_CLOSED,
-
#if defined(OS_MACOSX)
// This message is sent when the application is made active (Mac OS X only
// at present). No source or details are passed.
@@ -323,10 +313,6 @@ enum {
// the RenderWidgetHost, the details are not used.
NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
- // Sent when the widget is about to paint. The source is the
- // RenderWidgetHost, the details are not used.
- NOTIFICATION_RENDER_WIDGET_HOST_WILL_PAINT,
-
// Sent after the widget has painted. The source is the RenderWidgetHost,
// the details are not used.
NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT,
diff --git a/content/common/notification_service.h b/content/common/notification_service.h
index c6898f5..8040b7f 100644
--- a/content/common/notification_service.h
+++ b/content/common/notification_service.h
@@ -46,6 +46,19 @@ class NotificationService {
// (for the purpose of registering an observer for events from all sources).
static Source<void> AllSources() { return Source<void>(NULL); }
+ // Returns the same value as AllSources(). This function has semantic
+ // differences to the programmer: We have checked that this AllSources()
+ // usage is safe in the face of multiple profiles. Objects that were
+ // singletons now will always have multiple instances, one per profile.
+ //
+ // Some usage is safe, where the Source is checked to see if it's a member of
+ // a container before use. But, we want the number of AllSources() calls to
+ // drop to almost nothing, because most usages are not multiprofile safe and
+ // were done because it was easier to listen to everything.
+ static Source<void> AllBrowserContextsAndSources() {
+ return Source<void>(NULL);
+ }
+
// Returns a NotificationDetails object that represents a lack of details
// associated with a notification. (This is effectively a null pointer.)
static Details<void> NoDetails() { return Details<void>(NULL); }