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 // This provides a way to access the application's current preferences. | 5 // This provides a way to access the application's current preferences. |
6 | 6 |
7 // Chromium settings and storage represent user-selected preferences and | 7 // Chromium settings and storage represent user-selected preferences and |
8 // information and MUST not be extracted, overwritten or modified except | 8 // information and MUST not be extracted, overwritten or modified except |
9 // through Chromium defined APIs. | 9 // through Chromium defined APIs. |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // extracted, overwritten or modified except through the defined APIs. | 53 // extracted, overwritten or modified except through the defined APIs. |
54 class COMPONENTS_PREFS_EXPORT PrefService : public base::NonThreadSafe { | 54 class COMPONENTS_PREFS_EXPORT PrefService : public base::NonThreadSafe { |
55 public: | 55 public: |
56 enum PrefInitializationStatus { | 56 enum PrefInitializationStatus { |
57 INITIALIZATION_STATUS_WAITING, | 57 INITIALIZATION_STATUS_WAITING, |
58 INITIALIZATION_STATUS_SUCCESS, | 58 INITIALIZATION_STATUS_SUCCESS, |
59 INITIALIZATION_STATUS_CREATED_NEW_PREF_STORE, | 59 INITIALIZATION_STATUS_CREATED_NEW_PREF_STORE, |
60 INITIALIZATION_STATUS_ERROR | 60 INITIALIZATION_STATUS_ERROR |
61 }; | 61 }; |
62 | 62 |
| 63 enum IncludeDefaults { |
| 64 INCLUDE_DEFAULTS, |
| 65 EXCLUDE_DEFAULTS, |
| 66 }; |
| 67 |
63 // A helper class to store all the information associated with a preference. | 68 // A helper class to store all the information associated with a preference. |
64 class COMPONENTS_PREFS_EXPORT Preference { | 69 class COMPONENTS_PREFS_EXPORT Preference { |
65 public: | 70 public: |
66 // The type of the preference is determined by the type with which it is | 71 // The type of the preference is determined by the type with which it is |
67 // registered. This type needs to be a boolean, integer, double, string, | 72 // registered. This type needs to be a boolean, integer, double, string, |
68 // dictionary (a branch), or list. You shouldn't need to construct this on | 73 // dictionary (a branch), or list. You shouldn't need to construct this on |
69 // your own; use the PrefService::Register*Pref methods instead. | 74 // your own; use the PrefService::Register*Pref methods instead. |
70 Preference(const PrefService* service, | 75 Preference(const PrefService* service, |
71 const std::string& name, | 76 const std::string& name, |
72 base::Value::Type type); | 77 base::Value::Type type); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // Returns the default value of the given preference. |path| must point to a | 248 // Returns the default value of the given preference. |path| must point to a |
244 // registered preference. In that case, will never return NULL. | 249 // registered preference. In that case, will never return NULL. |
245 const base::Value* GetDefaultPrefValue(const std::string& path) const; | 250 const base::Value* GetDefaultPrefValue(const std::string& path) const; |
246 | 251 |
247 // Returns true if a value has been set for the specified path. | 252 // Returns true if a value has been set for the specified path. |
248 // NOTE: this is NOT the same as FindPreference. In particular | 253 // NOTE: this is NOT the same as FindPreference. In particular |
249 // FindPreference returns whether RegisterXXX has been invoked, where as | 254 // FindPreference returns whether RegisterXXX has been invoked, where as |
250 // this checks if a value exists for the path. | 255 // this checks if a value exists for the path. |
251 bool HasPrefPath(const std::string& path) const; | 256 bool HasPrefPath(const std::string& path) const; |
252 | 257 |
253 // Returns a dictionary with effective preference values. | 258 // Issues a callback for every preference value. The preferences must not be |
254 std::unique_ptr<base::DictionaryValue> GetPreferenceValues() const; | 259 // mutated during iteration. |
| 260 void IteratePreferenceValues( |
| 261 base::RepeatingCallback<void(const std::string& key, |
| 262 const base::Value& value)> callback) const; |
255 | 263 |
256 // Returns a dictionary with effective preference values, omitting prefs that | 264 // Returns a dictionary with effective preference values. This is an expensive |
257 // are at their default values. | 265 // operation which does a deep copy. Use only if you really need the results |
258 std::unique_ptr<base::DictionaryValue> GetPreferenceValuesOmitDefaults() | 266 // in a base::Value (for example, for JSON serialization). Otherwise use |
259 const; | 267 // IteratePreferenceValues above to avoid the copies. |
260 | 268 // |
261 // Returns a dictionary with effective preference values. Contrary to | 269 // If INCLUDE_DEFAULTS is requested, preferences set to their default values |
262 // GetPreferenceValues(), the paths of registered preferences are not split on | 270 // will be included. Otherwise, these will be omitted from the returned |
263 // '.' characters. If a registered preference stores a dictionary, however, | 271 // dictionary. |
264 // the hierarchical structure inside the preference will be preserved. | 272 std::unique_ptr<base::DictionaryValue> GetPreferenceValues( |
265 // For example, if "foo.bar" is a registered preference, the result could look | 273 IncludeDefaults include_defaults) const; |
266 // like this: | |
267 // {"foo.bar": {"a": {"b": true}}}. | |
268 std::unique_ptr<base::DictionaryValue> | |
269 GetPreferenceValuesWithoutPathExpansion() const; | |
270 | 274 |
271 bool ReadOnly() const; | 275 bool ReadOnly() const; |
272 | 276 |
273 PrefInitializationStatus GetInitializationStatus() const; | 277 PrefInitializationStatus GetInitializationStatus() const; |
274 | 278 |
275 // Tell our PrefValueStore to update itself to |command_line_store|. | 279 // Tell our PrefValueStore to update itself to |command_line_store|. |
276 // Takes ownership of the store. | 280 // Takes ownership of the store. |
277 virtual void UpdateCommandLinePrefStore(PrefStore* command_line_store); | 281 virtual void UpdateCommandLinePrefStore(PrefStore* command_line_store); |
278 | 282 |
279 // We run the callback once, when initialization completes. The bool | 283 // We run the callback once, when initialization completes. The bool |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 385 |
382 // Local cache of registered Preference objects. The pref_registry_ | 386 // Local cache of registered Preference objects. The pref_registry_ |
383 // is authoritative with respect to what the types and default values | 387 // is authoritative with respect to what the types and default values |
384 // of registered preferences are. | 388 // of registered preferences are. |
385 mutable PreferenceMap prefs_map_; | 389 mutable PreferenceMap prefs_map_; |
386 | 390 |
387 DISALLOW_COPY_AND_ASSIGN(PrefService); | 391 DISALLOW_COPY_AND_ASSIGN(PrefService); |
388 }; | 392 }; |
389 | 393 |
390 #endif // COMPONENTS_PREFS_PREF_SERVICE_H_ | 394 #endif // COMPONENTS_PREFS_PREF_SERVICE_H_ |
OLD | NEW |