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

Unified Diff: chrome/browser/prefs/pref_value_map.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/pref_value_map.h ('k') | chrome/browser/prefs/pref_value_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/pref_value_map.cc
diff --git a/chrome/browser/prefs/pref_value_map.cc b/chrome/browser/prefs/pref_value_map.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8d37f2b9f749da45d9ebb3e4eb995b2c30560066
--- /dev/null
+++ b/chrome/browser/prefs/pref_value_map.cc
@@ -0,0 +1,57 @@
+// 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/browser/prefs/pref_value_map.h"
+
+#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "base/stl_util-inl.h"
+#include "base/values.h"
+
+PrefValueMap::~PrefValueMap() {
+ Clear();
+}
+
+bool PrefValueMap::GetValue(const std::string& key, Value** value) const {
+ const Map::const_iterator entry = prefs_.find(key);
+ if (entry != prefs_.end()) {
+ if (value)
+ *value = entry->second;
+ return true;
+ }
+
+ return false;
+}
+
+bool PrefValueMap::SetValue(const std::string& key, Value* value) {
+ DCHECK(value);
+ scoped_ptr<Value> value_ptr(value);
+ const Map::iterator entry = prefs_.find(key);
+ if (entry != prefs_.end()) {
+ if (Value::Equals(entry->second, value))
+ return false;
+ delete entry->second;
+ entry->second = value_ptr.release();
+ } else {
+ prefs_[key] = value_ptr.release();
+ }
+
+ return true;
+}
+
+bool PrefValueMap::RemoveValue(const std::string& key) {
+ const Map::iterator entry = prefs_.find(key);
+ if (entry != prefs_.end()) {
+ delete entry->second;
+ prefs_.erase(entry);
+ return true;
+ }
+
+ return false;
+}
+
+void PrefValueMap::Clear() {
+ STLDeleteValues(&prefs_);
+ prefs_.clear();
+}
« no previous file with comments | « chrome/browser/prefs/pref_value_map.h ('k') | chrome/browser/prefs/pref_value_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698