diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 15:10:17 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 15:10:17 +0000 |
commit | f2d1f61006eac0f8a051fa485b2cffb6b6fa74e0 (patch) | |
tree | f848fcb564eaff40eeebcf7044da9972f798bd2b /chrome/common/pref_store.h | |
parent | ba99ca24c0ba8f0e154dbd74d8a43a55736630e1 (diff) | |
download | chromium_src-f2d1f61006eac0f8a051fa485b2cffb6b6fa74e0.zip chromium_src-f2d1f61006eac0f8a051fa485b2cffb6b6fa74e0.tar.gz chromium_src-f2d1f61006eac0f8a051fa485b2cffb6b6fa74e0.tar.bz2 |
Sanitize PrefStore interface.
This reworks the PrefStore interface, specifically:
- Split up the interface into PrefStore, which only provides reading functionality, and the derived PersistentPrefStore for the actual user pref store
- Remove the hurt-me-plenty prefs() function from PrefStore, instead provide Get/Set/Remove operations
- Remove special handling of default and user pref store from PrefValueStore and put it into PrefService
- Pref change notification handling now almost exclusively handled through PrefValueStore
- Adjust all consumers of these interfaces (but keep ConfigurationPolicyPrefStore untouched, that's up next on the list)
BUG=64232
TEST=existing unit tests
Review URL: http://codereview.chromium.org/5646003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68736 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/pref_store.h')
-rw-r--r-- | chrome/common/pref_store.h | 66 |
1 files changed, 17 insertions, 49 deletions
diff --git a/chrome/common/pref_store.h b/chrome/common/pref_store.h index 808ffbd2..745eff7 100644 --- a/chrome/common/pref_store.h +++ b/chrome/common/pref_store.h @@ -10,7 +10,6 @@ #include "base/basictypes.h" -class DictionaryValue; class Value; // This is an abstract interface for reading and writing from/to a persistent @@ -23,9 +22,9 @@ class Value; class PrefStore { public: // Observer interface for monitoring PrefStore. - class ObserverInterface { + class Observer { public: - virtual ~ObserverInterface() {} + virtual ~Observer() {} // Called when the value for the given |key| in the store changes. virtual void OnPrefValueChanged(const std::string& key) = 0; @@ -33,61 +32,30 @@ class PrefStore { virtual void OnInitializationCompleted() = 0; }; - // Unique integer code for each type of error so we can report them - // distinctly in a histogram. - // NOTE: Don't change the order here as it will change the server's meaning - // of the histogram. - enum PrefReadError { - PREF_READ_ERROR_NONE = 0, - PREF_READ_ERROR_JSON_PARSE, - PREF_READ_ERROR_JSON_TYPE, - PREF_READ_ERROR_ACCESS_DENIED, - PREF_READ_ERROR_FILE_OTHER, - PREF_READ_ERROR_FILE_LOCKED, - PREF_READ_ERROR_NO_FILE, - PREF_READ_ERROR_JSON_REPEAT, - PREF_READ_ERROR_OTHER, - PREF_READ_ERROR_FILE_NOT_SPECIFIED + // Return values for GetValue(). + enum ReadResult { + // Value found and returned. + READ_OK, + // No value present, but skip other pref stores and use default. + READ_USE_DEFAULT, + // No value present. + READ_NO_VALUE, }; - // To require that the default value be used for a preference, a - // PrefStore can set the value in its own prefs dictionary to the - // sentinel Value returned by this function. - // TODO(danno): Instead of having a sentinel value, pref stores - // should return a richer set of information from the property - // accessor methods to indicate that the default should be used. - static Value* CreateUseDefaultSentinelValue(); - - // Returns true if a value is the special sentinel value created by - // CreateUseDefaultSentinelValue. - static bool IsUseDefaultSentinelValue(Value* value); - PrefStore() {} virtual ~PrefStore() {} // Add and remove observers. - virtual void AddObserver(ObserverInterface* observer) {} - virtual void RemoveObserver(ObserverInterface* observer) {} + virtual void AddObserver(Observer* observer) {} + virtual void RemoveObserver(Observer* observer) {} // Whether the store has completed all asynchronous initialization. - virtual bool IsInitializationComplete() { return true; } - - // Whether the store is in a pseudo-read-only mode where changes are not - // actually persisted to disk. This happens in some cases when there are - // read errors during startup. - virtual bool ReadOnly() const { return true; } - - // TODO(danno): PrefValueStore shouldn't allow direct access to the - // DictionaryValue. Instead, it should have getters that return a - // richer set of information for a pref, including if the store - // wants to return the default value for a preference. - virtual DictionaryValue* prefs() const = 0; - - virtual PrefReadError ReadPrefs() = 0; - - virtual bool WritePrefs() { return true; } + virtual bool IsInitializationComplete() const { return true; } - virtual void ScheduleWritePrefs() { } + // Get the value for a given preference |key| and stores it in |result|. + // |result| is only modified if the return value is READ_OK. Ownership of the + // |result| value remains with the PrefStore. + virtual ReadResult GetValue(const std::string& key, Value** result) const = 0; DISALLOW_COPY_AND_ASSIGN(PrefStore); }; |