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

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

Issue 1907043002: Convert //components/prefs from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IWYU fixes Created 4 years, 8 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 <utility> 8 #include <utility>
8 9
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 12
12 OverlayUserPrefStore::OverlayUserPrefStore( 13 OverlayUserPrefStore::OverlayUserPrefStore(
13 PersistentPrefStore* underlay) 14 PersistentPrefStore* underlay)
14 : underlay_(underlay) { 15 : underlay_(underlay) {
15 underlay_->AddObserver(this); 16 underlay_->AddObserver(this);
16 } 17 }
17 18
18 bool OverlayUserPrefStore::IsSetInOverlay(const std::string& key) const { 19 bool OverlayUserPrefStore::IsSetInOverlay(const std::string& key) const {
19 return overlay_.GetValue(key, NULL); 20 return overlay_.GetValue(key, NULL);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 54
54 if (overlay_.GetValue(key, result)) 55 if (overlay_.GetValue(key, result))
55 return true; 56 return true;
56 57
57 // 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.
58 base::Value* underlay_value = NULL; 59 base::Value* underlay_value = NULL;
59 if (!underlay_->GetMutableValue(GetUnderlayKey(key), &underlay_value)) 60 if (!underlay_->GetMutableValue(GetUnderlayKey(key), &underlay_value))
60 return false; 61 return false;
61 62
62 *result = underlay_value->DeepCopy(); 63 *result = underlay_value->DeepCopy();
63 overlay_.SetValue(key, make_scoped_ptr(*result)); 64 overlay_.SetValue(key, base::WrapUnique(*result));
64 return true; 65 return true;
65 } 66 }
66 67
67 void OverlayUserPrefStore::SetValue(const std::string& key, 68 void OverlayUserPrefStore::SetValue(const std::string& key,
68 scoped_ptr<base::Value> value, 69 std::unique_ptr<base::Value> value,
69 uint32_t flags) { 70 uint32_t flags) {
70 if (!ShallBeStoredInOverlay(key)) { 71 if (!ShallBeStoredInOverlay(key)) {
71 underlay_->SetValue(GetUnderlayKey(key), std::move(value), flags); 72 underlay_->SetValue(GetUnderlayKey(key), std::move(value), flags);
72 return; 73 return;
73 } 74 }
74 75
75 if (overlay_.SetValue(key, std::move(value))) 76 if (overlay_.SetValue(key, std::move(value)))
76 ReportValueChanged(key, flags); 77 ReportValueChanged(key, flags);
77 } 78 }
78 79
79 void OverlayUserPrefStore::SetValueSilently(const std::string& key, 80 void OverlayUserPrefStore::SetValueSilently(const std::string& key,
80 scoped_ptr<base::Value> value, 81 std::unique_ptr<base::Value> value,
81 uint32_t flags) { 82 uint32_t flags) {
82 if (!ShallBeStoredInOverlay(key)) { 83 if (!ShallBeStoredInOverlay(key)) {
83 underlay_->SetValueSilently(GetUnderlayKey(key), std::move(value), flags); 84 underlay_->SetValueSilently(GetUnderlayKey(key), std::move(value), flags);
84 return; 85 return;
85 } 86 }
86 87
87 overlay_.SetValue(key, std::move(value)); 88 overlay_.SetValue(key, std::move(value));
88 } 89 }
89 90
90 void OverlayUserPrefStore::RemoveValue(const std::string& key, uint32_t flags) { 91 void OverlayUserPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
(...skipping 15 matching lines...) Expand all
106 } 107 }
107 108
108 PersistentPrefStore::PrefReadError OverlayUserPrefStore::ReadPrefs() { 109 PersistentPrefStore::PrefReadError OverlayUserPrefStore::ReadPrefs() {
109 // We do not read intentionally. 110 // We do not read intentionally.
110 OnInitializationCompleted(true); 111 OnInitializationCompleted(true);
111 return PersistentPrefStore::PREF_READ_ERROR_NONE; 112 return PersistentPrefStore::PREF_READ_ERROR_NONE;
112 } 113 }
113 114
114 void OverlayUserPrefStore::ReadPrefsAsync( 115 void OverlayUserPrefStore::ReadPrefsAsync(
115 ReadErrorDelegate* error_delegate_raw) { 116 ReadErrorDelegate* error_delegate_raw) {
116 scoped_ptr<ReadErrorDelegate> error_delegate(error_delegate_raw); 117 std::unique_ptr<ReadErrorDelegate> error_delegate(error_delegate_raw);
117 // We do not read intentionally. 118 // We do not read intentionally.
118 OnInitializationCompleted(true); 119 OnInitializationCompleted(true);
119 } 120 }
120 121
121 void OverlayUserPrefStore::CommitPendingWrite() { 122 void OverlayUserPrefStore::CommitPendingWrite() {
122 underlay_->CommitPendingWrite(); 123 underlay_->CommitPendingWrite();
123 // We do not write our content intentionally. 124 // We do not write our content intentionally.
124 } 125 }
125 126
126 void OverlayUserPrefStore::SchedulePendingLossyWrites() { 127 void OverlayUserPrefStore::SchedulePendingLossyWrites() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 NamesMap::const_iterator i = 182 NamesMap::const_iterator i =
182 overlay_to_underlay_names_map_.find(overlay_key); 183 overlay_to_underlay_names_map_.find(overlay_key);
183 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; 184 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key;
184 } 185 }
185 186
186 bool OverlayUserPrefStore::ShallBeStoredInOverlay( 187 bool OverlayUserPrefStore::ShallBeStoredInOverlay(
187 const std::string& key) const { 188 const std::string& key) const {
188 return overlay_to_underlay_names_map_.find(key) != 189 return overlay_to_underlay_names_map_.find(key) !=
189 overlay_to_underlay_names_map_.end(); 190 overlay_to_underlay_names_map_.end();
190 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698