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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/prefs/pref_value_map.h"
6
7 #include "base/logging.h"
8 #include "base/scoped_ptr.h"
9 #include "base/stl_util-inl.h"
10 #include "base/values.h"
11
12 PrefValueMap::~PrefValueMap() {
13 Clear();
14 }
15
16 bool PrefValueMap::GetValue(const std::string& key, Value** value) const {
17 const Map::const_iterator entry = prefs_.find(key);
18 if (entry != prefs_.end()) {
19 if (value)
20 *value = entry->second;
21 return true;
22 }
23
24 return false;
25 }
26
27 bool PrefValueMap::SetValue(const std::string& key, Value* value) {
28 DCHECK(value);
29 scoped_ptr<Value> value_ptr(value);
30 const Map::iterator entry = prefs_.find(key);
31 if (entry != prefs_.end()) {
32 if (Value::Equals(entry->second, value))
33 return false;
34 delete entry->second;
35 entry->second = value_ptr.release();
36 } else {
37 prefs_[key] = value_ptr.release();
38 }
39
40 return true;
41 }
42
43 bool PrefValueMap::RemoveValue(const std::string& key) {
44 const Map::iterator entry = prefs_.find(key);
45 if (entry != prefs_.end()) {
46 delete entry->second;
47 prefs_.erase(entry);
48 return true;
49 }
50
51 return false;
52 }
53
54 void PrefValueMap::Clear() {
55 STLDeleteValues(&prefs_);
56 prefs_.clear();
57 }
OLDNEW
« 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