From 40e0486b7052e76db03134a44cead2baf6ae528f Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Fri, 22 May 2009 01:47:27 +0000 Subject: More NotificationRegistrar conversions. BUG=2381 Review URL: http://codereview.chromium.org/113736 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16700 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/bookmarks/bookmark_model.cc | 14 +++------- chrome/browser/bookmarks/bookmark_model.h | 4 ++- chrome/browser/sessions/session_restore.cc | 41 ++++++++---------------------- 3 files changed, 17 insertions(+), 42 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index 9f2a102..4ea2a19 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -107,11 +107,6 @@ BookmarkModel::BookmarkModel(Profile* profile) } BookmarkModel::~BookmarkModel() { - if (profile_ && store_.get()) { - NotificationService::current()->RemoveObserver( - this, NotificationType::FAVICON_CHANGED, Source(profile_)); - } - FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, BookmarkModelBeingDeleted(this)); @@ -134,8 +129,8 @@ void BookmarkModel::Load() { // Listen for changes to favicons so that we can update the favicon of the // node appropriately. - NotificationService::current()->AddObserver( - this,NotificationType::FAVICON_CHANGED, Source(profile_)); + registrar_.Add(this, NotificationType::FAVICON_CHANGED, + Source(profile_)); // Load the bookmarks. BookmarkStorage notifies us when done. store_ = new BookmarkStorage(profile_, this); @@ -385,10 +380,7 @@ void BookmarkModel::GetBookmarksWithTitlesMatching( } void BookmarkModel::ClearStore() { - if (profile_ && store_.get()) { - NotificationService::current()->RemoveObserver( - this, NotificationType::FAVICON_CHANGED, Source(profile_)); - } + registrar_.RemoveAll(); store_ = NULL; } diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index 43484eb..6a27ba8 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -21,7 +21,7 @@ #include "chrome/browser/cancelable_request.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_types.h" -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" #include "testing/gtest/include/gtest/gtest_prod.h" @@ -414,6 +414,8 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { // persisted. void set_next_node_id(int id) { next_node_id_ = id; } + NotificationRegistrar registrar_; + Profile* profile_; // Whether the initial set of data has been loaded. diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc index 1304aa1..b165193 100644 --- a/chrome/browser/sessions/session_restore.cc +++ b/chrome/browser/sessions/session_restore.cc @@ -48,6 +48,8 @@ class TabLoader : public NotificationObserver { void LoadTabs(); private: + typedef std::set TabsLoading; + // NotificationObserver method. Removes the specified tab and loads the next // tab. virtual void Observe(NotificationType type, @@ -59,18 +61,13 @@ class TabLoader : public NotificationObserver { // from. void RemoveTab(NavigationController* tab); - // Adds the necessary listeners for the specified tab. - void AddListeners(NavigationController* controller); - - // Removes the necessary listeners for the specified tab. - void RemoveListeners(NavigationController* controller); + NotificationRegistrar registrar_; // Has Load been invoked? bool loading_; // The set of tabs we've initiated loading on. This does NOT include the // selected tabs. - typedef std::set TabsLoading; TabsLoading tabs_loading_; // The tabs we need to load. @@ -90,7 +87,10 @@ void TabLoader::AddTab(NavigationController* controller) { DCHECK(find(tabs_to_load_.begin(), tabs_to_load_.end(), controller) == tabs_to_load_.end()); tabs_to_load_.push_back(controller); - AddListeners(controller); + registrar_.Add(this, NotificationType::TAB_CLOSED, + Source(controller)); + registrar_.Add(this, NotificationType::LOAD_STOP, + Source(controller)); } else { // Should never get a NULL tab. NOTREACHED(); @@ -123,10 +123,6 @@ void TabLoader::LoadTabs() { } if (tabs_to_load_.empty()) { - for (TabsLoading::iterator i = tabs_loading_.begin(); - i != tabs_loading_.end(); ++i) { - RemoveListeners(*i); - } tabs_loading_.clear(); delete this; } @@ -146,7 +142,10 @@ void TabLoader::Observe(NotificationType type, } void TabLoader::RemoveTab(NavigationController* tab) { - RemoveListeners(tab); + registrar_.Remove(this, NotificationType::TAB_CLOSED, + Source(tab)); + registrar_.Remove(this, NotificationType::LOAD_STOP, + Source(tab)); TabsLoading::iterator i = tabs_loading_.find(tab); if (i != tabs_loading_.end()) @@ -158,24 +157,6 @@ void TabLoader::RemoveTab(NavigationController* tab) { tabs_to_load_.erase(j); } -void TabLoader::AddListeners(NavigationController* controller) { - NotificationService::current()->AddObserver( - this, NotificationType::TAB_CLOSED, - Source(controller)); - NotificationService::current()->AddObserver( - this, NotificationType::LOAD_STOP, - Source(controller)); -} - -void TabLoader::RemoveListeners(NavigationController* controller) { - NotificationService::current()->RemoveObserver( - this, NotificationType::TAB_CLOSED, - Source(controller)); - NotificationService::current()->RemoveObserver( - this, NotificationType::LOAD_STOP, - Source(controller)); -} - // SessionRestoreImpl --------------------------------------------------------- // SessionRestoreImpl is responsible for fetching the set of tabs to create -- cgit v1.1