OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/user_prefs/tracked/segregated_pref_store.h" | 5 #include "components/user_prefs/tracked/segregated_pref_store.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 bool SegregatedPrefStore::IsInitializationComplete() const { | 76 bool SegregatedPrefStore::IsInitializationComplete() const { |
77 return default_pref_store_->IsInitializationComplete() && | 77 return default_pref_store_->IsInitializationComplete() && |
78 selected_pref_store_->IsInitializationComplete(); | 78 selected_pref_store_->IsInitializationComplete(); |
79 } | 79 } |
80 | 80 |
81 bool SegregatedPrefStore::GetValue(const std::string& key, | 81 bool SegregatedPrefStore::GetValue(const std::string& key, |
82 const base::Value** result) const { | 82 const base::Value** result) const { |
83 return StoreForKey(key)->GetValue(key, result); | 83 return StoreForKey(key)->GetValue(key, result); |
84 } | 84 } |
85 | 85 |
86 std::unique_ptr<base::DictionaryValue> SegregatedPrefStore::GetValues() const { | |
87 auto selected_values = selected_pref_store_->GetValues(); | |
Sam McNally
2017/02/16 02:21:11
These should use the selected store for keys (with
tibell
2017/02/20 00:04:57
Done.
| |
88 auto default_values = default_pref_store_->GetValues(); | |
89 auto default_iter = base::DictionaryValue::Iterator(*default_values); | |
90 while (!default_iter.IsAtEnd()) { | |
91 const std::string key = default_iter.key(); | |
92 if (!selected_values->HasKey(key)) { | |
93 selected_values->SetWithoutPathExpansion( | |
94 key, default_iter.value().CreateDeepCopy()); | |
95 } | |
96 default_iter.Advance(); | |
97 } | |
98 return selected_values; | |
99 } | |
100 | |
86 void SegregatedPrefStore::SetValue(const std::string& key, | 101 void SegregatedPrefStore::SetValue(const std::string& key, |
87 std::unique_ptr<base::Value> value, | 102 std::unique_ptr<base::Value> value, |
88 uint32_t flags) { | 103 uint32_t flags) { |
89 StoreForKey(key)->SetValue(key, std::move(value), flags); | 104 StoreForKey(key)->SetValue(key, std::move(value), flags); |
90 } | 105 } |
91 | 106 |
92 void SegregatedPrefStore::RemoveValue(const std::string& key, uint32_t flags) { | 107 void SegregatedPrefStore::RemoveValue(const std::string& key, uint32_t flags) { |
93 StoreForKey(key)->RemoveValue(key, flags); | 108 StoreForKey(key)->RemoveValue(key, flags); |
94 } | 109 } |
95 | 110 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 .get(); | 186 .get(); |
172 } | 187 } |
173 | 188 |
174 const PersistentPrefStore* SegregatedPrefStore::StoreForKey( | 189 const PersistentPrefStore* SegregatedPrefStore::StoreForKey( |
175 const std::string& key) const { | 190 const std::string& key) const { |
176 return (base::ContainsKey(selected_preference_names_, key) | 191 return (base::ContainsKey(selected_preference_names_, key) |
177 ? selected_pref_store_ | 192 ? selected_pref_store_ |
178 : default_pref_store_) | 193 : default_pref_store_) |
179 .get(); | 194 .get(); |
180 } | 195 } |
OLD | NEW |