Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: chrome/browser/prefs/pref_service.h

Issue 6894020: Adds async interface method to PersistentPrefStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use Notifications. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 {
39 public:
40 virtual void OnPrefsLoaded(PrefService* prefs, bool success) = 0;
41 };
42
43 class PrefService : public base::NonThreadSafe, 38 class PrefService : public base::NonThreadSafe,
44 public JsonPrefStore::Delegate { 39 public PrefStore::Observer {
45 public: 40 public:
46 // A helper class to store all the information associated with a preference. 41 // A helper class to store all the information associated with a preference.
47 class Preference { 42 class Preference {
48 public: 43 public:
49 44
50 // The type of the preference is determined by the type with which it is 45 // 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, 46 // 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 47 // dictionary (a branch), or list. You shouldn't need to construct this on
53 // your own; use the PrefService::Register*Pref methods instead. 48 // your own; use the PrefService::Register*Pref methods instead.
54 Preference(const PrefService* service, 49 Preference(const PrefService* service,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 std::string name_; 108 std::string name_;
114 109
115 Value::ValueType type_; 110 Value::ValueType type_;
116 111
117 // Reference to the PrefService in which this pref was created. 112 // Reference to the PrefService in which this pref was created.
118 const PrefService* pref_service_; 113 const PrefService* pref_service_;
119 114
120 DISALLOW_COPY_AND_ASSIGN(Preference); 115 DISALLOW_COPY_AND_ASSIGN(Preference);
121 }; 116 };
122 117
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 118 // Factory method that creates a new instance of a PrefService with the
128 // applicable PrefStores. The |pref_filename| points to the user preference 119 // 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 120 // 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 121 // 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 122 // a new PrefService. |extension_pref_store| is used as the source for
132 // extension-controlled preferences and may be NULL. The PrefService takes 123 // extension-controlled preferences and may be NULL. The PrefService takes
133 // ownership of |extension_pref_store|. 124 // ownership of |extension_pref_store|. If |async| is true, asynchronous
125 // version is used. Notifies using PREF_INITIALIZATION_COMPLETED or
126 // PREF_INITIALIZATION_FAILED in the end.
134 static PrefService* CreatePrefService(const FilePath& pref_filename, 127 static PrefService* CreatePrefService(const FilePath& pref_filename,
135 PrefStore* extension_pref_store, 128 PrefStore* extension_pref_store,
136 Profile* profile); 129 Profile* profile,
137 130 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 131
144 // Creates an incognito copy of the pref service that shares most pref stores 132 // 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 133 // 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 134 // individual extension pref store (to cache the effective extension prefs for
147 // incognito windows). 135 // incognito windows).
148 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); 136 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs);
149 137
150 virtual ~PrefService(); 138 virtual ~PrefService();
151 139
152 // Reloads the data from file. This should only be called when the importer 140 // Reloads the data from file. This should only be called when the importer
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // Construct a new pref service, specifying the pref sources as explicit 241 // Construct a new pref service, specifying the pref sources as explicit
254 // PrefStore pointers. This constructor is what CreatePrefService() ends up 242 // PrefStore pointers. This constructor is what CreatePrefService() ends up
255 // calling. It's also used for unit tests. 243 // calling. It's also used for unit tests.
256 PrefService(PrefStore* managed_platform_prefs, 244 PrefService(PrefStore* managed_platform_prefs,
257 PrefStore* managed_cloud_prefs, 245 PrefStore* managed_cloud_prefs,
258 PrefStore* extension_prefs, 246 PrefStore* extension_prefs,
259 PrefStore* command_line_prefs, 247 PrefStore* command_line_prefs,
260 PersistentPrefStore* user_prefs, 248 PersistentPrefStore* user_prefs,
261 PrefStore* recommended_platform_prefs, 249 PrefStore* recommended_platform_prefs,
262 PrefStore* recommended_cloud_prefs, 250 PrefStore* recommended_cloud_prefs,
263 DefaultPrefStore* default_store, 251 DefaultPrefStore* default_store);
264 PrefServiceDelegate* delegate); 252
253 // PrefStore::Observer implementation:
254 virtual void OnPrefValueChanged(const std::string&) {}
255 virtual void OnInitializationCompleted();
265 256
266 // The PrefNotifier handles registering and notifying preference observers. 257 // The PrefNotifier handles registering and notifying preference observers.
267 // It is created and owned by this PrefService. Subclasses may access it for 258 // It is created and owned by this PrefService. Subclasses may access it for
268 // unit testing. 259 // unit testing.
269 scoped_ptr<PrefNotifierImpl> pref_notifier_; 260 scoped_ptr<PrefNotifierImpl> pref_notifier_;
270 261
271 private: 262 private:
272 class PreferencePathComparator { 263 class PreferencePathComparator {
273 public: 264 public:
274 bool operator() (Preference* lhs, Preference* rhs) const { 265 bool operator() (Preference* lhs, Preference* rhs) const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // NULL as it determines the preference value's type. 302 // NULL as it determines the preference value's type.
312 // RegisterPreference must not be called twice for the same path. 303 // RegisterPreference must not be called twice for the same path.
313 // This method takes ownership of |default_value|. 304 // This method takes ownership of |default_value|.
314 void RegisterPreference(const char* path, Value* default_value); 305 void RegisterPreference(const char* path, Value* default_value);
315 306
316 // Sets the value for this pref path in the user pref store and informs the 307 // Sets the value for this pref path in the user pref store and informs the
317 // PrefNotifier of the change. 308 // PrefNotifier of the change.
318 void SetUserPrefValue(const char* path, Value* new_value); 309 void SetUserPrefValue(const char* path, Value* new_value);
319 310
320 // Load preferences from storage, attempting to diagnose and handle errors. 311 // Load preferences from storage, attempting to diagnose and handle errors.
321 // This should only be called from the constructor. 312 // This should only be called right after construction.
322 void InitFromStorage(); 313 void InitFromStorage(bool async);
323 314
324 // Used to set the value of dictionary or list values in the user pref store. 315 // Used to set the value of dictionary or list values in the user pref store.
325 // This will create a dictionary or list if one does not exist in the user 316 // This will create a dictionary or list if one does not exist in the user
326 // pref store. This method returns NULL only if you're requesting an 317 // pref store. This method returns NULL only if you're requesting an
327 // unregistered pref or a non-dict/non-list pref. 318 // unregistered pref or a non-dict/non-list pref.
328 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and 319 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and
329 // |path| must point to a registered preference of type |type|. 320 // |path| must point to a registered preference of type |type|.
330 // Ownership of the returned value remains at the user pref store. 321 // Ownership of the returned value remains at the user pref store.
331 Value* GetMutableUserPref(const char* path, Value::ValueType type); 322 Value* GetMutableUserPref(const char* path, Value::ValueType type);
332 323
333 // The PrefValueStore provides prioritized preference values. It is created 324 // The PrefValueStore provides prioritized preference values. It is created
334 // and owned by this PrefService. Subclasses may access it for unit testing. 325 // and owned by this PrefService. Subclasses may access it for unit testing.
335 scoped_ptr<PrefValueStore> pref_value_store_; 326 scoped_ptr<PrefValueStore> pref_value_store_;
336 327
337 // Pref Stores and profile that we passed to the PrefValueStore. 328 // Pref Stores and profile that we passed to the PrefValueStore.
338 scoped_refptr<PersistentPrefStore> user_pref_store_; 329 scoped_refptr<PersistentPrefStore> user_pref_store_;
339 scoped_refptr<DefaultPrefStore> default_store_; 330 scoped_refptr<DefaultPrefStore> default_store_;
340 331
341 // Local cache of registered Preference objects. The default_store_ 332 // Local cache of registered Preference objects. The default_store_
342 // is authoritative with respect to what the types and default values 333 // is authoritative with respect to what the types and default values
343 // of registered preferences are. 334 // of registered preferences are.
344 mutable PreferenceSet prefs_; 335 mutable PreferenceSet prefs_;
345 336
346 // Holds delegator to be called after initialization, if async version
347 // is used.
348 PrefServiceDelegate* delegate_;
349
350 DISALLOW_COPY_AND_ASSIGN(PrefService); 337 DISALLOW_COPY_AND_ASSIGN(PrefService);
351 }; 338 };
352 339
353 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 340 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698