OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/overlay_user_pref_store.h" | 5 #include "components/prefs/overlay_user_pref_store.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 const base::Value** result) const { | 40 const base::Value** result) const { |
41 // If the |key| shall NOT be stored in the overlay store, there must not | 41 // If the |key| shall NOT be stored in the overlay store, there must not |
42 // be an entry. | 42 // be an entry. |
43 DCHECK(ShallBeStoredInOverlay(key) || !overlay_.GetValue(key, NULL)); | 43 DCHECK(ShallBeStoredInOverlay(key) || !overlay_.GetValue(key, NULL)); |
44 | 44 |
45 if (overlay_.GetValue(key, result)) | 45 if (overlay_.GetValue(key, result)) |
46 return true; | 46 return true; |
47 return underlay_->GetValue(GetUnderlayKey(key), result); | 47 return underlay_->GetValue(GetUnderlayKey(key), result); |
48 } | 48 } |
49 | 49 |
50 std::unique_ptr<base::DictionaryValue> OverlayUserPrefStore::GetValues() const { | |
51 auto overlay_values = overlay_.AsDictionaryValue(); | |
52 auto underlay_values = underlay_->GetValues(); | |
53 auto underlay_iter = base::DictionaryValue::Iterator(*underlay_values); | |
54 while (!underlay_iter.IsAtEnd()) { | |
55 const std::string overlay_key = GetOverlayKey(underlay_iter.key()); | |
Sam McNally
2017/02/16 02:21:11
const std::string&
tibell
2017/02/20 00:04:57
Done.
| |
56 if (!overlay_values->HasKey(overlay_key)) { | |
57 overlay_values->SetWithoutPathExpansion( | |
58 overlay_key, underlay_iter.value().CreateDeepCopy()); | |
59 } | |
60 underlay_iter.Advance(); | |
61 } | |
62 return overlay_values; | |
63 } | |
64 | |
50 bool OverlayUserPrefStore::GetMutableValue(const std::string& key, | 65 bool OverlayUserPrefStore::GetMutableValue(const std::string& key, |
51 base::Value** result) { | 66 base::Value** result) { |
52 if (!ShallBeStoredInOverlay(key)) | 67 if (!ShallBeStoredInOverlay(key)) |
53 return underlay_->GetMutableValue(GetUnderlayKey(key), result); | 68 return underlay_->GetMutableValue(GetUnderlayKey(key), result); |
54 | 69 |
55 if (overlay_.GetValue(key, result)) | 70 if (overlay_.GetValue(key, result)) |
56 return true; | 71 return true; |
57 | 72 |
58 // Try to create copy of underlay if the overlay does not contain a value. | 73 // Try to create copy of underlay if the overlay does not contain a value. |
59 base::Value* underlay_value = NULL; | 74 base::Value* underlay_value = NULL; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 NamesMap::const_iterator i = | 198 NamesMap::const_iterator i = |
184 overlay_to_underlay_names_map_.find(overlay_key); | 199 overlay_to_underlay_names_map_.find(overlay_key); |
185 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; | 200 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; |
186 } | 201 } |
187 | 202 |
188 bool OverlayUserPrefStore::ShallBeStoredInOverlay( | 203 bool OverlayUserPrefStore::ShallBeStoredInOverlay( |
189 const std::string& key) const { | 204 const std::string& key) const { |
190 return overlay_to_underlay_names_map_.find(key) != | 205 return overlay_to_underlay_names_map_.find(key) != |
191 overlay_to_underlay_names_map_.end(); | 206 overlay_to_underlay_names_map_.end(); |
192 } | 207 } |
OLD | NEW |