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

Unified Diff: chrome/common/json_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/common/json_pref_store.h ('k') | chrome/common/json_pref_store_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/json_pref_store.cc
diff --git a/chrome/common/json_pref_store.cc b/chrome/common/json_pref_store.cc
index d68307f622261b919ffdd4e907c2e231955d79ac..bbf33d738afbe771cf3e02ca8653f35066010347 100644
--- a/chrome/common/json_pref_store.cc
+++ b/chrome/common/json_pref_store.cc
@@ -30,7 +30,46 @@ JsonPrefStore::~JsonPrefStore() {
writer_.DoScheduledWrite();
}
-PrefStore::PrefReadError JsonPrefStore::ReadPrefs() {
+PrefStore::ReadResult JsonPrefStore::GetValue(const std::string& key,
+ Value** result) const {
+ return prefs_->Get(key, result) ? READ_OK : READ_NO_VALUE;
+}
+
+void JsonPrefStore::AddObserver(PrefStore::Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void JsonPrefStore::RemoveObserver(PrefStore::Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void JsonPrefStore::SetValue(const std::string& key, Value* value) {
+ DCHECK(value);
+ scoped_ptr<Value> new_value(value);
+ Value* old_value = NULL;
+ prefs_->Get(key, &old_value);
+ if (!old_value || !value->Equals(old_value)) {
+ prefs_->Set(key, new_value.release());
+ FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+ }
+}
+
+void JsonPrefStore::SetValueSilently(const std::string& key, Value* value) {
+ DCHECK(value);
+ scoped_ptr<Value> new_value(value);
+ Value* old_value = NULL;
+ prefs_->Get(key, &old_value);
+ if (!old_value || !value->Equals(old_value))
+ prefs_->Set(key, new_value.release());
+}
+
+void JsonPrefStore::RemoveValue(const std::string& key) {
+ if (prefs_->Remove(key, NULL)) {
+ FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+ }
+}
+
+PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() {
if (path_.empty()) {
read_only_ = true;
return PREF_READ_ERROR_FILE_NOT_SPECIFIED;
« no previous file with comments | « chrome/common/json_pref_store.h ('k') | chrome/common/json_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698