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

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

Issue 11368098: Draft change to use base::Closure instead of PrefObserver in PrefChangeRegistrar. (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 #include "base/callback.h"
12 #include "base/prefs/base_prefs_export.h" 13 #include "base/prefs/base_prefs_export.h"
13 14
14 class PrefObserver; 15 class PrefObserver;
15 class PrefServiceBase; 16 class PrefServiceBase;
16 17
17 // Automatically manages the registration of one or more pref change observers 18 // Automatically manages the registration of one or more pref change observers
18 // with a PrefStore. Functions much like NotificationRegistrar, but specifically 19 // with a PrefStore. Functions much like NotificationRegistrar, but specifically
19 // manages observers of preference changes. When the Registrar is destroyed, 20 // manages observers of preference changes. When the Registrar is destroyed,
20 // all registered observers are automatically unregistered with the PrefStore. 21 // all registered observers are automatically unregistered with the PrefStore.
21 class BASE_PREFS_EXPORT PrefChangeRegistrar { 22 class BASE_PREFS_EXPORT PrefChangeRegistrar {
22 public: 23 public:
23 PrefChangeRegistrar(); 24 PrefChangeRegistrar();
24 virtual ~PrefChangeRegistrar(); 25 virtual ~PrefChangeRegistrar();
25 26
26 // Must be called before adding or removing observers. Can be called more 27 // Must be called before adding or removing observers. Can be called more
27 // than once as long as the value of |service| doesn't change. 28 // than once as long as the value of |service| doesn't change.
28 void Init(PrefServiceBase* service); 29 void Init(PrefServiceBase* service);
29 30
30 // Adds an pref observer for the specified pref |path| and |obs| observer 31 // Adds an pref observer for the specified pref |path| and |obs| observer
31 // object. All registered observers will be automatically unregistered 32 // object. All registered observers will be automatically unregistered
32 // when the registrar's destructor is called unless the observer has been 33 // when the registrar's destructor is called unless the observer has been
33 // explicitly removed by a call to Remove beforehand. 34 // explicitly removed by a call to Remove beforehand.
34 void Add(const char* path, PrefObserver* obs); 35 void Add(const char* path, PrefObserver* obs);
36 void Add(const char* path, const base::Closure& obs);
35 37
36 // Removes a preference observer that has previously been added with a call to 38 // Removes a preference observer that has previously been added with
37 // Add. 39 // a call to Add. Note that in the base::Callback version of this
40 // method, you must pass an object whose Equal() method returns true
41 // when compared to the callback you registered via Add().
38 void Remove(const char* path, PrefObserver* obs); 42 void Remove(const char* path, PrefObserver* obs);
43 void Remove(const char* path, const base::Closure& obs);
39 44
40 // Removes all observers that have been previously added with a call to Add. 45 // Removes all observers that have been previously added with a call to Add.
41 void RemoveAll(); 46 void RemoveAll();
42 47
43 // Returns true if no pref observers are registered. 48 // Returns true if no pref observers are registered.
44 bool IsEmpty() const; 49 bool IsEmpty() const;
45 50
46 // Check whether |pref| is in the set of preferences being observed. 51 // Check whether |pref| is in the set of preferences being observed.
47 bool IsObserved(const std::string& pref); 52 bool IsObserved(const std::string& pref);
48 53
49 // Check whether any of the observed preferences has the managed bit set. 54 // Check whether any of the observed preferences has the managed bit set.
50 bool IsManaged(); 55 bool IsManaged();
51 56
52 private: 57 private:
53 typedef std::pair<std::string, PrefObserver*> ObserverRegistration; 58 typedef std::pair<std::string, base::Closure> ObserverRegistration;
54 59
55 std::set<ObserverRegistration> observers_; 60 std::set<ObserverRegistration> observers_;
56 PrefServiceBase* service_; 61 PrefServiceBase* service_;
57 62
58 DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar); 63 DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar);
59 }; 64 };
60 65
61 #endif // BASE_PREFS_PUBLIC_PREF_CHANGE_REGISTRAR_H_ 66 #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_change_registrar.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698