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 "components/prefs/pref_value_map.h" | 5 #include "components/prefs/pref_value_map.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 return prefs_.empty(); | 78 return prefs_.empty(); |
79 } | 79 } |
80 | 80 |
81 bool PrefValueMap::GetBoolean(const std::string& key, | 81 bool PrefValueMap::GetBoolean(const std::string& key, |
82 bool* value) const { | 82 bool* value) const { |
83 const base::Value* stored_value = nullptr; | 83 const base::Value* stored_value = nullptr; |
84 return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value); | 84 return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value); |
85 } | 85 } |
86 | 86 |
87 void PrefValueMap::SetBoolean(const std::string& key, bool value) { | 87 void PrefValueMap::SetBoolean(const std::string& key, bool value) { |
88 SetValue(key, base::MakeUnique<base::FundamentalValue>(value)); | 88 SetValue(key, base::MakeUnique<base::Value>(value)); |
89 } | 89 } |
90 | 90 |
91 bool PrefValueMap::GetString(const std::string& key, | 91 bool PrefValueMap::GetString(const std::string& key, |
92 std::string* value) const { | 92 std::string* value) const { |
93 const base::Value* stored_value = nullptr; | 93 const base::Value* stored_value = nullptr; |
94 return GetValue(key, &stored_value) && stored_value->GetAsString(value); | 94 return GetValue(key, &stored_value) && stored_value->GetAsString(value); |
95 } | 95 } |
96 | 96 |
97 void PrefValueMap::SetString(const std::string& key, | 97 void PrefValueMap::SetString(const std::string& key, |
98 const std::string& value) { | 98 const std::string& value) { |
99 SetValue(key, base::MakeUnique<base::StringValue>(value)); | 99 SetValue(key, base::MakeUnique<base::StringValue>(value)); |
100 } | 100 } |
101 | 101 |
102 bool PrefValueMap::GetInteger(const std::string& key, int* value) const { | 102 bool PrefValueMap::GetInteger(const std::string& key, int* value) const { |
103 const base::Value* stored_value = nullptr; | 103 const base::Value* stored_value = nullptr; |
104 return GetValue(key, &stored_value) && stored_value->GetAsInteger(value); | 104 return GetValue(key, &stored_value) && stored_value->GetAsInteger(value); |
105 } | 105 } |
106 | 106 |
107 void PrefValueMap::SetInteger(const std::string& key, const int value) { | 107 void PrefValueMap::SetInteger(const std::string& key, const int value) { |
108 SetValue(key, base::MakeUnique<base::FundamentalValue>(value)); | 108 SetValue(key, base::MakeUnique<base::Value>(value)); |
109 } | 109 } |
110 | 110 |
111 void PrefValueMap::SetDouble(const std::string& key, const double value) { | 111 void PrefValueMap::SetDouble(const std::string& key, const double value) { |
112 SetValue(key, base::MakeUnique<base::FundamentalValue>(value)); | 112 SetValue(key, base::MakeUnique<base::Value>(value)); |
113 } | 113 } |
114 | 114 |
115 void PrefValueMap::GetDifferingKeys( | 115 void PrefValueMap::GetDifferingKeys( |
116 const PrefValueMap* other, | 116 const PrefValueMap* other, |
117 std::vector<std::string>* differing_keys) const { | 117 std::vector<std::string>* differing_keys) const { |
118 differing_keys->clear(); | 118 differing_keys->clear(); |
119 | 119 |
120 // Put everything into ordered maps. | 120 // Put everything into ordered maps. |
121 std::map<std::string, base::Value*> this_prefs(prefs_.begin(), prefs_.end()); | 121 std::map<std::string, base::Value*> this_prefs(prefs_.begin(), prefs_.end()); |
122 std::map<std::string, base::Value*> other_prefs(other->prefs_.begin(), | 122 std::map<std::string, base::Value*> other_prefs(other->prefs_.begin(), |
(...skipping 17 matching lines...) Expand all Loading... |
140 ++other_pref; | 140 ++other_pref; |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 // Add the remaining entries. | 144 // Add the remaining entries. |
145 for ( ; this_pref != this_prefs.end(); ++this_pref) | 145 for ( ; this_pref != this_prefs.end(); ++this_pref) |
146 differing_keys->push_back(this_pref->first); | 146 differing_keys->push_back(this_pref->first); |
147 for ( ; other_pref != other_prefs.end(); ++other_pref) | 147 for ( ; other_pref != other_prefs.end(); ++other_pref) |
148 differing_keys->push_back(other_pref->first); | 148 differing_keys->push_back(other_pref->first); |
149 } | 149 } |
OLD | NEW |