diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 21:21:32 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 21:21:32 +0000 |
commit | 32eee5d094e9d919338038edffab4518899055ae (patch) | |
tree | 3a6263214123aac7b3a36b136b7ba09a0946fa7b /chrome | |
parent | 0c86472602ed831e15caf15c69a09c3dcf97dd6d (diff) | |
download | chromium_src-32eee5d094e9d919338038edffab4518899055ae.zip chromium_src-32eee5d094e9d919338038edffab4518899055ae.tar.gz chromium_src-32eee5d094e9d919338038edffab4518899055ae.tar.bz2 |
Use a NotificationRegistrar to listen for notifications.
BUG=2381
Review URL: http://codereview.chromium.org/115648
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16656 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.cc | 19 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.h | 8 | ||||
-rw-r--r-- | chrome/browser/views/infobars/infobar_container.cc | 20 | ||||
-rw-r--r-- | chrome/browser/views/infobars/infobar_container.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/repost_form_warning_view.cc | 13 | ||||
-rw-r--r-- | chrome/browser/views/repost_form_warning_view.h | 4 |
6 files changed, 24 insertions, 44 deletions
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index a93387b..f295476 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -386,7 +386,6 @@ BookmarkBarView::BookmarkBarView(Profile* profile, Browser* browser) BookmarkBarView::~BookmarkBarView() { NotifyModelChanged(); - RemoveNotificationObservers(); if (model_) model_->RemoveObserver(this); StopShowFolderDropMenuTimer(); @@ -401,6 +400,7 @@ void BookmarkBarView::SetProfile(Profile* profile) { // Cancels the current cancelable. NotifyModelChanged(); + registrar_.RemoveAll(); profile_ = profile; @@ -411,11 +411,10 @@ void BookmarkBarView::SetProfile(Profile* profile) { // loaded. other_bookmarked_button_->SetEnabled(false); - NotificationService* ns = NotificationService::current(); Source<Profile> ns_source(profile_->GetOriginalProfile()); - ns->AddObserver(this, NotificationType::BOOKMARK_BUBBLE_SHOWN, ns_source); - ns->AddObserver(this, NotificationType::BOOKMARK_BUBBLE_HIDDEN, ns_source); - ns->AddObserver(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, + registrar_.Add(this, NotificationType::BOOKMARK_BUBBLE_SHOWN, ns_source); + registrar_.Add(this, NotificationType::BOOKMARK_BUBBLE_HIDDEN, ns_source); + registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, NotificationService::AllSources()); model_ = profile_->GetBookmarkModel(); @@ -1271,16 +1270,6 @@ void BookmarkBarView::Observe(NotificationType type, } } -void BookmarkBarView::RemoveNotificationObservers() { - NotificationService* ns = NotificationService::current(); - Source<Profile> ns_source(profile_->GetOriginalProfile()); - ns->RemoveObserver(this, NotificationType::BOOKMARK_BUBBLE_SHOWN, ns_source); - ns->RemoveObserver(this, NotificationType::BOOKMARK_BUBBLE_HIDDEN, ns_source); - ns->RemoveObserver(this, - NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, - NotificationService::AllSources()); -} - void BookmarkBarView::NotifyModelChanged() { if (model_changed_listener_) model_changed_listener_->ModelChanged(); diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h index 6e423a2..b4a748b 100644 --- a/chrome/browser/views/bookmark_bar_view.h +++ b/chrome/browser/views/bookmark_bar_view.h @@ -10,6 +10,7 @@ #include "chrome/browser/bookmarks/bookmark_menu_controller_win.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/common/notification_registrar.h" #include "views/controls/button/menu_button.h" #include "views/controls/label.h" #include "views/controls/menu/menu.h" @@ -334,11 +335,6 @@ class BookmarkBarView : public views::View, const NotificationSource& source, const NotificationDetails& details); - // If we have registered an observer on the notification service, this - // unregisters it. This does nothing if we have not installed ourself as an - // observer. - void RemoveNotificationObservers(); - // If the ModelChangedListener is non-null, ModelChanged is invoked on it. void NotifyModelChanged(); @@ -373,6 +369,8 @@ class BookmarkBarView : public views::View, // throbs. void StopThrobbing(bool immediate); + NotificationRegistrar registrar_; + Profile* profile_; // Used for opening urls. diff --git a/chrome/browser/views/infobars/infobar_container.cc b/chrome/browser/views/infobars/infobar_container.cc index 35d7f7a..3a135c1 100644 --- a/chrome/browser/views/infobars/infobar_container.cc +++ b/chrome/browser/views/infobars/infobar_container.cc @@ -26,26 +26,18 @@ InfoBarContainer::~InfoBarContainer() { } void InfoBarContainer::ChangeTabContents(TabContents* contents) { - if (tab_contents_) { - NotificationService::current()->RemoveObserver( - this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, - Source<TabContents>(tab_contents_)); - NotificationService::current()->RemoveObserver( - this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, - Source<TabContents>(tab_contents_)); - } + registrar_.RemoveAll(); // No need to delete the child views here, their removal from the view // hierarchy does this automatically (see InfoBar::InfoBarRemoved). RemoveAllChildViews(false); tab_contents_ = contents; if (tab_contents_) { UpdateInfoBars(); - NotificationService::current()->AddObserver( - this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, - Source<TabContents>(tab_contents_)); - NotificationService::current()->AddObserver( - this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, - Source<TabContents>(tab_contents_)); + Source<TabContents> tc_source(tab_contents_); + registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, + tc_source); + registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, + tc_source); } } diff --git a/chrome/browser/views/infobars/infobar_container.h b/chrome/browser/views/infobars/infobar_container.h index 6cf02fa..e7abce1 100644 --- a/chrome/browser/views/infobars/infobar_container.h +++ b/chrome/browser/views/infobars/infobar_container.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_ #define CHROME_BROWSER_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_ -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "views/view.h" class BrowserView; @@ -61,6 +61,8 @@ class InfoBarContainer : public views::View, // will be animated. void RemoveInfoBar(InfoBarDelegate* delegate); + NotificationRegistrar registrar_; + // The BrowserView that hosts this InfoBarContainer. BrowserView* browser_view_; diff --git a/chrome/browser/views/repost_form_warning_view.cc b/chrome/browser/views/repost_form_warning_view.cc index 4c91b20..943d8d5 100644 --- a/chrome/browser/views/repost_form_warning_view.cc +++ b/chrome/browser/views/repost_form_warning_view.cc @@ -36,17 +36,14 @@ RepostFormWarningView::RepostFormWarningView( window()->GetNativeHandle()); } views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this)->Show(); - NotificationService::current()->AddObserver( - this, NotificationType::LOAD_START, NotificationService::AllSources()); - NotificationService::current()->AddObserver( - this, NotificationType::TAB_CLOSING, NotificationService::AllSources()); + + registrar_.Add(this, NotificationType::LOAD_START, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::TAB_CLOSING, + NotificationService::AllSources()); } RepostFormWarningView::~RepostFormWarningView() { - NotificationService::current()->RemoveObserver( - this, NotificationType::LOAD_START, NotificationService::AllSources()); - NotificationService::current()->RemoveObserver( - this, NotificationType::TAB_CLOSING, NotificationService::AllSources()); } ////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/views/repost_form_warning_view.h b/chrome/browser/views/repost_form_warning_view.h index a7da41c..40db8ac 100644 --- a/chrome/browser/views/repost_form_warning_view.h +++ b/chrome/browser/views/repost_form_warning_view.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_REPOST_FORM_WARNING_VIEW_H_ #define CHROME_BROWSER_VIEWS_REPOST_FORM_WARNING_VIEW_H_ -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "views/window/dialog_delegate.h" class MessageBoxView; @@ -41,6 +41,8 @@ class RepostFormWarningView : public views::DialogDelegate, const NotificationSource& source, const NotificationDetails& details); + NotificationRegistrar registrar_; + // The message box view whose commands we handle. MessageBoxView* message_box_view_; |