diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-22 01:47:27 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-22 01:47:27 +0000 |
commit | 40e0486b7052e76db03134a44cead2baf6ae528f (patch) | |
tree | 6ca8210291a0287626b126f6b373a48f7f6e11ee /chrome | |
parent | b3edb31e6ec0a3a3a312718933e907f341606548 (diff) | |
download | chromium_src-40e0486b7052e76db03134a44cead2baf6ae528f.zip chromium_src-40e0486b7052e76db03134a44cead2baf6ae528f.tar.gz chromium_src-40e0486b7052e76db03134a44cead2baf6ae528f.tar.bz2 |
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
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.cc | 14 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.h | 4 | ||||
-rw-r--r-- | chrome/browser/sessions/session_restore.cc | 41 |
3 files changed, 17 insertions, 42 deletions
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>(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>(profile_)); + registrar_.Add(this, NotificationType::FAVICON_CHANGED, + Source<Profile>(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>(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<NavigationController*> 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<NavigationController*> 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<NavigationController>(controller)); + registrar_.Add(this, NotificationType::LOAD_STOP, + Source<NavigationController>(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<NavigationController>(tab)); + registrar_.Remove(this, NotificationType::LOAD_STOP, + Source<NavigationController>(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<NavigationController>(controller)); - NotificationService::current()->AddObserver( - this, NotificationType::LOAD_STOP, - Source<NavigationController>(controller)); -} - -void TabLoader::RemoveListeners(NavigationController* controller) { - NotificationService::current()->RemoveObserver( - this, NotificationType::TAB_CLOSED, - Source<NavigationController>(controller)); - NotificationService::current()->RemoveObserver( - this, NotificationType::LOAD_STOP, - Source<NavigationController>(controller)); -} - // SessionRestoreImpl --------------------------------------------------------- // SessionRestoreImpl is responsible for fetching the set of tabs to create |