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

Side by Side Diff: base/prefs/pref_value_map.cc

Issue 16797003: Make base use the proper Value namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: iwarnings fixed Created 7 years, 6 months 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/prefs/pref_value_map.h" 5 #include "base/prefs/pref_value_map.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 11
12 PrefValueMap::PrefValueMap() {} 12 PrefValueMap::PrefValueMap() {}
13 13
14 PrefValueMap::~PrefValueMap() { 14 PrefValueMap::~PrefValueMap() {
15 Clear(); 15 Clear();
16 } 16 }
17 17
18 bool PrefValueMap::GetValue(const std::string& key, const Value** value) const { 18 bool PrefValueMap::GetValue(const std::string& key,
19 const base::Value** value) const {
19 const Map::const_iterator entry = prefs_.find(key); 20 const Map::const_iterator entry = prefs_.find(key);
20 if (entry != prefs_.end()) { 21 if (entry != prefs_.end()) {
21 if (value) 22 if (value)
22 *value = entry->second; 23 *value = entry->second;
23 return true; 24 return true;
24 } 25 }
25 26
26 return false; 27 return false;
27 } 28 }
28 29
29 bool PrefValueMap::GetValue(const std::string& key, Value** value) { 30 bool PrefValueMap::GetValue(const std::string& key, base::Value** value) {
30 const Map::const_iterator entry = prefs_.find(key); 31 const Map::const_iterator entry = prefs_.find(key);
31 if (entry != prefs_.end()) { 32 if (entry != prefs_.end()) {
32 if (value) 33 if (value)
33 *value = entry->second; 34 *value = entry->second;
34 return true; 35 return true;
35 } 36 }
36 37
37 return false; 38 return false;
38 } 39 }
39 40
40 bool PrefValueMap::SetValue(const std::string& key, Value* value) { 41 bool PrefValueMap::SetValue(const std::string& key, base::Value* value) {
41 DCHECK(value); 42 DCHECK(value);
42 scoped_ptr<Value> value_ptr(value); 43 scoped_ptr<base::Value> value_ptr(value);
43 const Map::iterator entry = prefs_.find(key); 44 const Map::iterator entry = prefs_.find(key);
44 if (entry != prefs_.end()) { 45 if (entry != prefs_.end()) {
45 if (Value::Equals(entry->second, value)) 46 if (base::Value::Equals(entry->second, value))
46 return false; 47 return false;
47 delete entry->second; 48 delete entry->second;
48 entry->second = value_ptr.release(); 49 entry->second = value_ptr.release();
49 } else { 50 } else {
50 prefs_[key] = value_ptr.release(); 51 prefs_[key] = value_ptr.release();
51 } 52 }
52 53
53 return true; 54 return true;
54 } 55 }
55 56
(...skipping 28 matching lines...) Expand all
84 PrefValueMap::const_iterator PrefValueMap::begin() const { 85 PrefValueMap::const_iterator PrefValueMap::begin() const {
85 return prefs_.begin(); 86 return prefs_.begin();
86 } 87 }
87 88
88 PrefValueMap::const_iterator PrefValueMap::end() const { 89 PrefValueMap::const_iterator PrefValueMap::end() const {
89 return prefs_.end(); 90 return prefs_.end();
90 } 91 }
91 92
92 bool PrefValueMap::GetBoolean(const std::string& key, 93 bool PrefValueMap::GetBoolean(const std::string& key,
93 bool* value) const { 94 bool* value) const {
94 const Value* stored_value = NULL; 95 const base::Value* stored_value = NULL;
95 return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value); 96 return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value);
96 } 97 }
97 98
98 void PrefValueMap::SetBoolean(const std::string& key, bool value) { 99 void PrefValueMap::SetBoolean(const std::string& key, bool value) {
99 SetValue(key, new base::FundamentalValue(value)); 100 SetValue(key, new base::FundamentalValue(value));
100 } 101 }
101 102
102 bool PrefValueMap::GetString(const std::string& key, 103 bool PrefValueMap::GetString(const std::string& key,
103 std::string* value) const { 104 std::string* value) const {
104 const Value* stored_value = NULL; 105 const base::Value* stored_value = NULL;
105 return GetValue(key, &stored_value) && stored_value->GetAsString(value); 106 return GetValue(key, &stored_value) && stored_value->GetAsString(value);
106 } 107 }
107 108
108 void PrefValueMap::SetString(const std::string& key, 109 void PrefValueMap::SetString(const std::string& key,
109 const std::string& value) { 110 const std::string& value) {
110 SetValue(key, new base::StringValue(value)); 111 SetValue(key, new base::StringValue(value));
111 } 112 }
112 113
113 bool PrefValueMap::GetInteger(const std::string& key, int* value) const { 114 bool PrefValueMap::GetInteger(const std::string& key, int* value) const {
114 const Value* stored_value = NULL; 115 const base::Value* stored_value = NULL;
115 return GetValue(key, &stored_value) && stored_value->GetAsInteger(value); 116 return GetValue(key, &stored_value) && stored_value->GetAsInteger(value);
116 } 117 }
117 118
118 void PrefValueMap::SetInteger(const std::string& key, const int value) { 119 void PrefValueMap::SetInteger(const std::string& key, const int value) {
119 SetValue(key, new base::FundamentalValue(value)); 120 SetValue(key, new base::FundamentalValue(value));
120 } 121 }
121 122
122 void PrefValueMap::GetDifferingKeys( 123 void PrefValueMap::GetDifferingKeys(
123 const PrefValueMap* other, 124 const PrefValueMap* other,
124 std::vector<std::string>* differing_keys) const { 125 std::vector<std::string>* differing_keys) const {
(...skipping 17 matching lines...) Expand all
142 ++other_pref; 143 ++other_pref;
143 } 144 }
144 } 145 }
145 146
146 // Add the remaining entries. 147 // Add the remaining entries.
147 for ( ; this_pref != prefs_.end(); ++this_pref) 148 for ( ; this_pref != prefs_.end(); ++this_pref)
148 differing_keys->push_back(this_pref->first); 149 differing_keys->push_back(this_pref->first);
149 for ( ; other_pref != other->prefs_.end(); ++other_pref) 150 for ( ; other_pref != other->prefs_.end(); ++other_pref)
150 differing_keys->push_back(other_pref->first); 151 differing_keys->push_back(other_pref->first);
151 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698