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 values = underlay_->GetValues(); |
| 52 auto overlay_values = overlay_.AsDictionaryValue(); |
| 53 for (const auto& overlay_mapping : overlay_to_underlay_names_map_) { |
| 54 const std::string& overlay_key = overlay_mapping.first; |
| 55 const std::string& underlay_key = overlay_mapping.second; |
| 56 std::unique_ptr<base::Value> out_value; |
| 57 if (overlay_key != underlay_key) { |
| 58 values->Remove(underlay_key, &out_value); |
| 59 } |
| 60 overlay_values->Remove(overlay_key, &out_value); |
| 61 if (out_value) { |
| 62 values->Set(overlay_key, std::move(out_value)); |
| 63 } |
| 64 } |
| 65 return values; |
| 66 } |
| 67 |
50 bool OverlayUserPrefStore::GetMutableValue(const std::string& key, | 68 bool OverlayUserPrefStore::GetMutableValue(const std::string& key, |
51 base::Value** result) { | 69 base::Value** result) { |
52 if (!ShallBeStoredInOverlay(key)) | 70 if (!ShallBeStoredInOverlay(key)) |
53 return underlay_->GetMutableValue(GetUnderlayKey(key), result); | 71 return underlay_->GetMutableValue(GetUnderlayKey(key), result); |
54 | 72 |
55 if (overlay_.GetValue(key, result)) | 73 if (overlay_.GetValue(key, result)) |
56 return true; | 74 return true; |
57 | 75 |
58 // Try to create copy of underlay if the overlay does not contain a value. | 76 // Try to create copy of underlay if the overlay does not contain a value. |
59 base::Value* underlay_value = NULL; | 77 base::Value* underlay_value = NULL; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 NamesMap::const_iterator i = | 201 NamesMap::const_iterator i = |
184 overlay_to_underlay_names_map_.find(overlay_key); | 202 overlay_to_underlay_names_map_.find(overlay_key); |
185 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; | 203 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; |
186 } | 204 } |
187 | 205 |
188 bool OverlayUserPrefStore::ShallBeStoredInOverlay( | 206 bool OverlayUserPrefStore::ShallBeStoredInOverlay( |
189 const std::string& key) const { | 207 const std::string& key) const { |
190 return overlay_to_underlay_names_map_.find(key) != | 208 return overlay_to_underlay_names_map_.find(key) != |
191 overlay_to_underlay_names_map_.end(); | 209 overlay_to_underlay_names_map_.end(); |
192 } | 210 } |
OLD | NEW |