Index: base/prefs/public/pref_change_registrar.h |
diff --git a/base/prefs/public/pref_change_registrar.h b/base/prefs/public/pref_change_registrar.h |
index f3abd9869191056aedecb8a731f499c94414f521..adb92ee83957cb65e507c85213037c21a5af444a 100644 |
--- a/base/prefs/public/pref_change_registrar.h |
+++ b/base/prefs/public/pref_change_registrar.h |
@@ -5,20 +5,21 @@ |
#ifndef BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_ |
#define BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_ |
-#include <set> |
+#include <map> |
#include <string> |
#include "base/basictypes.h" |
+#include "base/callback.h" |
#include "base/prefs/base_prefs_export.h" |
+#include "base/prefs/public/pref_observer.h" |
-class PrefObserver; |
class PrefServiceBase; |
// Automatically manages the registration of one or more pref change observers |
// with a PrefStore. Functions much like NotificationRegistrar, but specifically |
// manages observers of preference changes. When the Registrar is destroyed, |
// all registered observers are automatically unregistered with the PrefStore. |
-class BASE_PREFS_EXPORT PrefChangeRegistrar { |
+class BASE_PREFS_EXPORT PrefChangeRegistrar : public PrefObserver { |
public: |
PrefChangeRegistrar(); |
virtual ~PrefChangeRegistrar(); |
@@ -29,13 +30,16 @@ class BASE_PREFS_EXPORT PrefChangeRegistrar { |
// Adds an pref observer for the specified pref |path| and |obs| observer |
// object. All registered observers will be automatically unregistered |
- // when the registrar's destructor is called unless the observer has been |
- // explicitly removed by a call to Remove beforehand. |
+ // when the registrar's destructor is called. |
+ // |
+ // Only one observer may be registered per path. |
+ void Add(const char* path, const base::Closure& obs); |
+ |
+ // Deprecated version of Add, soon to be removed. |
void Add(const char* path, PrefObserver* obs); |
- // Removes a preference observer that has previously been added with a call to |
- // Add. |
- void Remove(const char* path, PrefObserver* obs); |
+ // Removes the pref observer registered for |path|. |
+ void Remove(const char* path); |
// Removes all observers that have been previously added with a call to Add. |
void RemoveAll(); |
@@ -50,9 +54,13 @@ class BASE_PREFS_EXPORT PrefChangeRegistrar { |
bool IsManaged(); |
private: |
- typedef std::pair<std::string, PrefObserver*> ObserverRegistration; |
+ // PrefObserver: |
+ virtual void OnPreferenceChanged(PrefServiceBase* service, |
+ const std::string& pref_name) OVERRIDE; |
+ |
+ typedef std::map<std::string, base::Closure> ObserverMap; |
- std::set<ObserverRegistration> observers_; |
+ ObserverMap observers_; |
PrefServiceBase* service_; |
DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar); |