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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/prefs/base_prefs_export.h" | 9 #include "base/prefs/base_prefs_export.h" |
10 #include "base/prefs/pref_value_map.h" | 10 #include "base/prefs/pref_value_map.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class Value; | 13 class Value; |
14 } | 14 } |
15 | 15 |
16 class DefaultPrefStore; | 16 class DefaultPrefStore; |
17 class PrefStore; | 17 class PrefStore; |
18 | 18 |
19 // Preferences need to be registered with a type and default value | 19 // Preferences need to be registered with a type and default value |
20 // before they are used. | 20 // before they are used. |
21 // | 21 // |
22 // 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 |
23 // 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 |
24 // construction parameter to PrefService. | 24 // construction parameter to PrefService. |
25 // | 25 // |
26 // Currently, registrations after constructing the PrefService will | 26 // Currently, registrations after constructing the PrefService will |
27 // also work, but this is being deprecated. | 27 // also work, but this is being deprecated. |
28 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { | 28 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { |
29 public: | 29 public: |
30 // Registration flags that can be specified which impact how the pref will | |
31 // behave or be stored. This will be passed in a bitmask when the pref is | |
32 // registered. Subclasses of PrefRegistry can specify their own flags. Care | |
33 // must be taken to ensure none of these overlap with the flags below. | |
34 enum PrefRegistrationFlags { | |
35 // No flags are specified. | |
36 NO_REGISTRATION_FLAGS = 0, | |
37 | |
38 // The first 8 bits are reserved for subclasses of PrefRegistry to use. | |
39 }; | |
40 | |
30 typedef PrefValueMap::const_iterator const_iterator; | 41 typedef PrefValueMap::const_iterator const_iterator; |
42 typedef std::map<std::string, uint32> PrefRegistrationFlagsMap; | |
31 | 43 |
32 PrefRegistry(); | 44 PrefRegistry(); |
33 | 45 |
46 // Retrieve the set of registration flags for preferences currently | |
47 // registered. | |
48 const PrefRegistrationFlagsMap& registration_flags() const { | |
Mattias Nissler (ping if slow)
2015/04/22 07:06:34
OK, so you made the change to not store entries if
raymes
2015/04/23 05:21:03
Done.
| |
49 return registration_flags_; | |
50 } | |
51 | |
34 // Gets the registered defaults. | 52 // Gets the registered defaults. |
35 scoped_refptr<PrefStore> defaults(); | 53 scoped_refptr<PrefStore> defaults(); |
36 | 54 |
37 // Allows iteration over defaults. | 55 // Allows iteration over defaults. |
38 const_iterator begin() const; | 56 const_iterator begin() const; |
39 const_iterator end() const; | 57 const_iterator end() const; |
40 | 58 |
41 // Changes the default value for a preference. Takes ownership of |value|. | 59 // Changes the default value for a preference. Takes ownership of |value|. |
42 // | 60 // |
43 // |pref_name| must be a previously registered preference. | 61 // |pref_name| must be a previously registered preference. |
44 void SetDefaultPrefValue(const std::string& pref_name, base::Value* value); | 62 void SetDefaultPrefValue(const std::string& pref_name, base::Value* value); |
45 | 63 |
46 protected: | 64 protected: |
47 friend class base::RefCounted<PrefRegistry>; | 65 friend class base::RefCounted<PrefRegistry>; |
48 virtual ~PrefRegistry(); | 66 virtual ~PrefRegistry(); |
49 | 67 |
50 // Used by subclasses to register a default value for a preference. | 68 // Used by subclasses to register a default value and registration flags for |
51 void RegisterPreference(const std::string& path, base::Value* default_value); | 69 // a preference. |flags| is a bitmask of |PrefRegistrationFlags|. |
70 void RegisterPreference(const std::string& path, | |
71 base::Value* default_value, | |
72 uint32 flags); | |
52 | 73 |
53 scoped_refptr<DefaultPrefStore> defaults_; | 74 scoped_refptr<DefaultPrefStore> defaults_; |
54 | 75 |
76 // A map of pref name to a bitmask of PrefRegistrationFlags. | |
77 PrefRegistrationFlagsMap registration_flags_; | |
78 | |
55 private: | 79 private: |
56 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); | 80 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); |
57 }; | 81 }; |
58 | 82 |
59 #endif // BASE_PREFS_PREF_REGISTRY_H_ | 83 #endif // BASE_PREFS_PREF_REGISTRY_H_ |
OLD | NEW |