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 COMPONENTS_PREFS_PREF_VALUE_STORE_H_ | 5 #ifndef COMPONENTS_PREFS_PREF_VALUE_STORE_H_ |
6 #define COMPONENTS_PREFS_PREF_VALUE_STORE_H_ | 6 #define COMPONENTS_PREFS_PREF_VALUE_STORE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... |
23 // (e.g., configuration policies, extensions, and user settings). It returns | 23 // (e.g., configuration policies, extensions, and user settings). It returns |
24 // the value of a Preference from the source with the highest priority, and | 24 // the value of a Preference from the source with the highest priority, and |
25 // allows setting user-defined values for preferences that are not managed. | 25 // allows setting user-defined values for preferences that are not managed. |
26 // | 26 // |
27 // Unless otherwise explicitly noted, all of the methods of this class must | 27 // Unless otherwise explicitly noted, all of the methods of this class must |
28 // be called on the UI thread. | 28 // be called on the UI thread. |
29 class COMPONENTS_PREFS_EXPORT PrefValueStore { | 29 class COMPONENTS_PREFS_EXPORT PrefValueStore { |
30 public: | 30 public: |
31 typedef base::Callback<void(const std::string&)> PrefChangedCallback; | 31 typedef base::Callback<void(const std::string&)> PrefChangedCallback; |
32 | 32 |
| 33 // PrefStores must be listed here in order from highest to lowest priority. |
| 34 // MANAGED contains all managed preference values that are provided by |
| 35 // mandatory policies (e.g. Windows Group Policy or cloud policy). |
| 36 // SUPERVISED_USER contains preferences that are valid for supervised users. |
| 37 // EXTENSION contains preference values set by extensions. |
| 38 // COMMAND_LINE contains preference values set by command-line switches. |
| 39 // USER contains all user-set preference values. |
| 40 // RECOMMENDED contains all preferences that are provided by recommended |
| 41 // policies. |
| 42 // DEFAULT contains all application default preference values. |
| 43 enum PrefStoreType { |
| 44 // INVALID_STORE is not associated with an actual PrefStore but used as |
| 45 // an invalid marker, e.g. as a return value. |
| 46 INVALID_STORE = -1, |
| 47 MANAGED_STORE = 0, |
| 48 SUPERVISED_USER_STORE, |
| 49 EXTENSION_STORE, |
| 50 COMMAND_LINE_STORE, |
| 51 USER_STORE, |
| 52 RECOMMENDED_STORE, |
| 53 DEFAULT_STORE, |
| 54 PREF_STORE_TYPE_MAX = DEFAULT_STORE |
| 55 }; |
| 56 |
33 // In decreasing order of precedence: | 57 // In decreasing order of precedence: |
34 // |managed_prefs| contains all preferences from mandatory policies. | 58 // |managed_prefs| contains all preferences from mandatory policies. |
35 // |supervised_user_prefs| contains all preferences from supervised user | 59 // |supervised_user_prefs| contains all preferences from supervised user |
36 // settings, i.e. settings configured for a supervised user by their | 60 // settings, i.e. settings configured for a supervised user by their |
37 // custodian. | 61 // custodian. |
38 // |extension_prefs| contains preference values set by extensions. | 62 // |extension_prefs| contains preference values set by extensions. |
39 // |command_line_prefs| contains preference values set by command-line | 63 // |command_line_prefs| contains preference values set by command-line |
40 // switches. | 64 // switches. |
41 // |user_prefs| contains all user-set preference values. | 65 // |user_prefs| contains all user-set preference values. |
42 // |recommended_prefs| contains all preferences from recommended policies. | 66 // |recommended_prefs| contains all preferences from recommended policies. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 bool PrefValueUserModifiable(const std::string& name) const; | 135 bool PrefValueUserModifiable(const std::string& name) const; |
112 | 136 |
113 // Check whether a Preference value is modifiable by an extension, i.e. | 137 // Check whether a Preference value is modifiable by an extension, i.e. |
114 // whether there is no higher-priority source controlling it. | 138 // whether there is no higher-priority source controlling it. |
115 bool PrefValueExtensionModifiable(const std::string& name) const; | 139 bool PrefValueExtensionModifiable(const std::string& name) const; |
116 | 140 |
117 // Update the command line PrefStore with |command_line_prefs|. | 141 // Update the command line PrefStore with |command_line_prefs|. |
118 void UpdateCommandLinePrefStore(PrefStore* command_line_prefs); | 142 void UpdateCommandLinePrefStore(PrefStore* command_line_prefs); |
119 | 143 |
120 private: | 144 private: |
121 // PrefStores must be listed here in order from highest to lowest priority. | |
122 // MANAGED contains all managed preference values that are provided by | |
123 // mandatory policies (e.g. Windows Group Policy or cloud policy). | |
124 // SUPERVISED_USER contains preferences that are valid for supervised users. | |
125 // EXTENSION contains preference values set by extensions. | |
126 // COMMAND_LINE contains preference values set by command-line switches. | |
127 // USER contains all user-set preference values. | |
128 // RECOMMENDED contains all preferences that are provided by recommended | |
129 // policies. | |
130 // DEFAULT contains all application default preference values. | |
131 enum PrefStoreType { | |
132 // INVALID_STORE is not associated with an actual PrefStore but used as | |
133 // an invalid marker, e.g. as a return value. | |
134 INVALID_STORE = -1, | |
135 MANAGED_STORE = 0, | |
136 SUPERVISED_USER_STORE, | |
137 EXTENSION_STORE, | |
138 COMMAND_LINE_STORE, | |
139 USER_STORE, | |
140 RECOMMENDED_STORE, | |
141 DEFAULT_STORE, | |
142 PREF_STORE_TYPE_MAX = DEFAULT_STORE | |
143 }; | |
144 | |
145 // Keeps a PrefStore reference on behalf of the PrefValueStore and monitors | 145 // Keeps a PrefStore reference on behalf of the PrefValueStore and monitors |
146 // the PrefStore for changes, forwarding notifications to PrefValueStore. This | 146 // the PrefStore for changes, forwarding notifications to PrefValueStore. This |
147 // indirection is here for the sake of disambiguating notifications from the | 147 // indirection is here for the sake of disambiguating notifications from the |
148 // individual PrefStores. | 148 // individual PrefStores. |
149 class PrefStoreKeeper : public PrefStore::Observer { | 149 class PrefStoreKeeper : public PrefStore::Observer { |
150 public: | 150 public: |
151 PrefStoreKeeper(); | 151 PrefStoreKeeper(); |
152 ~PrefStoreKeeper() override; | 152 ~PrefStoreKeeper() override; |
153 | 153 |
154 // Takes ownership of |pref_store|. | 154 // Takes ownership of |pref_store|. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 250 |
251 // A mapping of preference names to their registered types. | 251 // A mapping of preference names to their registered types. |
252 PrefTypeMap pref_types_; | 252 PrefTypeMap pref_types_; |
253 | 253 |
254 // True if not all of the PrefStores were initialized successfully. | 254 // True if not all of the PrefStores were initialized successfully. |
255 bool initialization_failed_; | 255 bool initialization_failed_; |
256 | 256 |
257 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 257 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
258 }; | 258 }; |
259 | 259 |
| 260 namespace std { |
| 261 |
| 262 template <> |
| 263 struct hash<PrefValueStore::PrefStoreType> { |
| 264 size_t operator()(PrefValueStore::PrefStoreType type) const { |
| 265 return std::hash< |
| 266 base::underlying_type<PrefValueStore::PrefStoreType>::type>()(type); |
| 267 } |
| 268 }; |
| 269 |
| 270 } // namespace std |
| 271 |
260 #endif // COMPONENTS_PREFS_PREF_VALUE_STORE_H_ | 272 #endif // COMPONENTS_PREFS_PREF_VALUE_STORE_H_ |
OLD | NEW |