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

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: 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 unified diff | Download patch | Annotate | Revision Log
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 {
battre (please use the other) 2010/12/08 12:24:15 DCHECK(value)? or: if value == NULL, don't write b
Mattias Nissler (ping if slow) 2010/12/09 10:20:20 Done.
17 Map::const_iterator entry = prefs_.find(key);
danno 2010/12/08 13:08:45 const
Mattias Nissler (ping if slow) 2010/12/09 10:20:20 Done.
18 if (entry != prefs_.end()) {
19 *value = entry->second;
20 return true;
21 }
22
23 return false;
24 }
25
26 bool PrefValueMap::SetValue(const std::string& key, Value* value) {
27 DCHECK(value);
28 scoped_ptr<Value> value_ptr(value);
29 Map::iterator entry = prefs_.find(key);
danno 2010/12/08 13:08:45 const
Mattias Nissler (ping if slow) 2010/12/09 10:20:20 Done.
30 if (entry != prefs_.end()) {
31 if (Value::Equals(entry->second, value))
32 return false;
33 delete entry->second;
34 entry->second = value_ptr.release();
35 } else {
36 prefs_[key] = value_ptr.release();
37 }
38
39 return true;
40 }
41
42 bool PrefValueMap::RemoveValue(const std::string& key) {
43 Map::iterator entry = prefs_.find(key);
danno 2010/12/08 13:08:45 const
Mattias Nissler (ping if slow) 2010/12/09 10:20:20 Done.
44 if (entry != prefs_.end()) {
45 delete entry->second;
46 prefs_.erase(entry);
47 return true;
48 }
49
50 return false;
51 }
52
53 void PrefValueMap::Clear() {
54 STLDeleteValues(&prefs_);
55 prefs_.clear();
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698