diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-08 09:49:11 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-08 09:49:11 +0000 |
commit | acd78969cf6569dcbf409dceb0b6511751afd026 (patch) | |
tree | ed2168c663ae3e8a15d857838b78ed2386da3281 /chrome/common/pref_store.h | |
parent | 5138bbffd1b2d5151ad74b4e7ae8091fc7d44114 (diff) | |
download | chromium_src-acd78969cf6569dcbf409dceb0b6511751afd026.zip chromium_src-acd78969cf6569dcbf409dceb0b6511751afd026.tar.gz chromium_src-acd78969cf6569dcbf409dceb0b6511751afd026.tar.bz2 |
Clean up pref change notification handling.
This is a complete overhaul of PrefValueStore, PrefStore, PrefNotifier, and PrefService. Specifically:
- Add an observer interface to PrefStore that can be used to notify the upper layers of the pref system about value changes. Currently, it's unused mostly, but that'll change when we refactor ExtensionPrefStore and ConfigurationPolicyPrefStore.
- Make PrefNotifier be a dependency of PrefValueStore. That helps in keeping the pref change detection handling local to PrefValueStore.
- Clean up related unit tests, removing redundant mocks and gmockify others.
BUG=64893
TEST=Compiles and passes tests
Review URL: http://codereview.chromium.org/5441002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68574 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/pref_store.h')
-rw-r--r-- | chrome/common/pref_store.h | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/chrome/common/pref_store.h b/chrome/common/pref_store.h index 7011eba..808ffbd2 100644 --- a/chrome/common/pref_store.h +++ b/chrome/common/pref_store.h @@ -6,15 +6,33 @@ #define CHROME_COMMON_PREF_STORE_H_ #pragma once +#include <string> + +#include "base/basictypes.h" + class DictionaryValue; class Value; // This is an abstract interface for reading and writing from/to a persistent -// preference store, used by |PrefService|. An implementation using a JSON file -// can be found in |JsonPrefStore|, while an implementation without any backing -// store (currently used for testing) can be found in |DummyPrefStore|. +// preference store, used by PrefService. An implementation using a JSON file +// can be found in JsonPrefStore, while an implementation without any backing +// store for testing can be found in TestingPrefStore. Furthermore, there is +// CommandLinePrefStore, which bridges command line options to preferences and +// ConfigurationPolicyPrefStore, which is used for hooking up configuration +// policy with the preference subsystem. class PrefStore { public: + // Observer interface for monitoring PrefStore. + class ObserverInterface { + public: + virtual ~ObserverInterface() {} + + // Called when the value for the given |key| in the store changes. + virtual void OnPrefValueChanged(const std::string& key) = 0; + // Notification about the PrefStore being fully initialized. + 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 @@ -44,12 +62,20 @@ class PrefStore { // CreateUseDefaultSentinelValue. static bool IsUseDefaultSentinelValue(Value* value); - virtual ~PrefStore() { } + PrefStore() {} + virtual ~PrefStore() {} + + // Add and remove observers. + virtual void AddObserver(ObserverInterface* observer) {} + virtual void RemoveObserver(ObserverInterface* 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() { return true; } + 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 @@ -62,6 +88,8 @@ class PrefStore { virtual bool WritePrefs() { return true; } virtual void ScheduleWritePrefs() { } + + DISALLOW_COPY_AND_ASSIGN(PrefStore); }; #endif // CHROME_COMMON_PREF_STORE_H_ |