| 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 16 matching lines...) Expand all Loading... |
| 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 bool OverlayUserPrefStore::GetValue(const std::string& key, | 36 bool OverlayUserPrefStore::GetValue(const std::string& key, |
| 37 const Value** result) const { | 37 const base::Value** result) const { |
| 38 // 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 |
| 39 // be an entry. | 39 // be an entry. |
| 40 DCHECK(ShallBeStoredInOverlay(key) || !overlay_.GetValue(key, NULL)); | 40 DCHECK(ShallBeStoredInOverlay(key) || !overlay_.GetValue(key, NULL)); |
| 41 | 41 |
| 42 if (overlay_.GetValue(key, result)) | 42 if (overlay_.GetValue(key, result)) |
| 43 return true; | 43 return true; |
| 44 return underlay_->GetValue(GetUnderlayKey(key), result); | 44 return underlay_->GetValue(GetUnderlayKey(key), result); |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool OverlayUserPrefStore::GetMutableValue(const std::string& key, | 47 bool OverlayUserPrefStore::GetMutableValue(const std::string& key, |
| 48 Value** result) { | 48 base::Value** result) { |
| 49 if (!ShallBeStoredInOverlay(key)) | 49 if (!ShallBeStoredInOverlay(key)) |
| 50 return underlay_->GetMutableValue(GetUnderlayKey(key), result); | 50 return underlay_->GetMutableValue(GetUnderlayKey(key), result); |
| 51 | 51 |
| 52 if (overlay_.GetValue(key, result)) | 52 if (overlay_.GetValue(key, result)) |
| 53 return true; | 53 return true; |
| 54 | 54 |
| 55 // 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. |
| 56 Value* underlay_value = NULL; | 56 base::Value* underlay_value = NULL; |
| 57 if (!underlay_->GetMutableValue(GetUnderlayKey(key), &underlay_value)) | 57 if (!underlay_->GetMutableValue(GetUnderlayKey(key), &underlay_value)) |
| 58 return false; | 58 return false; |
| 59 | 59 |
| 60 *result = underlay_value->DeepCopy(); | 60 *result = underlay_value->DeepCopy(); |
| 61 overlay_.SetValue(key, *result); | 61 overlay_.SetValue(key, *result); |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void OverlayUserPrefStore::SetValue(const std::string& key, | 65 void OverlayUserPrefStore::SetValue(const std::string& key, |
| 66 Value* value) { | 66 base::Value* value) { |
| 67 if (!ShallBeStoredInOverlay(key)) { | 67 if (!ShallBeStoredInOverlay(key)) { |
| 68 underlay_->SetValue(GetUnderlayKey(key), value); | 68 underlay_->SetValue(GetUnderlayKey(key), value); |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 | 71 |
| 72 if (overlay_.SetValue(key, value)) | 72 if (overlay_.SetValue(key, value)) |
| 73 ReportValueChanged(key); | 73 ReportValueChanged(key); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void OverlayUserPrefStore::SetValueSilently(const std::string& key, | 76 void OverlayUserPrefStore::SetValueSilently(const std::string& key, |
| 77 Value* value) { | 77 base::Value* value) { |
| 78 if (!ShallBeStoredInOverlay(key)) { | 78 if (!ShallBeStoredInOverlay(key)) { |
| 79 underlay_->SetValueSilently(GetUnderlayKey(key), value); | 79 underlay_->SetValueSilently(GetUnderlayKey(key), value); |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 | 82 |
| 83 overlay_.SetValue(key, value); | 83 overlay_.SetValue(key, value); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void OverlayUserPrefStore::RemoveValue(const std::string& key) { | 86 void OverlayUserPrefStore::RemoveValue(const std::string& key) { |
| 87 if (!ShallBeStoredInOverlay(key)) { | 87 if (!ShallBeStoredInOverlay(key)) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 NamesMap::const_iterator i = | 173 NamesMap::const_iterator i = |
| 174 overlay_to_underlay_names_map_.find(overlay_key); | 174 overlay_to_underlay_names_map_.find(overlay_key); |
| 175 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; |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool OverlayUserPrefStore::ShallBeStoredInOverlay( | 178 bool OverlayUserPrefStore::ShallBeStoredInOverlay( |
| 179 const std::string& key) const { | 179 const std::string& key) const { |
| 180 return overlay_to_underlay_names_map_.find(key) != | 180 return overlay_to_underlay_names_map_.find(key) != |
| 181 overlay_to_underlay_names_map_.end(); | 181 overlay_to_underlay_names_map_.end(); |
| 182 } | 182 } |
| OLD | NEW |