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

Unified Diff: chrome/browser/prefs/testing_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/browser/prefs/pref_value_store_unittest.cc ('k') | chrome/browser/prefs/testing_pref_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/testing_pref_store.h
diff --git a/chrome/browser/prefs/testing_pref_store.h b/chrome/browser/prefs/testing_pref_store.h
index fe014f45730ccbb33c692ce4dc0ac09eef0dcff9..555ee6907c6dbc11054c6065b6810a9aa8240a7a 100644
--- a/chrome/browser/prefs/testing_pref_store.h
+++ b/chrome/browser/prefs/testing_pref_store.h
@@ -7,46 +7,61 @@
#pragma once
#include "base/basictypes.h"
+#include "base/observer_list.h"
#include "base/scoped_ptr.h"
-#include "chrome/common/pref_store_base.h"
+#include "chrome/browser/prefs/pref_value_map.h"
+#include "chrome/common/persistent_pref_store.h"
class DictionaryValue;
-// |TestingPrefStore| is a stub implementation of the |PrefStore| interface.
-// It allows to get and set the state of the |PrefStore| as well as triggering
-// notifications.
-class TestingPrefStore : public PrefStoreBase {
+// |TestingPrefStore| is a preference store implementation that allows tests to
+// explicitly manipulate the contents of the store, triggering notifications
+// where appropriate.
+class TestingPrefStore : public PersistentPrefStore {
public:
TestingPrefStore();
virtual ~TestingPrefStore() {}
- virtual DictionaryValue* prefs() const { return prefs_.get(); }
-
- virtual PrefStore::PrefReadError ReadPrefs();
+ // Overriden from PrefStore.
+ virtual ReadResult GetValue(const std::string& key, Value** result) const;
+ virtual void AddObserver(PrefStore::Observer* observer);
+ virtual void RemoveObserver(PrefStore::Observer* observer);
+ virtual bool IsInitializationComplete() const { return init_complete_; }
+ // PersistentPrefStore overrides:
+ virtual void SetValue(const std::string& key, Value* value);
+ virtual void SetValueSilently(const std::string& key, Value* value);
+ virtual void RemoveValue(const std::string& key);
virtual bool ReadOnly() const { return read_only_; }
-
+ virtual PersistentPrefStore::PrefReadError ReadPrefs();
virtual bool WritePrefs();
+ virtual void ScheduleWritePrefs() {}
+
+ // Marks the store as having completed initialization.
+ void SetInitializationCompleted();
+
+ // Used for tests to trigger notifications explicitly.
+ void NotifyPrefValueChanged(const std::string& key);
+ void NotifyInitializationCompleted();
+
+ // Some convenience getters/setters.
+ void SetString(const std::string& key, const std::string& value);
+ void SetInteger(const std::string& key, int value);
+ void SetBoolean(const std::string& key, bool value);
+
+ bool GetString(const std::string& key, std::string* value) const;
+ bool GetInteger(const std::string& key, int* value) const;
+ bool GetBoolean(const std::string& key, bool* value) const;
// Getter and Setter methods for setting and getting the state of the
- // |DummyPrefStore|.
+ // |TestingPrefStore|.
virtual void set_read_only(bool read_only) { read_only_ = read_only; }
- virtual void set_prefs(DictionaryValue* prefs) { prefs_.reset(prefs); }
virtual void set_prefs_written(bool status) { prefs_written_ = status; }
virtual bool get_prefs_written() { return prefs_written_; }
- // Publish these functions so testing code can call them.
- virtual void NotifyPrefValueChanged(const std::string& key);
- virtual void NotifyInitializationCompleted();
-
- // Whether the store has completed all asynchronous initialization.
- virtual bool IsInitializationComplete() { return init_complete_; }
-
- // Mark the store as having completed initialization.
- void SetInitializationCompleted();
-
private:
- scoped_ptr<DictionaryValue> prefs_;
+ // Stores the preference values.
+ PrefValueMap prefs_;
// Flag that indicates if the PrefStore is read-only
bool read_only_;
@@ -57,6 +72,8 @@ class TestingPrefStore : public PrefStoreBase {
// Whether initialization has been completed.
bool init_complete_;
+ ObserverList<PrefStore::Observer, true> observers_;
+
DISALLOW_COPY_AND_ASSIGN(TestingPrefStore);
};
« no previous file with comments | « chrome/browser/prefs/pref_value_store_unittest.cc ('k') | chrome/browser/prefs/testing_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698