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

Unified Diff: chrome/service/service_prefs.cc

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, fix up unit tests. 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
Index: chrome/service/service_prefs.cc
diff --git a/chrome/service/service_prefs.cc b/chrome/service/service_prefs.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bc6303a0d80ae5f8a888e3e3b3b68cc848caf8ed
--- /dev/null
+++ b/chrome/service/service_prefs.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/service/service_prefs.h"
+
+#include "base/values.h"
+
+ServicePrefs::ServicePrefs(const FilePath& pref_filename,
+ base::MessageLoopProxy* file_message_loop_proxy)
+ : prefs_(pref_filename, file_message_loop_proxy) {
+}
+
+void ServicePrefs::ReadPrefs() {
+ prefs_.ReadPrefs();
+}
+
+void ServicePrefs::WritePrefs() {
+ prefs_.WritePrefs();
+}
+
+void ServicePrefs::GetString(const std::string& key, std::string* result) {
+ Value* value;
+ if (prefs_.GetValue(key, &value) == PersistentPrefStore::READ_OK)
+ value->GetAsString(result);
+}
+
+void ServicePrefs::SetString(const std::string& key, const std::string& value) {
+ prefs_.SetValue(key, Value::CreateStringValue(value));
+}
+
+void ServicePrefs::GetBoolean(const std::string& key, bool* result) {
+ Value* value;
+ if (prefs_.GetValue(key, &value) == PersistentPrefStore::READ_OK)
+ value->GetAsBoolean(result);
gfeher 2010/12/08 12:34:35 How about indicating missing prefs to the consumer
Mattias Nissler (ping if slow) 2010/12/09 10:20:20 If the consumers would need that. But so far they
+}
+
+void ServicePrefs::SetBoolean(const std::string& key, bool value) {
+ prefs_.SetValue(key, Value::CreateBooleanValue(value));
+}
+
+void ServicePrefs::GetDictionary(const std::string& key,
+ DictionaryValue** result) {
+ Value* value;
+ if (prefs_.GetValue(key, &value) != PersistentPrefStore::READ_OK ||
+ !value->IsType(Value::TYPE_DICTIONARY)) {
+ return;
+ }
+
+ *result = static_cast<DictionaryValue*>(value);
+}

Powered by Google App Engine
This is Rietveld 408576698