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_VALUE_STORE_H_ | 5 #ifndef BASE_PREFS_PREF_VALUE_STORE_H_ |
6 #define BASE_PREFS_PREF_VALUE_STORE_H_ | 6 #define BASE_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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // the matching |name| but a non-matching |type| is silently ignored. Returns | 87 // the matching |name| but a non-matching |type| is silently ignored. Returns |
88 // true if a valid value was found. Most callers should use | 88 // true if a valid value was found. Most callers should use |
89 // Preference::GetRecommendedValue() instead of calling this method directly. | 89 // Preference::GetRecommendedValue() instead of calling this method directly. |
90 bool GetRecommendedValue(const std::string& name, | 90 bool GetRecommendedValue(const std::string& name, |
91 base::Value::Type type, | 91 base::Value::Type type, |
92 const base::Value** out_value) const; | 92 const base::Value** out_value) const; |
93 | 93 |
94 // These methods return true if a preference with the given name is in the | 94 // These methods return true if a preference with the given name is in the |
95 // indicated pref store, even if that value is currently being overridden by | 95 // indicated pref store, even if that value is currently being overridden by |
96 // a higher-priority source. | 96 // a higher-priority source. |
97 bool PrefValueInManagedStore(const char* name) const; | 97 bool PrefValueInManagedStore(const std::string& name) const; |
98 bool PrefValueInExtensionStore(const char* name) const; | 98 bool PrefValueInExtensionStore(const std::string& name) const; |
99 bool PrefValueInUserStore(const char* name) const; | 99 bool PrefValueInUserStore(const std::string& name) const; |
100 | 100 |
101 // These methods return true if a preference with the given name is actually | 101 // These methods return true if a preference with the given name is actually |
102 // being controlled by the indicated pref store and not being overridden by | 102 // being controlled by the indicated pref store and not being overridden by |
103 // a higher-priority source. | 103 // a higher-priority source. |
104 bool PrefValueFromExtensionStore(const char* name) const; | 104 bool PrefValueFromExtensionStore(const std::string& name) const; |
105 bool PrefValueFromUserStore(const char* name) const; | 105 bool PrefValueFromUserStore(const std::string& name) const; |
106 bool PrefValueFromRecommendedStore(const char* name) const; | 106 bool PrefValueFromRecommendedStore(const std::string& name) const; |
107 bool PrefValueFromDefaultStore(const char* name) const; | 107 bool PrefValueFromDefaultStore(const std::string& name) const; |
108 | 108 |
109 // Check whether a Preference value is modifiable by the user, i.e. whether | 109 // Check whether a Preference value is modifiable by the user, i.e. whether |
110 // there is no higher-priority source controlling it. | 110 // there is no higher-priority source controlling it. |
111 bool PrefValueUserModifiable(const char* name) const; | 111 bool PrefValueUserModifiable(const std::string& name) const; |
112 | 112 |
113 // Check whether a Preference value is modifiable by an extension, i.e. | 113 // Check whether a Preference value is modifiable by an extension, i.e. |
114 // whether there is no higher-priority source controlling it. | 114 // whether there is no higher-priority source controlling it. |
115 bool PrefValueExtensionModifiable(const char* name) const; | 115 bool PrefValueExtensionModifiable(const std::string& name) const; |
116 | 116 |
117 // Update the command line PrefStore with |command_line_prefs|. | 117 // Update the command line PrefStore with |command_line_prefs|. |
118 void UpdateCommandLinePrefStore(PrefStore* command_line_prefs); | 118 void UpdateCommandLinePrefStore(PrefStore* command_line_prefs); |
119 | 119 |
120 private: | 120 private: |
121 // PrefStores must be listed here in order from highest to lowest priority. | 121 // PrefStores must be listed here in order from highest to lowest priority. |
122 // MANAGED contains all managed preference values that are provided by | 122 // MANAGED contains all managed preference values that are provided by |
123 // mandatory policies (e.g. Windows Group Policy or cloud policy). | 123 // mandatory policies (e.g. Windows Group Policy or cloud policy). |
124 // SUPERVISED_USER contains preferences that are valid for supervised users. | 124 // SUPERVISED_USER contains preferences that are valid for supervised users. |
125 // EXTENSION contains preference values set by extensions. | 125 // EXTENSION contains preference values set by extensions. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 friend class PrefValueStorePolicyRefreshTest; | 181 friend class PrefValueStorePolicyRefreshTest; |
182 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); | 182 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); |
183 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, | 183 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, |
184 TestRefreshPolicyPrefsCompletion); | 184 TestRefreshPolicyPrefsCompletion); |
185 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, | 185 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, |
186 TestConcurrentPolicyRefresh); | 186 TestConcurrentPolicyRefresh); |
187 | 187 |
188 // Returns true if the preference with the given name has a value in the | 188 // Returns true if the preference with the given name has a value in the |
189 // given PrefStoreType, of the same value type as the preference was | 189 // given PrefStoreType, of the same value type as the preference was |
190 // registered with. | 190 // registered with. |
191 bool PrefValueInStore(const char* name, PrefStoreType store) const; | 191 bool PrefValueInStore(const std::string& name, PrefStoreType store) const; |
192 | 192 |
193 // Returns true if a preference has an explicit value in any of the | 193 // Returns true if a preference has an explicit value in any of the |
194 // stores in the range specified by |first_checked_store| and | 194 // stores in the range specified by |first_checked_store| and |
195 // |last_checked_store|, even if that value is currently being | 195 // |last_checked_store|, even if that value is currently being |
196 // overridden by a higher-priority store. | 196 // overridden by a higher-priority store. |
197 bool PrefValueInStoreRange(const char* name, | 197 bool PrefValueInStoreRange(const std::string& name, |
198 PrefStoreType first_checked_store, | 198 PrefStoreType first_checked_store, |
199 PrefStoreType last_checked_store) const; | 199 PrefStoreType last_checked_store) const; |
200 | 200 |
201 // Returns the pref store type identifying the source that controls the | 201 // Returns the pref store type identifying the source that controls the |
202 // Preference identified by |name|. If none of the sources has a value, | 202 // Preference identified by |name|. If none of the sources has a value, |
203 // INVALID_STORE is returned. In practice, the default PrefStore | 203 // INVALID_STORE is returned. In practice, the default PrefStore |
204 // should always have a value for any registered preferencem, so INVALID_STORE | 204 // should always have a value for any registered preferencem, so INVALID_STORE |
205 // indicates an error. | 205 // indicates an error. |
206 PrefStoreType ControllingPrefStoreForPref(const char* name) const; | 206 PrefStoreType ControllingPrefStoreForPref(const std::string& name) const; |
207 | 207 |
208 // Get a value from the specified |store|. | 208 // Get a value from the specified |store|. |
209 bool GetValueFromStore(const char* name, | 209 bool GetValueFromStore(const std::string& name, |
210 PrefStoreType store, | 210 PrefStoreType store, |
211 const base::Value** out_value) const; | 211 const base::Value** out_value) const; |
212 | 212 |
213 // Get a value from the specified |store| if its |type| matches. | 213 // Get a value from the specified |store| if its |type| matches. |
214 bool GetValueFromStoreWithType(const char* name, | 214 bool GetValueFromStoreWithType(const std::string& name, |
215 base::Value::Type type, | 215 base::Value::Type type, |
216 PrefStoreType store, | 216 PrefStoreType store, |
217 const base::Value** out_value) const; | 217 const base::Value** out_value) const; |
218 | 218 |
219 // Called upon changes in individual pref stores in order to determine whether | 219 // Called upon changes in individual pref stores in order to determine whether |
220 // the user-visible pref value has changed. Triggers the change notification | 220 // the user-visible pref value has changed. Triggers the change notification |
221 // if the effective value of the preference has changed, or if the store | 221 // if the effective value of the preference has changed, or if the store |
222 // controlling the pref has changed. | 222 // controlling the pref has changed. |
223 void NotifyPrefChanged(const char* path, PrefStoreType new_store); | 223 void NotifyPrefChanged(const std::string& path, PrefStoreType new_store); |
224 | 224 |
225 // Called from the PrefStoreKeeper implementation when a pref value for |key| | 225 // Called from the PrefStoreKeeper implementation when a pref value for |key| |
226 // changed in the pref store for |type|. | 226 // changed in the pref store for |type|. |
227 void OnPrefValueChanged(PrefStoreType type, const std::string& key); | 227 void OnPrefValueChanged(PrefStoreType type, const std::string& key); |
228 | 228 |
229 // Handle the event that the store for |type| has completed initialization. | 229 // Handle the event that the store for |type| has completed initialization. |
230 void OnInitializationCompleted(PrefStoreType type, bool succeeded); | 230 void OnInitializationCompleted(PrefStoreType type, bool succeeded); |
231 | 231 |
232 // Initializes a pref store keeper. Sets up a PrefStoreKeeper that will take | 232 // Initializes a pref store keeper. Sets up a PrefStoreKeeper that will take |
233 // ownership of the passed |pref_store|. | 233 // ownership of the passed |pref_store|. |
(...skipping 24 matching lines...) Expand all Loading... |
258 // A mapping of preference names to their registered types. | 258 // A mapping of preference names to their registered types. |
259 PrefTypeMap pref_types_; | 259 PrefTypeMap pref_types_; |
260 | 260 |
261 // True if not all of the PrefStores were initialized successfully. | 261 // True if not all of the PrefStores were initialized successfully. |
262 bool initialization_failed_; | 262 bool initialization_failed_; |
263 | 263 |
264 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 264 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
265 }; | 265 }; |
266 | 266 |
267 #endif // BASE_PREFS_PREF_VALUE_STORE_H_ | 267 #endif // BASE_PREFS_PREF_VALUE_STORE_H_ |
OLD | NEW |