diff options
author | danno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 12:43:14 +0000 |
---|---|---|
committer | danno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 12:43:14 +0000 |
commit | 37d5293518a8657af4d79035f7ef2e8c3a8d6b9a (patch) | |
tree | 9897f36b9f09457d3a5fbb002abc4e081e79ae56 /chrome/browser/dom_ui | |
parent | 37c3dacaa38fddba1c53d9b3f3f0514933d3dd45 (diff) | |
download | chromium_src-37d5293518a8657af4d79035f7ef2e8c3a8d6b9a.zip chromium_src-37d5293518a8657af4d79035f7ef2e8c3a8d6b9a.tar.gz chromium_src-37d5293518a8657af4d79035f7ef2e8c3a8d6b9a.tar.bz2 |
Use PrefChangeRegistrar everywhere
BUG=54955
TEST=PrefChangeRegistrarTest.*
Review URL: http://codereview.chromium.org/3304015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60169 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/core_options_handler.cc | 15 | ||||
-rw-r--r-- | chrome/browser/dom_ui/core_options_handler.h | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/ntp_resource_cache.cc | 12 | ||||
-rw-r--r-- | chrome/browser/dom_ui/ntp_resource_cache.h | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.cc | 7 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.h | 4 |
6 files changed, 24 insertions, 23 deletions
diff --git a/chrome/browser/dom_ui/core_options_handler.cc b/chrome/browser/dom_ui/core_options_handler.cc index 2739ebc..849e768b 100644 --- a/chrome/browser/dom_ui/core_options_handler.cc +++ b/chrome/browser/dom_ui/core_options_handler.cc @@ -88,6 +88,13 @@ void CoreOptionsHandler::Uninitialize() { } } +DOMMessageHandler* CoreOptionsHandler::Attach(DOMUI* dom_ui) { + DOMMessageHandler* result = DOMMessageHandler::Attach(dom_ui); + DCHECK(dom_ui_); + registrar_.Init(dom_ui_->GetProfile()->GetPrefs()); + return result; +} + void CoreOptionsHandler::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { @@ -138,9 +145,7 @@ Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) { } void CoreOptionsHandler::ObservePref(const std::string& pref_name) { - DCHECK(dom_ui_); - PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs(); - pref_service->AddPrefObserver(pref_name.c_str(), this); + registrar_.Add(pref_name.c_str(), this); } void CoreOptionsHandler::SetPref(const std::string& pref_name, @@ -185,9 +190,7 @@ void CoreOptionsHandler::ProcessUserMetric(Value::ValueType pref_type, } void CoreOptionsHandler::StopObservingPref(const std::string& path) { - DCHECK(dom_ui_); - PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs(); - pref_service->RemovePrefObserver(path.c_str(), this); + registrar_.Remove(path.c_str(), this); } void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) { diff --git a/chrome/browser/dom_ui/core_options_handler.h b/chrome/browser/dom_ui/core_options_handler.h index 748ab83..fd94d10 100644 --- a/chrome/browser/dom_ui/core_options_handler.h +++ b/chrome/browser/dom_ui/core_options_handler.h @@ -11,6 +11,7 @@ #include "base/values.h" #include "chrome/browser/dom_ui/options_ui.h" +#include "chrome/browser/prefs/pref_change_registrar.h" // Core options UI handler. // Handles resource and JS calls common to all options sub-pages. @@ -22,7 +23,6 @@ class CoreOptionsHandler : public OptionsPageUIHandler { virtual void GetLocalizedValues(DictionaryValue* localized_strings); virtual void Uninitialize(); - // NotificationObserver implementation. virtual void Observe(NotificationType type, const NotificationSource& source, @@ -30,6 +30,7 @@ class CoreOptionsHandler : public OptionsPageUIHandler { // DOMMessageHandler implementation. virtual void RegisterMessages(); + virtual DOMMessageHandler* Attach(DOMUI* dom_ui); protected: // Fetches a pref value of given |pref_name|. @@ -87,6 +88,8 @@ class CoreOptionsHandler : public OptionsPageUIHandler { void NotifyPrefChanged(const std::string* pref_name); + PrefChangeRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(CoreOptionsHandler); }; diff --git a/chrome/browser/dom_ui/ntp_resource_cache.cc b/chrome/browser/dom_ui/ntp_resource_cache.cc index 169aea0..50964c9 100644 --- a/chrome/browser/dom_ui/ntp_resource_cache.cc +++ b/chrome/browser/dom_ui/ntp_resource_cache.cc @@ -130,15 +130,9 @@ NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { NotificationService::AllSources()); // Watch for pref changes that cause us to need to invalidate the HTML cache. - PrefService* pref_service = profile_->GetPrefs(); - pref_service->AddPrefObserver(prefs::kShowBookmarkBar, this); - pref_service->AddPrefObserver(prefs::kNTPShownSections, this); -} - -NTPResourceCache::~NTPResourceCache() { - PrefService* pref_service = profile_->GetPrefs(); - pref_service->RemovePrefObserver(prefs::kShowBookmarkBar, this); - pref_service->RemovePrefObserver(prefs::kNTPShownSections, this); + pref_change_registrar_.Init(profile_->GetPrefs()); + pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); + pref_change_registrar_.Add(prefs::kNTPShownSections, this); } RefCountedBytes* NTPResourceCache::GetNewTabHTML(bool is_off_the_record) { diff --git a/chrome/browser/dom_ui/ntp_resource_cache.h b/chrome/browser/dom_ui/ntp_resource_cache.h index f669325..3cdc3e5 100644 --- a/chrome/browser/dom_ui/ntp_resource_cache.h +++ b/chrome/browser/dom_ui/ntp_resource_cache.h @@ -10,6 +10,7 @@ #include "base/ref_counted.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" +#include "chrome/browser/prefs/pref_change_registrar.h" class Profile; class RefCountedBytes; @@ -19,7 +20,7 @@ class RefCountedBytes; class NTPResourceCache : public NotificationObserver { public: explicit NTPResourceCache(Profile* profile); - virtual ~NTPResourceCache(); + virtual ~NTPResourceCache() {} RefCountedBytes* GetNewTabHTML(bool is_off_the_record); RefCountedBytes* GetNewTabCSS(bool is_off_the_record); @@ -43,6 +44,7 @@ class NTPResourceCache : public NotificationObserver { scoped_refptr<RefCountedBytes> new_tab_css_; NotificationRegistrar registrar_; + PrefChangeRegistrar pref_change_registrar_; DISALLOW_COPY_AND_ASSIGN(NTPResourceCache); }; diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc index 4af2d0b..94a49a4 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.cc +++ b/chrome/browser/dom_ui/shown_sections_handler.cc @@ -50,11 +50,8 @@ int ShownSectionsHandler::GetShownSections(PrefService* prefs) { ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) : pref_service_(pref_service) { - pref_service_->AddPrefObserver(prefs::kNTPShownSections, this); -} - -ShownSectionsHandler::~ShownSectionsHandler() { - pref_service_->RemovePrefObserver(prefs::kNTPShownSections, this); + registrar_.Init(pref_service); + registrar_.Add(prefs::kNTPShownSections, this); } void ShownSectionsHandler::RegisterMessages() { diff --git a/chrome/browser/dom_ui/shown_sections_handler.h b/chrome/browser/dom_ui/shown_sections_handler.h index 8821d640..39428bb 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.h +++ b/chrome/browser/dom_ui/shown_sections_handler.h @@ -8,6 +8,7 @@ #include "chrome/browser/dom_ui/dom_ui.h" #include "chrome/common/notification_observer.h" +#include "chrome/browser/prefs/pref_change_registrar.h" class DOMUI; class Value; @@ -28,7 +29,7 @@ class ShownSectionsHandler : public DOMMessageHandler, public NotificationObserver { public: explicit ShownSectionsHandler(PrefService* pref_service); - virtual ~ShownSectionsHandler(); + virtual ~ShownSectionsHandler() {} // Helper to get the current shown sections. static int GetShownSections(PrefService* pref_service); @@ -55,6 +56,7 @@ class ShownSectionsHandler : public DOMMessageHandler, private: PrefService* pref_service_; + PrefChangeRegistrar registrar_; DISALLOW_COPY_AND_ASSIGN(ShownSectionsHandler); }; |