OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_PREFS_PREF_REGISTRY_H_ | |
6 #define CHROME_BROWSER_PREFS_PREF_REGISTRY_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/prefs/default_pref_store.h" | |
11 #include "base/prefs/pref_value_map.h" | |
12 | |
13 namespace base { | |
14 class Value; | |
15 } | |
16 | |
17 // Preferences need to be registered with a type and default value | |
18 // before they are used. | |
19 // | |
20 // The way you use a PrefRegistry is that you register all required | |
21 // preferences on it (via one of its subclasses), then pass it as a | |
22 // construction parameter to PrefService. | |
23 // | |
24 // Currently, registrations after constructing the PrefService will | |
25 // also work, but this is being deprecated. | |
26 class PrefRegistry : public base::RefCounted<PrefRegistry> { | |
27 public: | |
28 typedef PrefValueMap::const_iterator const_iterator; | |
29 typedef base::Callback<void(const char*, base::Value*)> RegistrationCallback; | |
30 typedef base::Callback<void(const char*)> UnregistrationCallback; | |
31 | |
32 PrefRegistry(); | |
33 | |
34 // Gets the registered defaults. | |
35 scoped_refptr<PrefStore> defaults(); | |
Mattias Nissler (ping if slow)
2013/01/29 18:10:45
forward-declare PrefStore?
Jói
2013/01/30 14:23:33
Done.
| |
36 | |
37 // Allows iteration over defaults. | |
38 const_iterator begin() const; | |
39 const_iterator end() const; | |
40 | |
41 // Exactly one callback can be set for each of two events: | |
42 // Registration and unregistration. If either is set, the callback | |
43 // will be invoked each time registration and/or unregistration has | |
44 // been performed on this object. | |
45 // | |
46 // Calling either of these methods after a callback has already been | |
47 // set will make the object forget the previous callback and use the | |
48 // new one instead. | |
49 void SetRegistrationCallback(const RegistrationCallback& callback); | |
50 void SetUnregistrationCallback(const UnregistrationCallback& callback); | |
51 | |
52 // Unregisters a preference. This is going away soon. | |
53 virtual void DeprecatedUnregisterPreference(const char* path); | |
54 | |
55 protected: | |
56 friend class base::RefCounted<PrefRegistry>; | |
57 virtual ~PrefRegistry(); | |
58 | |
59 // TODO(joi): Temporary until we have PrefRegistrySyncable. | |
60 friend class PrefServiceSyncable; | |
61 | |
62 // Used by subclasses to register a default value for a preference. | |
63 void RegisterPreference(const char* path, base::Value* default_value); | |
64 | |
65 private: | |
66 RegistrationCallback registration_callback_; | |
67 UnregistrationCallback unregistration_callback_; | |
68 scoped_refptr<DefaultPrefStore> defaults_; | |
Mattias Nissler (ping if slow)
2013/01/29 18:10:45
could be forward-declared?
Jói
2013/01/30 14:23:33
Done.
| |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); | |
71 }; | |
72 | |
73 #endif // CHROME_BROWSER_PREFS_PREF_REGISTRY_H_ | |
OLD | NEW |