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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return prefs_.empty(); | 85 return prefs_.empty(); |
86 } | 86 } |
87 | 87 |
88 bool PrefValueMap::GetBoolean(const std::string& key, | 88 bool PrefValueMap::GetBoolean(const std::string& key, |
89 bool* value) const { | 89 bool* value) const { |
90 const base::Value* stored_value = nullptr; | 90 const base::Value* stored_value = nullptr; |
91 return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value); | 91 return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value); |
92 } | 92 } |
93 | 93 |
94 void PrefValueMap::SetBoolean(const std::string& key, bool value) { | 94 void PrefValueMap::SetBoolean(const std::string& key, bool value) { |
95 SetValue(key, base::MakeUnique<base::FundamentalValue>(value)); | 95 SetValue(key, base::MakeUnique<base::Value>(value)); |
96 } | 96 } |
97 | 97 |
98 bool PrefValueMap::GetString(const std::string& key, | 98 bool PrefValueMap::GetString(const std::string& key, |
99 std::string* value) const { | 99 std::string* value) const { |
100 const base::Value* stored_value = nullptr; | 100 const base::Value* stored_value = nullptr; |
101 return GetValue(key, &stored_value) && stored_value->GetAsString(value); | 101 return GetValue(key, &stored_value) && stored_value->GetAsString(value); |
102 } | 102 } |
103 | 103 |
104 void PrefValueMap::SetString(const std::string& key, | 104 void PrefValueMap::SetString(const std::string& key, |
105 const std::string& value) { | 105 const std::string& value) { |
106 SetValue(key, base::MakeUnique<base::StringValue>(value)); | 106 SetValue(key, base::MakeUnique<base::StringValue>(value)); |
107 } | 107 } |
108 | 108 |
109 bool PrefValueMap::GetInteger(const std::string& key, int* value) const { | 109 bool PrefValueMap::GetInteger(const std::string& key, int* value) const { |
110 const base::Value* stored_value = nullptr; | 110 const base::Value* stored_value = nullptr; |
111 return GetValue(key, &stored_value) && stored_value->GetAsInteger(value); | 111 return GetValue(key, &stored_value) && stored_value->GetAsInteger(value); |
112 } | 112 } |
113 | 113 |
114 void PrefValueMap::SetInteger(const std::string& key, const int value) { | 114 void PrefValueMap::SetInteger(const std::string& key, const int value) { |
115 SetValue(key, base::MakeUnique<base::FundamentalValue>(value)); | 115 SetValue(key, base::MakeUnique<base::Value>(value)); |
116 } | 116 } |
117 | 117 |
118 void PrefValueMap::SetDouble(const std::string& key, const double value) { | 118 void PrefValueMap::SetDouble(const std::string& key, const double value) { |
119 SetValue(key, base::MakeUnique<base::FundamentalValue>(value)); | 119 SetValue(key, base::MakeUnique<base::Value>(value)); |
120 } | 120 } |
121 | 121 |
122 void PrefValueMap::GetDifferingKeys( | 122 void PrefValueMap::GetDifferingKeys( |
123 const PrefValueMap* other, | 123 const PrefValueMap* other, |
124 std::vector<std::string>* differing_keys) const { | 124 std::vector<std::string>* differing_keys) const { |
125 differing_keys->clear(); | 125 differing_keys->clear(); |
126 | 126 |
127 // Put everything into ordered maps. | 127 // Put everything into ordered maps. |
128 std::map<std::string, base::Value*> this_prefs; | 128 std::map<std::string, base::Value*> this_prefs; |
129 std::map<std::string, base::Value*> other_prefs; | 129 std::map<std::string, base::Value*> other_prefs; |
(...skipping 28 matching lines...) Expand all Loading... |
158 differing_keys->push_back(other_pref->first); | 158 differing_keys->push_back(other_pref->first); |
159 } | 159 } |
160 | 160 |
161 std::unique_ptr<base::DictionaryValue> PrefValueMap::AsDictionaryValue() const { | 161 std::unique_ptr<base::DictionaryValue> PrefValueMap::AsDictionaryValue() const { |
162 auto dictionary = base::MakeUnique<base::DictionaryValue>(); | 162 auto dictionary = base::MakeUnique<base::DictionaryValue>(); |
163 for (const auto& value : prefs_) { | 163 for (const auto& value : prefs_) { |
164 dictionary->Set(value.first, value.second->CreateDeepCopy()); | 164 dictionary->Set(value.first, value.second->CreateDeepCopy()); |
165 } | 165 } |
166 return dictionary; | 166 return dictionary; |
167 } | 167 } |
OLD | NEW |