Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: components/prefs/overlay_user_pref_store.cc

Issue 2704133006: Revert of Add PrefStore::GetValues (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
68 bool OverlayUserPrefStore::GetMutableValue(const std::string& key, 50 bool OverlayUserPrefStore::GetMutableValue(const std::string& key,
69 base::Value** result) { 51 base::Value** result) {
70 if (!ShallBeStoredInOverlay(key)) 52 if (!ShallBeStoredInOverlay(key))
71 return underlay_->GetMutableValue(GetUnderlayKey(key), result); 53 return underlay_->GetMutableValue(GetUnderlayKey(key), result);
72 54
73 if (overlay_.GetValue(key, result)) 55 if (overlay_.GetValue(key, result))
74 return true; 56 return true;
75 57
76 // Try to create copy of underlay if the overlay does not contain a value. 58 // Try to create copy of underlay if the overlay does not contain a value.
77 base::Value* underlay_value = NULL; 59 base::Value* underlay_value = NULL;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 NamesMap::const_iterator i = 183 NamesMap::const_iterator i =
202 overlay_to_underlay_names_map_.find(overlay_key); 184 overlay_to_underlay_names_map_.find(overlay_key);
203 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; 185 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key;
204 } 186 }
205 187
206 bool OverlayUserPrefStore::ShallBeStoredInOverlay( 188 bool OverlayUserPrefStore::ShallBeStoredInOverlay(
207 const std::string& key) const { 189 const std::string& key) const {
208 return overlay_to_underlay_names_map_.find(key) != 190 return overlay_to_underlay_names_map_.find(key) !=
209 overlay_to_underlay_names_map_.end(); 191 overlay_to_underlay_names_map_.end();
210 } 192 }
OLDNEW
« no previous file with comments | « components/prefs/overlay_user_pref_store.h ('k') | components/prefs/overlay_user_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698