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

Unified Diff: chrome/common/pref_store.h

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PrefService mock construction in PrefServiceTest to include command line store. Created 10 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/persistent_pref_store.h ('k') | chrome/common/pref_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/pref_store.h
diff --git a/chrome/common/pref_store.h b/chrome/common/pref_store.h
index 808ffbd20d986e369b63148ee03c21bd1f5af304..745eff7157afca49114a3876118dd4205f7ba91c 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);
};
« no previous file with comments | « chrome/common/persistent_pref_store.h ('k') | chrome/common/pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698