Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: base/prefs/public/pref_change_registrar.h

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_ 5 #ifndef BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_
6 #define BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_ 6 #define BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 12
13 class PrefObserver;
13 class PrefServiceBase; 14 class PrefServiceBase;
14 15
15 namespace content {
16 class NotificationObserver;
17 }
18
19 // Automatically manages the registration of one or more pref change observers 16 // Automatically manages the registration of one or more pref change observers
20 // with a PrefStore. Functions much like NotificationRegistrar, but specifically 17 // with a PrefStore. Functions much like NotificationRegistrar, but specifically
21 // manages observers of preference changes. When the Registrar is destroyed, 18 // manages observers of preference changes. When the Registrar is destroyed,
22 // all registered observers are automatically unregistered with the PrefStore. 19 // all registered observers are automatically unregistered with the PrefStore.
23 class PrefChangeRegistrar { 20 class PrefChangeRegistrar {
24 public: 21 public:
25 PrefChangeRegistrar(); 22 PrefChangeRegistrar();
26 virtual ~PrefChangeRegistrar(); 23 virtual ~PrefChangeRegistrar();
27 24
28 // Must be called before adding or removing observers. Can be called more 25 // Must be called before adding or removing observers. Can be called more
29 // than once as long as the value of |service| doesn't change. 26 // than once as long as the value of |service| doesn't change.
30 void Init(PrefServiceBase* service); 27 void Init(PrefServiceBase* service);
31 28
32 // Adds an pref observer for the specified pref |path| and |obs| observer 29 // Adds an pref observer for the specified pref |path| and |obs| observer
33 // object. All registered observers will be automatically unregistered 30 // object. All registered observers will be automatically unregistered
34 // when the registrar's destructor is called unless the observer has been 31 // when the registrar's destructor is called unless the observer has been
35 // explicitly removed by a call to Remove beforehand. 32 // explicitly removed by a call to Remove beforehand.
36 void Add(const char* path, 33 void Add(const char* path, PrefObserver* obs);
37 content::NotificationObserver* obs);
38 34
39 // Removes a preference observer that has previously been added with a call to 35 // Removes a preference observer that has previously been added with a call to
40 // Add. 36 // Add.
41 void Remove(const char* path, 37 void Remove(const char* path, PrefObserver* obs);
42 content::NotificationObserver* obs);
43 38
44 // Removes all observers that have been previously added with a call to Add. 39 // Removes all observers that have been previously added with a call to Add.
45 void RemoveAll(); 40 void RemoveAll();
46 41
47 // Returns true if no pref observers are registered. 42 // Returns true if no pref observers are registered.
48 bool IsEmpty() const; 43 bool IsEmpty() const;
49 44
50 // Check whether |pref| is in the set of preferences being observed. 45 // Check whether |pref| is in the set of preferences being observed.
51 bool IsObserved(const std::string& pref); 46 bool IsObserved(const std::string& pref);
52 47
53 // Check whether any of the observed preferences has the managed bit set. 48 // Check whether any of the observed preferences has the managed bit set.
54 bool IsManaged(); 49 bool IsManaged();
55 50
56 private: 51 private:
57 typedef std::pair<std::string, content::NotificationObserver*> 52 typedef std::pair<std::string, PrefObserver*> ObserverRegistration;
58 ObserverRegistration;
59 53
60 std::set<ObserverRegistration> observers_; 54 std::set<ObserverRegistration> observers_;
61 PrefServiceBase* service_; 55 PrefServiceBase* service_;
62 56
63 DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar); 57 DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar);
64 }; 58 };
65 59
66 #endif // BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_ 60 #endif // BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_
OLDNEW
« no previous file with comments | « no previous file | base/prefs/public/pref_change_registrar.cc » ('j') | base/prefs/public/pref_init_observer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698