| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 base::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, make_scoped_ptr(*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 base::Value* value, | 66 scoped_ptr<base::Value> value, |
| 67 uint32 flags) { | 67 uint32 flags) { |
| 68 if (!ShallBeStoredInOverlay(key)) { | 68 if (!ShallBeStoredInOverlay(key)) { |
| 69 underlay_->SetValue(GetUnderlayKey(key), value, flags); | 69 underlay_->SetValue(GetUnderlayKey(key), value.Pass(), flags); |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 | 72 |
| 73 if (overlay_.SetValue(key, value)) | 73 if (overlay_.SetValue(key, value.Pass())) |
| 74 ReportValueChanged(key, flags); | 74 ReportValueChanged(key, flags); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void OverlayUserPrefStore::SetValueSilently(const std::string& key, | 77 void OverlayUserPrefStore::SetValueSilently(const std::string& key, |
| 78 base::Value* value, | 78 scoped_ptr<base::Value> value, |
| 79 uint32 flags) { | 79 uint32 flags) { |
| 80 if (!ShallBeStoredInOverlay(key)) { | 80 if (!ShallBeStoredInOverlay(key)) { |
| 81 underlay_->SetValueSilently(GetUnderlayKey(key), value, flags); | 81 underlay_->SetValueSilently(GetUnderlayKey(key), value.Pass(), flags); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 overlay_.SetValue(key, value); | 85 overlay_.SetValue(key, value.Pass()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void OverlayUserPrefStore::RemoveValue(const std::string& key, uint32 flags) { | 88 void OverlayUserPrefStore::RemoveValue(const std::string& key, uint32 flags) { |
| 89 if (!ShallBeStoredInOverlay(key)) { | 89 if (!ShallBeStoredInOverlay(key)) { |
| 90 underlay_->RemoveValue(GetUnderlayKey(key), flags); | 90 underlay_->RemoveValue(GetUnderlayKey(key), flags); |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 93 | 93 |
| 94 if (overlay_.RemoveValue(key)) | 94 if (overlay_.RemoveValue(key)) |
| 95 ReportValueChanged(key, flags); | 95 ReportValueChanged(key, flags); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 NamesMap::const_iterator i = | 175 NamesMap::const_iterator i = |
| 176 overlay_to_underlay_names_map_.find(overlay_key); | 176 overlay_to_underlay_names_map_.find(overlay_key); |
| 177 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; | 177 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool OverlayUserPrefStore::ShallBeStoredInOverlay( | 180 bool OverlayUserPrefStore::ShallBeStoredInOverlay( |
| 181 const std::string& key) const { | 181 const std::string& key) const { |
| 182 return overlay_to_underlay_names_map_.find(key) != | 182 return overlay_to_underlay_names_map_.find(key) != |
| 183 overlay_to_underlay_names_map_.end(); | 183 overlay_to_underlay_names_map_.end(); |
| 184 } | 184 } |
| OLD | NEW |