summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-22 19:51:21 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-22 19:51:21 +0000
commit0cb941091a7bd3ae1fbb909330d73001afa7f5f3 (patch)
tree8b84b1689fd8f41901b5f489440979f72bb6f622
parent557c772943a7257f3c90cbe811c5ec1b7902a3ba (diff)
downloadchromium_src-0cb941091a7bd3ae1fbb909330d73001afa7f5f3.zip
chromium_src-0cb941091a7bd3ae1fbb909330d73001afa7f5f3.tar.gz
chromium_src-0cb941091a7bd3ae1fbb909330d73001afa7f5f3.tar.bz2
Use a NotificationRegistrar to listen for notifications.
BUG=2381 Review URL: http://codereview.chromium.org/115673 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16777 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser.cc33
-rw-r--r--chrome/browser/browser.h4
2 files changed, 11 insertions, 26 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 7c3e679..1c9885c 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -185,14 +185,10 @@ Browser::Browser(Type type, Profile* profile)
idle_task_(new BrowserIdleTimer) {
tabstrip_model_.AddObserver(this);
- NotificationService::current()->AddObserver(
- this,
- NotificationType::SSL_VISIBLE_STATE_CHANGED,
- NotificationService::AllSources());
- NotificationService::current()->AddObserver(
- this,
- NotificationType::EXTENSION_UNLOADED,
- NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
+ NotificationService::AllSources());
InitCommandState();
BrowserList::AddBrowser(this);
@@ -234,15 +230,6 @@ Browser::~Browser() {
if (tab_restore_service)
tab_restore_service->BrowserClosed(this);
- NotificationService::current()->RemoveObserver(
- this,
- NotificationType::SSL_VISIBLE_STATE_CHANGED,
- NotificationService::AllSources());
- NotificationService::current()->RemoveObserver(
- this,
- NotificationType::EXTENSION_UNLOADED,
- NotificationService::AllSources());
-
if (profile_->IsOffTheRecord() &&
!BrowserList::IsOffTheRecordSessionActive()) {
// An off-the-record profile is no longer needed, this indirectly
@@ -1572,10 +1559,8 @@ void Browser::TabInsertedAt(TabContents* contents,
// If the tab crashes in the beforeunload or unload handler, it won't be
// able to ack. But we know we can close it.
- NotificationService::current()->AddObserver(
- this,
- NotificationType::TAB_CONTENTS_DISCONNECTED,
- Source<TabContents>(contents));
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
+ Source<TabContents>(contents));
}
void Browser::TabClosingAt(TabContents* contents, int index) {
@@ -1598,10 +1583,8 @@ void Browser::TabDetachedAt(TabContents* contents, int index) {
if (find_bar_controller_.get() && index == tabstrip_model_.selected_index())
find_bar_controller_->ChangeTabContents(NULL);
- NotificationService::current()->RemoveObserver(
- this,
- NotificationType::TAB_CONTENTS_DISCONNECTED,
- Source<TabContents>(contents));
+ registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
+ Source<TabContents>(contents));
}
void Browser::TabSelectedAt(TabContents* old_contents,
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index d1aca35..6972308 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -20,7 +20,7 @@
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/browser/toolbar_model.h"
-#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
#include "chrome/common/pref_member.h"
#include "base/gfx/rect.h"
#include "base/scoped_ptr.h"
@@ -644,6 +644,8 @@ class Browser : public TabStripModelDelegate,
// Data members /////////////////////////////////////////////////////////////
+ NotificationRegistrar registrar_;
+
// This Browser's type.
Type type_;