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

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: 2010->2011 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 18 matching lines...) Expand all
29 class Profile; 29 class Profile;
30 class SyncableService; 30 class SyncableService;
31 31
32 namespace subtle { 32 namespace subtle {
33 class PrefMemberBase; 33 class PrefMemberBase;
34 class ScopedUserPrefUpdateBase; 34 class ScopedUserPrefUpdateBase;
35 }; 35 };
36 36
37 class PrefService; 37 class PrefService;
38 38
39 class PrefServiceDelegate { 39 class PrefService : public base::NonThreadSafe {
40 public:
41 virtual void OnPrefsLoaded(PrefService* prefs, bool success) = 0;
42 };
43
44 class PrefService : public base::NonThreadSafe,
45 public JsonPrefStore::Delegate {
46 public: 40 public:
47 // Enum used when registering preferences to determine if it should be synced 41 // Enum used when registering preferences to determine if it should be synced
48 // or not. This is only used for profile prefs, not local state prefs. 42 // or not. This is only used for profile prefs, not local state prefs.
49 // See the Register*Pref methods for profile prefs below. 43 // See the Register*Pref methods for profile prefs below.
50 enum PrefSyncStatus { 44 enum PrefSyncStatus {
51 UNSYNCABLE_PREF, 45 UNSYNCABLE_PREF,
52 SYNCABLE_PREF 46 SYNCABLE_PREF
53 }; 47 };
54 48
55 // A helper class to store all the information associated with a preference. 49 // A helper class to store all the information associated with a preference.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 std::string name_; 116 std::string name_;
123 117
124 Value::ValueType type_; 118 Value::ValueType type_;
125 119
126 // Reference to the PrefService in which this pref was created. 120 // Reference to the PrefService in which this pref was created.
127 const PrefService* pref_service_; 121 const PrefService* pref_service_;
128 122
129 DISALLOW_COPY_AND_ASSIGN(Preference); 123 DISALLOW_COPY_AND_ASSIGN(Preference);
130 }; 124 };
131 125
132 // JsonPrefStore::Delegate implementaion.
133 virtual void OnPrefsRead(PersistentPrefStore::PrefReadError error,
134 bool no_dir);
135
136 // Factory method that creates a new instance of a PrefService with the 126 // Factory method that creates a new instance of a PrefService with the
137 // applicable PrefStores. The |pref_filename| points to the user preference 127 // applicable PrefStores. The |pref_filename| points to the user preference
138 // file. The |profile| is the one to which these preferences apply; it may be 128 // file. The |profile| is the one to which these preferences apply; it may be
139 // NULL if we're dealing with the local state. This is the usual way to create 129 // NULL if we're dealing with the local state. This is the usual way to create
140 // a new PrefService. |extension_pref_store| is used as the source for 130 // a new PrefService. |extension_pref_store| is used as the source for
141 // extension-controlled preferences and may be NULL. The PrefService takes 131 // extension-controlled preferences and may be NULL. The PrefService takes
142 // ownership of |extension_pref_store|. 132 // ownership of |extension_pref_store|. If |async| is true, asynchronous
133 // version is used. Notifies using PREF_INITIALIZATION_COMPLETED in the end.
134 // Details is set to the created PrefService or NULL if creation has failed.
135 // Note, it is guaranteed that in asynchronous version initialization happens
136 // after this function returned.
143 static PrefService* CreatePrefService(const FilePath& pref_filename, 137 static PrefService* CreatePrefService(const FilePath& pref_filename,
144 PrefStore* extension_pref_store, 138 PrefStore* extension_pref_store,
145 Profile* profile); 139 Profile* profile,
146 140 bool async);
147 // Same as above, but with async initialization.
148 static PrefService* CreatePrefServiceAsync(const FilePath& pref_filename,
149 PrefStore* extension_pref_store,
150 Profile* profile,
151 PrefServiceDelegate* delegate);
152 141
153 // Creates an incognito copy of the pref service that shares most pref stores 142 // Creates an incognito copy of the pref service that shares most pref stores
154 // but uses a fresh non-persistent overlay for the user pref store and an 143 // but uses a fresh non-persistent overlay for the user pref store and an
155 // individual extension pref store (to cache the effective extension prefs for 144 // individual extension pref store (to cache the effective extension prefs for
156 // incognito windows). 145 // incognito windows).
157 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); 146 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs);
158 147
159 virtual ~PrefService(); 148 virtual ~PrefService();
160 149
161 // Reloads the data from file. This should only be called when the importer 150 // Reloads the data from file. This should only be called when the importer
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // PrefStore pointers. This constructor is what CreatePrefService() ends up 298 // PrefStore pointers. This constructor is what CreatePrefService() ends up
310 // calling. It's also used for unit tests. 299 // calling. It's also used for unit tests.
311 PrefService(PrefStore* managed_platform_prefs, 300 PrefService(PrefStore* managed_platform_prefs,
312 PrefStore* managed_cloud_prefs, 301 PrefStore* managed_cloud_prefs,
313 PrefStore* extension_prefs, 302 PrefStore* extension_prefs,
314 PrefStore* command_line_prefs, 303 PrefStore* command_line_prefs,
315 PersistentPrefStore* user_prefs, 304 PersistentPrefStore* user_prefs,
316 PrefStore* recommended_platform_prefs, 305 PrefStore* recommended_platform_prefs,
317 PrefStore* recommended_cloud_prefs, 306 PrefStore* recommended_cloud_prefs,
318 DefaultPrefStore* default_store, 307 DefaultPrefStore* default_store,
319 PrefServiceDelegate* delegate); 308 bool async);
320 309
321 // The PrefNotifier handles registering and notifying preference observers. 310 // The PrefNotifier handles registering and notifying preference observers.
322 // It is created and owned by this PrefService. Subclasses may access it for 311 // It is created and owned by this PrefService. Subclasses may access it for
323 // unit testing. 312 // unit testing.
324 scoped_ptr<PrefNotifierImpl> pref_notifier_; 313 scoped_ptr<PrefNotifierImpl> pref_notifier_;
325 314
326 private: 315 private:
327 class PreferencePathComparator { 316 class PreferencePathComparator {
328 public: 317 public:
329 bool operator() (Preference* lhs, Preference* rhs) const { 318 bool operator() (Preference* lhs, Preference* rhs) const {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 void RegisterPreference(const char* path, 358 void RegisterPreference(const char* path,
370 Value* default_value, 359 Value* default_value,
371 PrefSyncStatus sync_status); 360 PrefSyncStatus sync_status);
372 361
373 // Sets the value for this pref path in the user pref store and informs the 362 // Sets the value for this pref path in the user pref store and informs the
374 // PrefNotifier of the change. 363 // PrefNotifier of the change.
375 void SetUserPrefValue(const char* path, Value* new_value); 364 void SetUserPrefValue(const char* path, Value* new_value);
376 365
377 // Load preferences from storage, attempting to diagnose and handle errors. 366 // Load preferences from storage, attempting to diagnose and handle errors.
378 // This should only be called from the constructor. 367 // This should only be called from the constructor.
379 void InitFromStorage(); 368 void InitFromStorage(bool async);
380 369
381 // Used to set the value of dictionary or list values in the user pref store. 370 // Used to set the value of dictionary or list values in the user pref store.
382 // This will create a dictionary or list if one does not exist in the user 371 // This will create a dictionary or list if one does not exist in the user
383 // pref store. This method returns NULL only if you're requesting an 372 // pref store. This method returns NULL only if you're requesting an
384 // unregistered pref or a non-dict/non-list pref. 373 // unregistered pref or a non-dict/non-list pref.
385 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and 374 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and
386 // |path| must point to a registered preference of type |type|. 375 // |path| must point to a registered preference of type |type|.
387 // Ownership of the returned value remains at the user pref store. 376 // Ownership of the returned value remains at the user pref store.
388 Value* GetMutableUserPref(const char* path, Value::ValueType type); 377 Value* GetMutableUserPref(const char* path, Value::ValueType type);
389 378
390 // The PrefValueStore provides prioritized preference values. It is created 379 // The PrefValueStore provides prioritized preference values. It is created
391 // and owned by this PrefService. Subclasses may access it for unit testing. 380 // and owned by this PrefService. Subclasses may access it for unit testing.
392 scoped_ptr<PrefValueStore> pref_value_store_; 381 scoped_ptr<PrefValueStore> pref_value_store_;
393 382
394 // Pref Stores and profile that we passed to the PrefValueStore. 383 // Pref Stores and profile that we passed to the PrefValueStore.
395 scoped_refptr<PersistentPrefStore> user_pref_store_; 384 scoped_refptr<PersistentPrefStore> user_pref_store_;
396 scoped_refptr<DefaultPrefStore> default_store_; 385 scoped_refptr<DefaultPrefStore> default_store_;
397 386
398 // Local cache of registered Preference objects. The default_store_ 387 // Local cache of registered Preference objects. The default_store_
399 // is authoritative with respect to what the types and default values 388 // is authoritative with respect to what the types and default values
400 // of registered preferences are. 389 // of registered preferences are.
401 mutable PreferenceSet prefs_; 390 mutable PreferenceSet prefs_;
402 391
403 // Holds delegator to be called after initialization, if async version
404 // is used.
405 PrefServiceDelegate* delegate_;
406
407 // The model associator that maintains the links with the sync db. 392 // The model associator that maintains the links with the sync db.
408 scoped_ptr<PrefModelAssociator> pref_sync_associator_; 393 scoped_ptr<PrefModelAssociator> pref_sync_associator_;
409 394
410 DISALLOW_COPY_AND_ASSIGN(PrefService); 395 DISALLOW_COPY_AND_ASSIGN(PrefService);
411 }; 396 };
412 397
413 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 398 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_notifier_impl_unittest.cc ('k') | chrome/browser/prefs/pref_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698