Index: chrome/browser/prefs/pref_service.h |
diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h |
index 2bcbdf095904ccd8b2329287a7c12941352f8413..f723b6799bf2ea8b41a0f4874318e7b3e4c726f8 100644 |
--- a/chrome/browser/prefs/pref_service.h |
+++ b/chrome/browser/prefs/pref_service.h |
@@ -25,22 +25,19 @@ |
class CommandLine; |
class DefaultPrefStore; |
-class PrefModelAssociator; |
class PrefNotifier; |
class PrefNotifierImpl; |
class PrefObserver; |
-class PrefServiceObserver; |
class PrefStore; |
class PrefValueStore; |
-namespace syncer { |
-class SyncableService; |
-} |
- |
namespace subtle { |
class ScopedUserPrefUpdateBase; |
}; |
+// Base class for PrefServices. You can use the base class to read and |
+// interact with preferences, but not to register new preferences; for |
+// that see subclasses like PrefServiceSimple. |
class PrefService : public PrefServiceBase, public base::NonThreadSafe { |
public: |
enum PrefInitializationStatus { |
@@ -90,15 +87,11 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { |
// Reference to the PrefService in which this pref was created. |
const PrefService* pref_service_; |
- |
}; |
- // Creates an incognito copy of the pref service that shares most pref stores |
- // but uses a fresh non-persistent overlay for the user pref store and an |
- // individual extension pref store (to cache the effective extension prefs for |
- // incognito windows). |
- PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); |
- |
+ // Constructs a PrefService that is uninitialized and unusable. You |
+ // must pass it to PrefServiceBuilder::Create for initialization. |
+ PrefService(); |
Mattias Nissler (ping if slow)
2012/12/14 13:50:06
Please not. Let's pass all dependencies through th
|
virtual ~PrefService(); |
// Reloads the data from file. This should only be called when the importer |
@@ -110,94 +103,9 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { |
// immediately (basically, during shutdown). |
void CommitPendingWrite(); |
- void AddObserver(PrefServiceObserver* observer); |
- void RemoveObserver(PrefServiceObserver* observer); |
- |
- // Returns true if preferences state has synchronized with the remote |
- // preferences. If true is returned it can be assumed the local preferences |
- // has applied changes from the remote preferences. The two may not be |
- // identical if a change is in flight (from either side). |
- bool IsSyncing(); |
- |
- // Invoked internally when the IsSyncing() state changes. |
- void OnIsSyncingChanged(); |
- |
// PrefServiceBase implementation. |
virtual bool IsManagedPreference(const char* pref_name) const OVERRIDE; |
virtual bool IsUserModifiablePreference(const char* pref_name) const OVERRIDE; |
- virtual void RegisterBooleanPref(const char* path, |
- bool default_value) OVERRIDE; |
- virtual void RegisterIntegerPref(const char* path, |
- int default_value) OVERRIDE; |
- virtual void RegisterDoublePref(const char* path, |
- double default_value) OVERRIDE; |
- virtual void RegisterStringPref(const char* path, |
- const std::string& default_value) OVERRIDE; |
- virtual void RegisterFilePathPref(const char* path, |
- const FilePath& default_value) OVERRIDE; |
- virtual void RegisterListPref(const char* path) OVERRIDE; |
- virtual void RegisterDictionaryPref(const char* path) OVERRIDE; |
- virtual void RegisterListPref(const char* path, |
- base::ListValue* default_value) OVERRIDE; |
- virtual void RegisterDictionaryPref( |
- const char* path, base::DictionaryValue* default_value) OVERRIDE; |
- virtual void RegisterLocalizedBooleanPref( |
- const char* path, int locale_default_message_id) OVERRIDE; |
- virtual void RegisterLocalizedIntegerPref( |
- const char* path, int locale_default_message_id) OVERRIDE; |
- virtual void RegisterLocalizedDoublePref( |
- const char* path, int locale_default_message_id) OVERRIDE; |
- virtual void RegisterLocalizedStringPref( |
- const char* path, int locale_default_message_id) OVERRIDE; |
- virtual void RegisterInt64Pref(const char* path, |
- int64 default_value) OVERRIDE; |
- virtual void RegisterBooleanPref(const char* path, |
- bool default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterIntegerPref(const char* path, |
- int default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterDoublePref(const char* path, |
- double default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterStringPref(const char* path, |
- const std::string& default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterFilePathPref(const char* path, |
- const FilePath& default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterListPref(const char* path, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterDictionaryPref(const char* path, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterListPref(const char* path, |
- base::ListValue* default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterDictionaryPref(const char* path, |
- base::DictionaryValue* default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterLocalizedBooleanPref( |
- const char* path, |
- int locale_default_message_id, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterLocalizedIntegerPref( |
- const char* path, |
- int locale_default_message_id, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterLocalizedDoublePref( |
- const char* path, |
- int locale_default_message_id, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterLocalizedStringPref( |
- const char* path, |
- int locale_default_message_id, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterInt64Pref(const char* path, |
- int64 default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
- virtual void RegisterUint64Pref(const char* path, |
- uint64 default_value, |
- PrefSyncStatus sync_status) OVERRIDE; |
virtual void UnregisterPreference(const char* path) OVERRIDE; |
virtual const PrefService::Preference* FindPreference( |
const char* path) const OVERRIDE; |
@@ -243,13 +151,8 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { |
PrefInitializationStatus GetInitializationStatus() const; |
- // syncer::SyncableService getter. |
- // TODO(zea): Have PrefService implement syncer::SyncableService directly. |
- syncer::SyncableService* GetSyncableService(); |
- |
// Tell our PrefValueStore to update itself using |command_line|. |
- // Do not call this after having derived an incognito or per tab pref service. |
- void UpdateCommandLinePrefStore(CommandLine* command_line); |
+ virtual void UpdateCommandLinePrefStore(CommandLine* command_line); |
// We run the callback once, when initialization completes. The bool |
// parameter will be set to true for successful initialization, |
@@ -257,23 +160,43 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { |
void AddPrefInitObserver(base::Callback<void(bool)> callback); |
protected: |
- // Construct a new pref service. This constructor is what |
- // factory methods end up calling and what is used for unit tests. |
- PrefService(PrefNotifierImpl* pref_notifier, |
- PrefValueStore* pref_value_store, |
- PersistentPrefStore* user_prefs, |
- DefaultPrefStore* default_store, |
- PrefModelAssociator* pref_sync_associator, |
- base::Callback<std::string(int)> get_localized_string_method, |
- base::Callback<void(PersistentPrefStore::PrefReadError)> |
- read_error_callback, |
- bool async); |
+ // Initialize a PrefService instance. This is what |
+ // PrefServiceBuilder::Create ends up calling. |
+ virtual void Initialize( |
+ PrefNotifierImpl* pref_notifier, |
+ PrefValueStore* pref_value_store, |
+ PersistentPrefStore* user_prefs, |
+ DefaultPrefStore* default_store, |
+ base::Callback<std::string(int)> get_localized_string_method, |
+ base::Callback<void(PersistentPrefStore::PrefReadError)> |
+ read_error_callback, |
+ bool async); |
+ |
+ // Registers a new preference at |path|. The |default_value| must not be |
+ // NULL as it determines the preference value's type. |
+ // RegisterPreference must not be called twice for the same path. |
+ // This method takes ownership of |default_value|. |
+ void RegisterPreference(const char* path, base::Value* default_value); |
// The PrefNotifier handles registering and notifying preference observers. |
// It is created and owned by this PrefService. Subclasses may access it for |
// unit testing. |
scoped_ptr<PrefNotifierImpl> pref_notifier_; |
+ // The PrefValueStore provides prioritized preference values. It is owned by |
+ // this PrefService. Subclasses may access it for unit testing. |
+ scoped_ptr<PrefValueStore> pref_value_store_; |
+ |
+ // Pref Stores and profile that we passed to the PrefValueStore. |
+ scoped_refptr<PersistentPrefStore> user_pref_store_; |
+ scoped_refptr<DefaultPrefStore> default_store_; |
+ |
+ // Function with which to retrieve localized UTF8 resources. |
+ base::Callback<std::string(int)> get_localized_string_method_; |
+ |
+ // Callback to call when a read error occurs. |
+ base::Callback<void(PersistentPrefStore::PrefReadError)> read_error_callback_; |
+ |
private: |
// Hash map expected to be fastest here since it minimises expensive |
// string comparisons. Order is unimportant, and deletions are rare. |
@@ -296,14 +219,6 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { |
// a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. |
void ReportUserPrefChanged(const std::string& key); |
- // Registers a new preference at |path|. The |default_value| must not be |
- // NULL as it determines the preference value's type. |
- // RegisterPreference must not be called twice for the same path. |
- // This method takes ownership of |default_value|. |
- void RegisterPreference(const char* path, |
- base::Value* default_value, |
- PrefSyncStatus sync_status); |
- |
// Sets the value for this pref path in the user pref store and informs the |
// PrefNotifier of the change. |
void SetUserPrefValue(const char* path, base::Value* new_value); |
@@ -329,35 +244,177 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { |
// actually get the value.). |
const base::Value* GetPreferenceValue(const std::string& path) const; |
- // The PrefValueStore provides prioritized preference values. It is owned by |
- // this PrefService. Subclasses may access it for unit testing. |
- scoped_ptr<PrefValueStore> pref_value_store_; |
- |
- // Pref Stores and profile that we passed to the PrefValueStore. |
- scoped_refptr<PersistentPrefStore> user_pref_store_; |
- scoped_refptr<DefaultPrefStore> default_store_; |
- |
// Local cache of registered Preference objects. The default_store_ |
// is authoritative with respect to what the types and default values |
// of registered preferences are. |
mutable PreferenceMap prefs_map_; |
- // The model associator that maintains the links with the sync db. |
- scoped_ptr<PrefModelAssociator> pref_sync_associator_; |
+ DISALLOW_COPY_AND_ASSIGN(PrefService); |
+}; |
- // Function with which to retrieve localized UTF8 resources. |
- base::Callback<std::string(int)> get_localized_string_method_; |
- // Callback to call when a read error occurs. |
- base::Callback<void(PersistentPrefStore::PrefReadError)> read_error_callback_; |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+// A simple PrefService implementation. |
+class PrefServiceSimple : public PrefService { |
+ public: |
+ void RegisterBooleanPref(const char* path, bool default_value); |
+ void RegisterIntegerPref(const char* path, int default_value); |
+ void RegisterDoublePref(const char* path, double default_value); |
+ void RegisterStringPref(const char* path, const std::string& default_value); |
+ void RegisterFilePathPref(const char* path, const FilePath& default_value); |
+ void RegisterListPref(const char* path); |
+ void RegisterDictionaryPref(const char* path); |
+ void RegisterListPref(const char* path, base::ListValue* default_value); |
+ void RegisterDictionaryPref( |
+ const char* path, base::DictionaryValue* default_value); |
+ void RegisterLocalizedBooleanPref( |
+ const char* path, int locale_default_message_id); |
+ void RegisterLocalizedIntegerPref( |
+ const char* path, int locale_default_message_id); |
+ void RegisterLocalizedDoublePref( |
+ const char* path, int locale_default_message_id); |
+ void RegisterLocalizedStringPref( |
+ const char* path, int locale_default_message_id); |
+ void RegisterInt64Pref(const char* path, |
+ int64 default_value); |
+}; |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+#include "chrome/browser/prefs/pref_model_associator.h" |
+ |
+// TODO(joi) Move to c/b/prefs and rename PrefServiceSyncableObserver. |
+class PrefServiceObserver; |
+ |
+namespace syncer { |
+class SyncableService; |
+} |
+ |
+// A PrefService that can be synced. Users are forced to declare |
+// whether preferences are syncable or not when registering them to |
+// this PrefService. |
+class PrefServiceSyncable : public PrefService { |
+ public: |
+ // Enum used when registering preferences to determine if it should be synced |
+ // or not. This is only used for profile prefs, not local state prefs. |
+ // See the Register*Pref methods for profile prefs below. |
+ enum PrefSyncStatus { |
+ UNSYNCABLE_PREF, |
+ SYNCABLE_PREF |
+ }; |
+ |
+ PrefServiceSyncable(); |
+ virtual ~PrefServiceSyncable(); |
+ |
+ // Creates an incognito copy of the pref service that shares most pref stores |
+ // but uses a fresh non-persistent overlay for the user pref store and an |
+ // individual extension pref store (to cache the effective extension prefs for |
+ // incognito windows). |
+ PrefServiceSyncable* CreateIncognitoPrefService( |
+ PrefStore* incognito_extension_prefs); |
+ |
+ // Returns true if preferences state has synchronized with the remote |
+ // preferences. If true is returned it can be assumed the local preferences |
+ // has applied changes from the remote preferences. The two may not be |
+ // identical if a change is in flight (from either side). |
+ bool IsSyncing(); |
+ |
+ void AddObserver(PrefServiceObserver* observer); |
+ void RemoveObserver(PrefServiceObserver* observer); |
+ |
+ virtual void UnregisterPreference(const char* path) OVERRIDE; |
+ |
+ void RegisterBooleanPref(const char* path, |
+ bool default_value, |
+ PrefSyncStatus sync_status); |
+ void RegisterIntegerPref(const char* path, |
+ int default_value, |
+ PrefSyncStatus sync_status); |
+ void RegisterDoublePref(const char* path, |
+ double default_value, |
+ PrefSyncStatus sync_status); |
+ void RegisterStringPref(const char* path, |
+ const std::string& default_value, |
+ PrefSyncStatus sync_status); |
+ void RegisterFilePathPref(const char* path, |
+ const FilePath& default_value, |
+ PrefSyncStatus sync_status); |
+ void RegisterListPref(const char* path, |
+ PrefSyncStatus sync_status); |
+ void RegisterDictionaryPref(const char* path, |
+ PrefSyncStatus sync_status); |
+ void RegisterListPref(const char* path, |
+ base::ListValue* default_value, |
+ PrefSyncStatus sync_status); |
+ void RegisterDictionaryPref(const char* path, |
+ base::DictionaryValue* default_value, |
+ PrefSyncStatus sync_status); |
+ void RegisterLocalizedBooleanPref(const char* path, |
+ int locale_default_message_id, |
+ PrefSyncStatus sync_status); |
+ void RegisterLocalizedIntegerPref(const char* path, |
+ int locale_default_message_id, |
+ PrefSyncStatus sync_status); |
+ void RegisterLocalizedDoublePref(const char* path, |
+ int locale_default_message_id, |
+ PrefSyncStatus sync_status); |
+ void RegisterLocalizedStringPref(const char* path, |
+ int locale_default_message_id, |
+ PrefSyncStatus sync_status); |
+ void RegisterInt64Pref(const char* path, |
+ int64 default_value, |
+ PrefSyncStatus sync_status); |
+ void RegisterUint64Pref(const char* path, |
+ uint64 default_value, |
+ PrefSyncStatus sync_status); |
+ |
+ // syncer::SyncableService getter. |
+ // TODO(zea): Have PrefService implement syncer::SyncableService directly. |
+ syncer::SyncableService* GetSyncableService(); |
+ |
+ // Do not call this after having derived an incognito or per tab pref service. |
+ virtual void UpdateCommandLinePrefStore(CommandLine* command_line) OVERRIDE; |
+ |
+ protected: |
+ virtual void Initialize( |
+ PrefNotifierImpl* pref_notifier, |
+ PrefValueStore* pref_value_store, |
+ PersistentPrefStore* user_prefs, |
+ DefaultPrefStore* default_store, |
+ base::Callback<std::string(int)> get_localized_string_method, |
+ base::Callback<void(PersistentPrefStore::PrefReadError)> |
+ read_error_callback, |
+ bool async) OVERRIDE; |
+ |
+ private: |
+ // Invoked internally when the IsSyncing() state changes. |
+ void OnIsSyncingChanged(); |
+ |
+ void RegisterSyncablePreference( |
+ const char* path, Value* default_value, PrefSyncStatus sync_status); |
// Whether CreateIncognitoPrefService() has been called to create a |
// "forked" PrefService. |
bool pref_service_forked_; |
- ObserverList<PrefServiceObserver> observer_list_; |
+ PrefModelAssociator pref_sync_associator_; |
- DISALLOW_COPY_AND_ASSIGN(PrefService); |
+ ObserverList<PrefServiceObserver> observer_list_; |
}; |
#endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |