| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| 8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class PrefValueStore; | 28 class PrefValueStore; |
| 29 class Profile; | 29 class Profile; |
| 30 | 30 |
| 31 namespace subtle { | 31 namespace subtle { |
| 32 class PrefMemberBase; | 32 class PrefMemberBase; |
| 33 class ScopedUserPrefUpdateBase; | 33 class ScopedUserPrefUpdateBase; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 class PrefService; | 36 class PrefService; |
| 37 | 37 |
| 38 class PrefServiceDelegate { | 38 class PrefService : public base::NonThreadSafe { |
| 39 public: | |
| 40 virtual void OnPrefsLoaded(PrefService* prefs, bool success) = 0; | |
| 41 }; | |
| 42 | |
| 43 class PrefService : public base::NonThreadSafe, | |
| 44 public JsonPrefStore::Delegate { | |
| 45 public: | 39 public: |
| 46 // A helper class to store all the information associated with a preference. | 40 // A helper class to store all the information associated with a preference. |
| 47 class Preference { | 41 class Preference { |
| 48 public: | 42 public: |
| 49 | 43 |
| 50 // The type of the preference is determined by the type with which it is | 44 // The type of the preference is determined by the type with which it is |
| 51 // registered. This type needs to be a boolean, integer, double, string, | 45 // registered. This type needs to be a boolean, integer, double, string, |
| 52 // dictionary (a branch), or list. You shouldn't need to construct this on | 46 // dictionary (a branch), or list. You shouldn't need to construct this on |
| 53 // your own; use the PrefService::Register*Pref methods instead. | 47 // your own; use the PrefService::Register*Pref methods instead. |
| 54 Preference(const PrefService* service, | 48 Preference(const PrefService* service, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 std::string name_; | 107 std::string name_; |
| 114 | 108 |
| 115 Value::ValueType type_; | 109 Value::ValueType type_; |
| 116 | 110 |
| 117 // Reference to the PrefService in which this pref was created. | 111 // Reference to the PrefService in which this pref was created. |
| 118 const PrefService* pref_service_; | 112 const PrefService* pref_service_; |
| 119 | 113 |
| 120 DISALLOW_COPY_AND_ASSIGN(Preference); | 114 DISALLOW_COPY_AND_ASSIGN(Preference); |
| 121 }; | 115 }; |
| 122 | 116 |
| 123 // JsonPrefStore::Delegate implementaion. | |
| 124 virtual void OnPrefsRead(PersistentPrefStore::PrefReadError error, | |
| 125 bool no_dir); | |
| 126 | |
| 127 // Factory method that creates a new instance of a PrefService with the | 117 // Factory method that creates a new instance of a PrefService with the |
| 128 // applicable PrefStores. The |pref_filename| points to the user preference | 118 // applicable PrefStores. The |pref_filename| points to the user preference |
| 129 // file. The |profile| is the one to which these preferences apply; it may be | 119 // file. The |profile| is the one to which these preferences apply; it may be |
| 130 // NULL if we're dealing with the local state. This is the usual way to create | 120 // NULL if we're dealing with the local state. This is the usual way to create |
| 131 // a new PrefService. |extension_pref_store| is used as the source for | 121 // a new PrefService. |extension_pref_store| is used as the source for |
| 132 // extension-controlled preferences and may be NULL. The PrefService takes | 122 // extension-controlled preferences and may be NULL. The PrefService takes |
| 133 // ownership of |extension_pref_store|. | 123 // ownership of |extension_pref_store|. If |async| is true, asynchronous |
| 124 // version is used. Notifies using PREF_INITIALIZATION_COMPLETED in the end. |
| 125 // Details is set to the created PrefService or NULL if creation has failed. |
| 126 // Note, it is guaranteed that in asynchronous version initialization happens |
| 127 // after this function returned. |
| 134 static PrefService* CreatePrefService(const FilePath& pref_filename, | 128 static PrefService* CreatePrefService(const FilePath& pref_filename, |
| 135 PrefStore* extension_pref_store, | 129 PrefStore* extension_pref_store, |
| 136 Profile* profile); | 130 Profile* profile, |
| 137 | 131 bool async); |
| 138 // Same as above, but with async initialization. | |
| 139 static PrefService* CreatePrefServiceAsync(const FilePath& pref_filename, | |
| 140 PrefStore* extension_pref_store, | |
| 141 Profile* profile, | |
| 142 PrefServiceDelegate* delegate); | |
| 143 | 132 |
| 144 // Creates an incognito copy of the pref service that shares most pref stores | 133 // Creates an incognito copy of the pref service that shares most pref stores |
| 145 // but uses a fresh non-persistent overlay for the user pref store and an | 134 // but uses a fresh non-persistent overlay for the user pref store and an |
| 146 // individual extension pref store (to cache the effective extension prefs for | 135 // individual extension pref store (to cache the effective extension prefs for |
| 147 // incognito windows). | 136 // incognito windows). |
| 148 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); | 137 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); |
| 149 | 138 |
| 150 virtual ~PrefService(); | 139 virtual ~PrefService(); |
| 151 | 140 |
| 152 // Reloads the data from file. This should only be called when the importer | 141 // Reloads the data from file. This should only be called when the importer |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // PrefStore pointers. This constructor is what CreatePrefService() ends up | 240 // PrefStore pointers. This constructor is what CreatePrefService() ends up |
| 252 // calling. It's also used for unit tests. | 241 // calling. It's also used for unit tests. |
| 253 PrefService(PrefStore* managed_platform_prefs, | 242 PrefService(PrefStore* managed_platform_prefs, |
| 254 PrefStore* managed_cloud_prefs, | 243 PrefStore* managed_cloud_prefs, |
| 255 PrefStore* extension_prefs, | 244 PrefStore* extension_prefs, |
| 256 PrefStore* command_line_prefs, | 245 PrefStore* command_line_prefs, |
| 257 PersistentPrefStore* user_prefs, | 246 PersistentPrefStore* user_prefs, |
| 258 PrefStore* recommended_platform_prefs, | 247 PrefStore* recommended_platform_prefs, |
| 259 PrefStore* recommended_cloud_prefs, | 248 PrefStore* recommended_cloud_prefs, |
| 260 DefaultPrefStore* default_store, | 249 DefaultPrefStore* default_store, |
| 261 PrefServiceDelegate* delegate); | 250 bool async); |
| 262 | 251 |
| 263 // The PrefNotifier handles registering and notifying preference observers. | 252 // The PrefNotifier handles registering and notifying preference observers. |
| 264 // It is created and owned by this PrefService. Subclasses may access it for | 253 // It is created and owned by this PrefService. Subclasses may access it for |
| 265 // unit testing. | 254 // unit testing. |
| 266 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 255 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
| 267 | 256 |
| 268 private: | 257 private: |
| 269 class PreferencePathComparator { | 258 class PreferencePathComparator { |
| 270 public: | 259 public: |
| 271 bool operator() (Preference* lhs, Preference* rhs) const { | 260 bool operator() (Preference* lhs, Preference* rhs) const { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // RegisterPreference must not be called twice for the same path. | 298 // RegisterPreference must not be called twice for the same path. |
| 310 // This method takes ownership of |default_value|. | 299 // This method takes ownership of |default_value|. |
| 311 void RegisterPreference(const char* path, Value* default_value); | 300 void RegisterPreference(const char* path, Value* default_value); |
| 312 | 301 |
| 313 // Sets the value for this pref path in the user pref store and informs the | 302 // Sets the value for this pref path in the user pref store and informs the |
| 314 // PrefNotifier of the change. | 303 // PrefNotifier of the change. |
| 315 void SetUserPrefValue(const char* path, Value* new_value); | 304 void SetUserPrefValue(const char* path, Value* new_value); |
| 316 | 305 |
| 317 // Load preferences from storage, attempting to diagnose and handle errors. | 306 // Load preferences from storage, attempting to diagnose and handle errors. |
| 318 // This should only be called from the constructor. | 307 // This should only be called from the constructor. |
| 319 void InitFromStorage(); | 308 void InitFromStorage(bool async); |
| 320 | 309 |
| 321 // Used to set the value of dictionary or list values in the user pref store. | 310 // Used to set the value of dictionary or list values in the user pref store. |
| 322 // This will create a dictionary or list if one does not exist in the user | 311 // This will create a dictionary or list if one does not exist in the user |
| 323 // pref store. This method returns NULL only if you're requesting an | 312 // pref store. This method returns NULL only if you're requesting an |
| 324 // unregistered pref or a non-dict/non-list pref. | 313 // unregistered pref or a non-dict/non-list pref. |
| 325 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and | 314 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and |
| 326 // |path| must point to a registered preference of type |type|. | 315 // |path| must point to a registered preference of type |type|. |
| 327 // Ownership of the returned value remains at the user pref store. | 316 // Ownership of the returned value remains at the user pref store. |
| 328 Value* GetMutableUserPref(const char* path, Value::ValueType type); | 317 Value* GetMutableUserPref(const char* path, Value::ValueType type); |
| 329 | 318 |
| 330 // The PrefValueStore provides prioritized preference values. It is created | 319 // The PrefValueStore provides prioritized preference values. It is created |
| 331 // and owned by this PrefService. Subclasses may access it for unit testing. | 320 // and owned by this PrefService. Subclasses may access it for unit testing. |
| 332 scoped_ptr<PrefValueStore> pref_value_store_; | 321 scoped_ptr<PrefValueStore> pref_value_store_; |
| 333 | 322 |
| 334 // Pref Stores and profile that we passed to the PrefValueStore. | 323 // Pref Stores and profile that we passed to the PrefValueStore. |
| 335 scoped_refptr<PersistentPrefStore> user_pref_store_; | 324 scoped_refptr<PersistentPrefStore> user_pref_store_; |
| 336 scoped_refptr<DefaultPrefStore> default_store_; | 325 scoped_refptr<DefaultPrefStore> default_store_; |
| 337 | 326 |
| 338 // Local cache of registered Preference objects. The default_store_ | 327 // Local cache of registered Preference objects. The default_store_ |
| 339 // is authoritative with respect to what the types and default values | 328 // is authoritative with respect to what the types and default values |
| 340 // of registered preferences are. | 329 // of registered preferences are. |
| 341 mutable PreferenceSet prefs_; | 330 mutable PreferenceSet prefs_; |
| 342 | 331 |
| 343 // Holds delegator to be called after initialization, if async version | |
| 344 // is used. | |
| 345 PrefServiceDelegate* delegate_; | |
| 346 | |
| 347 DISALLOW_COPY_AND_ASSIGN(PrefService); | 332 DISALLOW_COPY_AND_ASSIGN(PrefService); |
| 348 }; | 333 }; |
| 349 | 334 |
| 350 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 335 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| OLD | NEW |