OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_PREF_REGISTRY_H_ | 5 #ifndef BASE_PREFS_PREF_REGISTRY_H_ |
6 #define BASE_PREFS_PREF_REGISTRY_H_ | 6 #define BASE_PREFS_PREF_REGISTRY_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/prefs/base_prefs_export.h" | 10 #include "base/prefs/base_prefs_export.h" |
11 #include "base/prefs/pref_value_map.h" | 11 #include "base/prefs/pref_value_map.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class Value; | 14 class Value; |
15 } | 15 } |
16 | 16 |
17 class DefaultPrefStore; | 17 class DefaultPrefStore; |
18 class PrefStore; | |
19 | 18 |
20 // Preferences need to be registered with a type and default value | 19 // Preferences need to be registered with a type and default value |
21 // before they are used. | 20 // before they are used. |
22 // | 21 // |
23 // The way you use a PrefRegistry is that you register all required | 22 // The way you use a PrefRegistry is that you register all required |
24 // preferences on it (via one of its subclasses), then pass it as a | 23 // preferences on it (via one of its subclasses), then pass it as a |
25 // construction parameter to PrefService. | 24 // construction parameter to PrefService. |
26 // | 25 // |
27 // Currently, registrations after constructing the PrefService will | 26 // Currently, registrations after constructing the PrefService will |
28 // also work, but this is being deprecated. | 27 // also work, but this is being deprecated. |
29 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { | 28 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { |
30 public: | 29 public: |
31 typedef PrefValueMap::const_iterator const_iterator; | 30 typedef PrefValueMap::const_iterator const_iterator; |
32 typedef base::Callback<void(const char*, base::Value*)> RegistrationCallback; | 31 typedef base::Callback<void(const char*, base::Value*)> RegistrationCallback; |
33 | 32 |
34 PrefRegistry(); | 33 PrefRegistry(); |
35 | 34 |
36 // Gets the registered defaults. | 35 // Gets the registered defaults. |
37 scoped_refptr<PrefStore> defaults(); | 36 scoped_refptr<DefaultPrefStore> defaults(); |
Mattias Nissler (ping if slow)
2013/02/27 10:50:52
I think we should rather not expose the DefaultPre
Jói
2013/02/27 16:30:56
Done.
| |
38 | |
39 // Allows iteration over defaults. | |
40 const_iterator begin() const; | |
41 const_iterator end() const; | |
42 | 37 |
43 // Exactly one callback can be set for registration. The callback | 38 // Exactly one callback can be set for registration. The callback |
44 // will be invoked each time registration has been performed on this | 39 // will be invoked each time registration has been performed on this |
45 // object. | 40 // object. |
46 // | 41 // |
47 // Calling this method after a callback has already been set will | 42 // Calling this method after a callback has already been set will |
48 // make the object forget the previous callback and use the new one | 43 // make the object forget the previous callback and use the new one |
49 // instead. | 44 // instead. |
50 void SetRegistrationCallback(const RegistrationCallback& callback); | 45 void SetRegistrationCallback(const RegistrationCallback& callback); |
51 | 46 |
52 protected: | 47 protected: |
53 friend class base::RefCounted<PrefRegistry>; | 48 friend class base::RefCounted<PrefRegistry>; |
54 virtual ~PrefRegistry(); | 49 virtual ~PrefRegistry(); |
55 | 50 |
56 // Used by subclasses to register a default value for a preference. | 51 // Used by subclasses to register a default value for a preference. |
57 void RegisterPreference(const char* path, base::Value* default_value); | 52 void RegisterPreference(const char* path, base::Value* default_value); |
58 | 53 |
59 scoped_refptr<DefaultPrefStore> defaults_; | 54 scoped_refptr<DefaultPrefStore> defaults_; |
60 | 55 |
61 private: | 56 private: |
62 RegistrationCallback registration_callback_; | 57 RegistrationCallback registration_callback_; |
63 | 58 |
64 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); | 59 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); |
65 }; | 60 }; |
66 | 61 |
67 #endif // BASE_PREFS_PREF_REGISTRY_H_ | 62 #endif // BASE_PREFS_PREF_REGISTRY_H_ |
OLD | NEW |