summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/core_options_handler.cc15
-rw-r--r--chrome/browser/dom_ui/core_options_handler.h5
-rw-r--r--chrome/browser/dom_ui/ntp_resource_cache.cc12
-rw-r--r--chrome/browser/dom_ui/ntp_resource_cache.h4
-rw-r--r--chrome/browser/dom_ui/shown_sections_handler.cc7
-rw-r--r--chrome/browser/dom_ui/shown_sections_handler.h4
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 600710f..bd7ff37 100644
--- a/chrome/browser/dom_ui/ntp_resource_cache.cc
+++ b/chrome/browser/dom_ui/ntp_resource_cache.cc
@@ -133,15 +133,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 78ff716..e32511d 100644
--- a/chrome/browser/dom_ui/shown_sections_handler.cc
+++ b/chrome/browser/dom_ui/shown_sections_handler.cc
@@ -48,11 +48,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 14a3215..a281346 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;
@@ -25,7 +26,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);
@@ -52,6 +53,7 @@ class ShownSectionsHandler : public DOMMessageHandler,
private:
PrefService* pref_service_;
+ PrefChangeRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ShownSectionsHandler);
};