OLD | NEW |
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 "chrome/browser/prefs/pref_value_map.h" | 5 #include "chrome/browser/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" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 std::string* value) const { | 95 std::string* value) const { |
96 const Value* stored_value = NULL; | 96 const Value* stored_value = NULL; |
97 return GetValue(key, &stored_value) && stored_value->GetAsString(value); | 97 return GetValue(key, &stored_value) && stored_value->GetAsString(value); |
98 } | 98 } |
99 | 99 |
100 void PrefValueMap::SetString(const std::string& key, | 100 void PrefValueMap::SetString(const std::string& key, |
101 const std::string& value) { | 101 const std::string& value) { |
102 SetValue(key, Value::CreateStringValue(value)); | 102 SetValue(key, Value::CreateStringValue(value)); |
103 } | 103 } |
104 | 104 |
| 105 bool PrefValueMap::GetInteger(const std::string& key, int* value) const { |
| 106 const Value* stored_value = NULL; |
| 107 return GetValue(key, &stored_value) && stored_value->GetAsInteger(value); |
| 108 } |
| 109 |
| 110 void PrefValueMap::SetInteger(const std::string& key, const int value) { |
| 111 SetValue(key, Value::CreateIntegerValue(value)); |
| 112 } |
| 113 |
105 void PrefValueMap::GetDifferingKeys( | 114 void PrefValueMap::GetDifferingKeys( |
106 const PrefValueMap* other, | 115 const PrefValueMap* other, |
107 std::vector<std::string>* differing_keys) const { | 116 std::vector<std::string>* differing_keys) const { |
108 differing_keys->clear(); | 117 differing_keys->clear(); |
109 | 118 |
110 // Walk over the maps in lockstep, adding everything that is different. | 119 // Walk over the maps in lockstep, adding everything that is different. |
111 Map::const_iterator this_pref(prefs_.begin()); | 120 Map::const_iterator this_pref(prefs_.begin()); |
112 Map::const_iterator other_pref(other->prefs_.begin()); | 121 Map::const_iterator other_pref(other->prefs_.begin()); |
113 while (this_pref != prefs_.end() && other_pref != other->prefs_.end()) { | 122 while (this_pref != prefs_.end() && other_pref != other->prefs_.end()) { |
114 const int diff = this_pref->first.compare(other_pref->first); | 123 const int diff = this_pref->first.compare(other_pref->first); |
(...skipping 10 matching lines...) Expand all Loading... |
125 ++other_pref; | 134 ++other_pref; |
126 } | 135 } |
127 } | 136 } |
128 | 137 |
129 // Add the remaining entries. | 138 // Add the remaining entries. |
130 for ( ; this_pref != prefs_.end(); ++this_pref) | 139 for ( ; this_pref != prefs_.end(); ++this_pref) |
131 differing_keys->push_back(this_pref->first); | 140 differing_keys->push_back(this_pref->first); |
132 for ( ; other_pref != other->prefs_.end(); ++other_pref) | 141 for ( ; other_pref != other->prefs_.end(); ++other_pref) |
133 differing_keys->push_back(other_pref->first); | 142 differing_keys->push_back(other_pref->first); |
134 } | 143 } |
OLD | NEW |