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

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: Merge to head for commit 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
« no previous file with comments | « base/base.gyp ('k') | base/prefs/public/pref_change_registrar.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/prefs/base_prefs_export.h" 12 #include "base/prefs/base_prefs_export.h"
13 13
14 class PrefObserver;
14 class PrefServiceBase; 15 class PrefServiceBase;
15 16
16 namespace content {
17 class NotificationObserver;
18 }
19
20 // Automatically manages the registration of one or more pref change observers 17 // Automatically manages the registration of one or more pref change observers
21 // with a PrefStore. Functions much like NotificationRegistrar, but specifically 18 // with a PrefStore. Functions much like NotificationRegistrar, but specifically
22 // manages observers of preference changes. When the Registrar is destroyed, 19 // manages observers of preference changes. When the Registrar is destroyed,
23 // all registered observers are automatically unregistered with the PrefStore. 20 // all registered observers are automatically unregistered with the PrefStore.
24 class BASE_PREFS_EXPORT PrefChangeRegistrar { 21 class BASE_PREFS_EXPORT PrefChangeRegistrar {
25 public: 22 public:
26 PrefChangeRegistrar(); 23 PrefChangeRegistrar();
27 virtual ~PrefChangeRegistrar(); 24 virtual ~PrefChangeRegistrar();
28 25
29 // Must be called before adding or removing observers. Can be called more 26 // Must be called before adding or removing observers. Can be called more
30 // than once as long as the value of |service| doesn't change. 27 // than once as long as the value of |service| doesn't change.
31 void Init(PrefServiceBase* service); 28 void Init(PrefServiceBase* service);
32 29
33 // Adds an pref observer for the specified pref |path| and |obs| observer 30 // Adds an pref observer for the specified pref |path| and |obs| observer
34 // object. All registered observers will be automatically unregistered 31 // object. All registered observers will be automatically unregistered
35 // when the registrar's destructor is called unless the observer has been 32 // when the registrar's destructor is called unless the observer has been
36 // explicitly removed by a call to Remove beforehand. 33 // explicitly removed by a call to Remove beforehand.
37 void Add(const char* path, 34 void Add(const char* path, PrefObserver* obs);
38 content::NotificationObserver* obs);
39 35
40 // Removes a preference observer that has previously been added with a call to 36 // Removes a preference observer that has previously been added with a call to
41 // Add. 37 // Add.
42 void Remove(const char* path, 38 void Remove(const char* path, PrefObserver* obs);
43 content::NotificationObserver* obs);
44 39
45 // Removes all observers that have been previously added with a call to Add. 40 // Removes all observers that have been previously added with a call to Add.
46 void RemoveAll(); 41 void RemoveAll();
47 42
48 // Returns true if no pref observers are registered. 43 // Returns true if no pref observers are registered.
49 bool IsEmpty() const; 44 bool IsEmpty() const;
50 45
51 // Check whether |pref| is in the set of preferences being observed. 46 // Check whether |pref| is in the set of preferences being observed.
52 bool IsObserved(const std::string& pref); 47 bool IsObserved(const std::string& pref);
53 48
54 // Check whether any of the observed preferences has the managed bit set. 49 // Check whether any of the observed preferences has the managed bit set.
55 bool IsManaged(); 50 bool IsManaged();
56 51
57 private: 52 private:
58 typedef std::pair<std::string, content::NotificationObserver*> 53 typedef std::pair<std::string, PrefObserver*> ObserverRegistration;
59 ObserverRegistration;
60 54
61 std::set<ObserverRegistration> observers_; 55 std::set<ObserverRegistration> observers_;
62 PrefServiceBase* service_; 56 PrefServiceBase* service_;
63 57
64 DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar); 58 DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar);
65 }; 59 };
66 60
67 #endif // BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_ 61 #endif // BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/prefs/public/pref_change_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698