From 59316ec0027a6e6eec0f71405edc8d2a53039db0 Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Thu, 21 May 2009 00:47:20 +0000 Subject: Use a NotificationRegistrar to handle notification observing. BUG=2381 Review URL: http://codereview.chromium.org/115607 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16560 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/dom_ui/history_ui.cc | 12 ++---------- chrome/browser/dom_ui/history_ui.h | 3 +++ chrome/browser/dom_ui/new_tab_ui.cc | 7 ++----- chrome/browser/dom_ui/new_tab_ui.h | 4 +++- 4 files changed, 10 insertions(+), 16 deletions(-) (limited to 'chrome/browser/dom_ui') diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index 1c37d12..1fbbb38 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -113,20 +113,12 @@ BrowsingHistoryHandler::BrowsingHistoryHandler(DOMUI* dom_ui) new DOMUIFavIconSource(dom_ui_->GetProfile()))); // Get notifications when history is cleared. - NotificationService* service = NotificationService::current(); - service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED, - Source( - dom_ui_->GetProfile()->GetOriginalProfile())); + registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, + Source(dom_ui_->GetProfile()->GetOriginalProfile())); } BrowsingHistoryHandler::~BrowsingHistoryHandler() { cancelable_consumer_.CancelAllRequests(); - - NotificationService* service = NotificationService::current(); - service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED, - Source( - dom_ui_->GetProfile()->GetOriginalProfile())); - if (remover_.get()) remover_->RemoveObserver(this); } diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h index a4f201c..f44e033 100644 --- a/chrome/browser/dom_ui/history_ui.h +++ b/chrome/browser/dom_ui/history_ui.h @@ -11,6 +11,7 @@ #include "chrome/browser/dom_ui/dom_ui.h" #include "chrome/browser/cancelable_request.h" #include "chrome/browser/history/history.h" +#include "chrome/common/notification_registrar.h" class GURL; @@ -67,6 +68,8 @@ class BrowsingHistoryHandler : public DOMMessageHandler, // Figure out the query options for a month-wide query. history::QueryOptions CreateMonthQueryOptions(int month); + NotificationRegistrar registrar_; + // Current search text. std::wstring search_text_; diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index e64f02e..ccef07f 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -1193,14 +1193,11 @@ NewTabUI::NewTabUI(TabContents* contents) } // Listen for theme installation. - NotificationService::current()->AddObserver(this, - NotificationType::THEME_INSTALLED, NotificationService::AllSources()); + registrar_.Add(this, NotificationType::THEME_INSTALLED, + NotificationService::AllSources()); } NewTabUI::~NewTabUI() { - // Remove theme observer. - NotificationService::current()->RemoveObserver(this, - NotificationType::THEME_INSTALLED, NotificationService::AllSources()); } void NewTabUI::Observe(NotificationType type, diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h index 1efb8dd..6c3a2f1 100644 --- a/chrome/browser/dom_ui/new_tab_ui.h +++ b/chrome/browser/dom_ui/new_tab_ui.h @@ -6,7 +6,7 @@ #define CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H_ #include "chrome/browser/dom_ui/dom_ui.h" -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" class GURL; class PrefService; @@ -33,6 +33,8 @@ class NewTabUI : public DOMUI, const NotificationSource& source, const NotificationDetails& details); + NotificationRegistrar registrar_; + // The message id that should be displayed in this NewTabUIContents // instance's motd area. int motd_message_id_; -- cgit v1.1