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 "base/prefs/overlay_user_pref_store.h" | 5 #include "base/prefs/overlay_user_pref_store.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 | 9 |
10 OverlayUserPrefStore::OverlayUserPrefStore( | 10 OverlayUserPrefStore::OverlayUserPrefStore( |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 size_t OverlayUserPrefStore::NumberOfObservers() const { | 28 size_t OverlayUserPrefStore::NumberOfObservers() const { |
29 return observers_.size(); | 29 return observers_.size(); |
30 } | 30 } |
31 | 31 |
32 bool OverlayUserPrefStore::IsInitializationComplete() const { | 32 bool OverlayUserPrefStore::IsInitializationComplete() const { |
33 return underlay_->IsInitializationComplete(); | 33 return underlay_->IsInitializationComplete(); |
34 } | 34 } |
35 | 35 |
36 PrefStore::ReadResult OverlayUserPrefStore::GetValue( | 36 bool OverlayUserPrefStore::GetValue(const std::string& key, |
37 const std::string& key, | 37 const Value** result) const { |
38 const Value** result) const { | |
39 // If the |key| shall NOT be stored in the overlay store, there must not | 38 // If the |key| shall NOT be stored in the overlay store, there must not |
40 // be an entry. | 39 // be an entry. |
41 DCHECK(ShallBeStoredInOverlay(key) || !overlay_.GetValue(key, NULL)); | 40 DCHECK(ShallBeStoredInOverlay(key) || !overlay_.GetValue(key, NULL)); |
42 | 41 |
43 if (overlay_.GetValue(key, result)) | 42 if (overlay_.GetValue(key, result)) |
44 return READ_OK; | 43 return true; |
45 return underlay_->GetValue(GetUnderlayKey(key), result); | 44 return underlay_->GetValue(GetUnderlayKey(key), result); |
46 } | 45 } |
47 | 46 |
48 PrefStore::ReadResult OverlayUserPrefStore::GetMutableValue( | 47 bool OverlayUserPrefStore::GetMutableValue(const std::string& key, |
49 const std::string& key, | 48 Value** result) { |
50 Value** result) { | |
51 if (!ShallBeStoredInOverlay(key)) | 49 if (!ShallBeStoredInOverlay(key)) |
52 return underlay_->GetMutableValue(GetUnderlayKey(key), result); | 50 return underlay_->GetMutableValue(GetUnderlayKey(key), result); |
53 | 51 |
54 if (overlay_.GetValue(key, result)) | 52 if (overlay_.GetValue(key, result)) |
55 return READ_OK; | 53 return true; |
56 | 54 |
57 // Try to create copy of underlay if the overlay does not contain a value. | 55 // Try to create copy of underlay if the overlay does not contain a value. |
58 Value* underlay_value = NULL; | 56 Value* underlay_value = NULL; |
59 PrefStore::ReadResult read_result = | 57 if (!underlay_->GetMutableValue(GetUnderlayKey(key), &underlay_value)) |
60 underlay_->GetMutableValue(GetUnderlayKey(key), &underlay_value); | 58 return false; |
61 if (read_result != READ_OK) | |
62 return read_result; | |
63 | 59 |
64 *result = underlay_value->DeepCopy(); | 60 *result = underlay_value->DeepCopy(); |
65 overlay_.SetValue(key, *result); | 61 overlay_.SetValue(key, *result); |
66 return READ_OK; | 62 return true; |
67 } | 63 } |
68 | 64 |
69 void OverlayUserPrefStore::SetValue(const std::string& key, | 65 void OverlayUserPrefStore::SetValue(const std::string& key, |
70 Value* value) { | 66 Value* value) { |
71 if (!ShallBeStoredInOverlay(key)) { | 67 if (!ShallBeStoredInOverlay(key)) { |
72 underlay_->SetValue(GetUnderlayKey(key), value); | 68 underlay_->SetValue(GetUnderlayKey(key), value); |
73 return; | 69 return; |
74 } | 70 } |
75 | 71 |
76 if (overlay_.SetValue(key, value)) | 72 if (overlay_.SetValue(key, value)) |
77 ReportValueChanged(key); | 73 ReportValueChanged(key); |
78 } | 74 } |
79 | 75 |
80 void OverlayUserPrefStore::SetValueSilently(const std::string& key, | 76 void OverlayUserPrefStore::SetValueSilently(const std::string& key, |
81 Value* value) { | 77 Value* value) { |
82 if (!ShallBeStoredInOverlay(key)) { | 78 if (!ShallBeStoredInOverlay(key)) { |
83 underlay_->SetValueSilently(GetUnderlayKey(key), value); | 79 underlay_->SetValueSilently(GetUnderlayKey(key), value); |
84 return; | 80 return; |
85 } | 81 } |
86 | 82 |
87 overlay_.SetValue(key, value); | 83 overlay_.SetValue(key, value); |
88 } | 84 } |
89 | 85 |
90 void OverlayUserPrefStore::RemoveValue(const std::string& key) { | 86 void OverlayUserPrefStore::RemoveValue(const std::string& key) { |
91 if (!ShallBeStoredInOverlay(key)) { | 87 if (!ShallBeStoredInOverlay(key)) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 NamesMap::const_iterator i = | 173 NamesMap::const_iterator i = |
178 overlay_to_underlay_names_map_.find(overlay_key); | 174 overlay_to_underlay_names_map_.find(overlay_key); |
179 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; | 175 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; |
180 } | 176 } |
181 | 177 |
182 bool OverlayUserPrefStore::ShallBeStoredInOverlay( | 178 bool OverlayUserPrefStore::ShallBeStoredInOverlay( |
183 const std::string& key) const { | 179 const std::string& key) const { |
184 return overlay_to_underlay_names_map_.find(key) != | 180 return overlay_to_underlay_names_map_.find(key) != |
185 overlay_to_underlay_names_map_.end(); | 181 overlay_to_underlay_names_map_.end(); |
186 } | 182 } |
OLD | NEW |