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

Unified Diff: chrome/browser/prefs/testing_pref_store.cc

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/testing_pref_store.h ('k') | chrome/browser/prefs/value_map_pref_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/testing_pref_store.cc
diff --git a/chrome/browser/prefs/testing_pref_store.cc b/chrome/browser/prefs/testing_pref_store.cc
index 519473757f0848e3ee794a3b1242c87843b89e3f..39c20f266c50bfab24e8aa51d168406b6fa003c7 100644
--- a/chrome/browser/prefs/testing_pref_store.cc
+++ b/chrome/browser/prefs/testing_pref_store.cc
@@ -7,14 +7,40 @@
#include "base/values.h"
TestingPrefStore::TestingPrefStore()
- : prefs_(new DictionaryValue()),
- read_only_(true),
+ : read_only_(true),
prefs_written_(false),
init_complete_(false) { }
-PrefStore::PrefReadError TestingPrefStore::ReadPrefs() {
- prefs_.reset(new DictionaryValue());
- return PrefStore::PREF_READ_ERROR_NONE;
+PrefStore::ReadResult TestingPrefStore::GetValue(const std::string& key,
+ Value** value) const {
+ return prefs_.GetValue(key, value) ? READ_OK : READ_NO_VALUE;
+}
+
+void TestingPrefStore::AddObserver(PrefStore::Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void TestingPrefStore::RemoveObserver(PrefStore::Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void TestingPrefStore::SetValue(const std::string& key, Value* value) {
+ if (prefs_.SetValue(key, value))
+ NotifyPrefValueChanged(key);
+}
+
+void TestingPrefStore::SetValueSilently(const std::string& key, Value* value) {
+ prefs_.SetValue(key, value);
+}
+
+void TestingPrefStore::RemoveValue(const std::string& key) {
+ if (prefs_.RemoveValue(key))
+ NotifyPrefValueChanged(key);
+}
+
+PersistentPrefStore::PrefReadError TestingPrefStore::ReadPrefs() {
+ prefs_.Clear();
+ return PersistentPrefStore::PREF_READ_ERROR_NONE;
}
bool TestingPrefStore::WritePrefs() {
@@ -22,15 +48,53 @@ bool TestingPrefStore::WritePrefs() {
return prefs_written_;
}
+void TestingPrefStore::SetInitializationCompleted() {
+ init_complete_ = true;
+ NotifyInitializationCompleted();
+}
+
void TestingPrefStore::NotifyPrefValueChanged(const std::string& key) {
- PrefStoreBase::NotifyPrefValueChanged(key);
+ FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
}
void TestingPrefStore::NotifyInitializationCompleted() {
- PrefStoreBase::NotifyInitializationCompleted();
+ FOR_EACH_OBSERVER(Observer, observers_, OnInitializationCompleted());
}
-void TestingPrefStore::SetInitializationCompleted() {
- init_complete_ = true;
- NotifyInitializationCompleted();
+void TestingPrefStore::SetString(const std::string& key,
+ const std::string& value) {
+ SetValue(key, Value::CreateStringValue(value));
+}
+
+void TestingPrefStore::SetInteger(const std::string& key, int value) {
+ SetValue(key, Value::CreateIntegerValue(value));
+}
+
+void TestingPrefStore::SetBoolean(const std::string& key, bool value) {
+ SetValue(key, Value::CreateBooleanValue(value));
+}
+
+bool TestingPrefStore::GetString(const std::string& key,
+ std::string* value) const {
+ Value* stored_value;
+ if (!prefs_.GetValue(key, &stored_value) || !stored_value)
+ return false;
+
+ return stored_value->GetAsString(value);
+}
+
+bool TestingPrefStore::GetInteger(const std::string& key, int* value) const {
+ Value* stored_value;
+ if (!prefs_.GetValue(key, &stored_value) || !stored_value)
+ return false;
+
+ return stored_value->GetAsInteger(value);
+}
+
+bool TestingPrefStore::GetBoolean(const std::string& key, bool* value) const {
+ Value* stored_value;
+ if (!prefs_.GetValue(key, &stored_value) || !stored_value)
+ return false;
+
+ return stored_value->GetAsBoolean(value);
}
« no previous file with comments | « chrome/browser/prefs/testing_pref_store.h ('k') | chrome/browser/prefs/value_map_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698