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

Side by Side Diff: services/preferences/persistent_pref_store_impl.cc

Issue 2803023005: Switch base::Value typemapping to be by value instead of by unique_ptr.
Patch Set: Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "services/preferences/persistent_pref_store_impl.h" 5 #include "services/preferences/persistent_pref_store_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 24 matching lines...) Expand all
35 ~Connection() override = default; 35 ~Connection() override = default;
36 36
37 void OnPrefValuesChanged(const std::vector<mojom::PrefUpdatePtr>& updates) { 37 void OnPrefValuesChanged(const std::vector<mojom::PrefUpdatePtr>& updates) {
38 if (write_in_progress_) 38 if (write_in_progress_)
39 return; 39 return;
40 40
41 std::vector<mojom::PrefUpdatePtr> filtered_updates; 41 std::vector<mojom::PrefUpdatePtr> filtered_updates;
42 for (const auto& update : updates) { 42 for (const auto& update : updates) {
43 if (base::ContainsKey(observed_keys_, update->key)) { 43 if (base::ContainsKey(observed_keys_, update->key)) {
44 filtered_updates.push_back(mojom::PrefUpdate::New( 44 filtered_updates.push_back(mojom::PrefUpdate::New(
45 update->key, 45 update->key, update->value ? update->value : base::nullopt, 0));
46 update->value ? update->value->CreateDeepCopy() : nullptr, 0));
47 } 46 }
48 } 47 }
49 if (!filtered_updates.empty()) 48 if (!filtered_updates.empty())
50 observer_->OnPrefsChanged(std::move(filtered_updates)); 49 observer_->OnPrefsChanged(std::move(filtered_updates));
51 } 50 }
52 51
53 private: 52 private:
54 // mojom::PersistentPrefStore: 53 // mojom::PersistentPrefStore:
55 void SetValues(std::vector<mojom::PrefUpdatePtr> updates) override { 54 void SetValues(std::vector<mojom::PrefUpdatePtr> updates) override {
56 base::AutoReset<bool> scoped_call_in_progress(&write_in_progress_, true); 55 base::AutoReset<bool> scoped_call_in_progress(&write_in_progress_, true);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 mojom::PersistentPrefStorePtr pref_store_ptr; 104 mojom::PersistentPrefStorePtr pref_store_ptr;
106 mojom::PrefStoreObserverPtr observer; 105 mojom::PrefStoreObserverPtr observer;
107 mojom::PrefStoreObserverRequest observer_request = 106 mojom::PrefStoreObserverRequest observer_request =
108 mojo::MakeRequest(&observer); 107 mojo::MakeRequest(&observer);
109 auto connection = base::MakeUnique<Connection>( 108 auto connection = base::MakeUnique<Connection>(
110 this, mojo::MakeRequest(&pref_store_ptr), std::move(observer), 109 this, mojo::MakeRequest(&pref_store_ptr), std::move(observer),
111 std::move(observed_prefs)); 110 std::move(observed_prefs));
112 auto* connection_ptr = connection.get(); 111 auto* connection_ptr = connection.get();
113 connections_.insert(std::make_pair(connection_ptr, std::move(connection))); 112 connections_.insert(std::make_pair(connection_ptr, std::move(connection)));
114 return mojom::PersistentPrefStoreConnection::New( 113 return mojom::PersistentPrefStoreConnection::New(
115 mojom::PrefStoreConnection::New(std::move(observer_request), 114 mojom::PrefStoreConnection::New(
116 backing_pref_store_->GetValues(), true), 115 std::move(observer_request),
116 std::move(*backing_pref_store_->GetValues()), true),
117 std::move(pref_store_ptr), backing_pref_store_->GetReadError(), 117 std::move(pref_store_ptr), backing_pref_store_->GetReadError(),
118 backing_pref_store_->ReadOnly()); 118 backing_pref_store_->ReadOnly());
119 } 119 }
120 120
121 void PersistentPrefStoreImpl::OnPrefValueChanged(const std::string& key) {} 121 void PersistentPrefStoreImpl::OnPrefValueChanged(const std::string& key) {}
122 122
123 void PersistentPrefStoreImpl::OnInitializationCompleted(bool succeeded) { 123 void PersistentPrefStoreImpl::OnInitializationCompleted(bool succeeded) {
124 DCHECK(initializing_); 124 DCHECK(initializing_);
125 backing_pref_store_->RemoveObserver(this); 125 backing_pref_store_->RemoveObserver(this);
126 initializing_ = false; 126 initializing_ = false;
127 std::move(on_initialized_).Run(); 127 std::move(on_initialized_).Run();
128 } 128 }
129 129
130 void PersistentPrefStoreImpl::SetValues( 130 void PersistentPrefStoreImpl::SetValues(
131 std::vector<mojom::PrefUpdatePtr> updates) { 131 std::vector<mojom::PrefUpdatePtr> updates) {
132 for (auto& entry : connections_) 132 for (auto& entry : connections_)
133 entry.first->OnPrefValuesChanged(updates); 133 entry.first->OnPrefValuesChanged(updates);
134 134
135 for (auto& update : updates) { 135 for (auto& update : updates) {
136 if (update->value) { 136 if (update->value) {
137 backing_pref_store_->SetValue(update->key, std::move(update->value), 137 backing_pref_store_->SetValue(
138 update->flags); 138 update->key, update->value->CreateDeepCopy(), update->flags);
139 } else { 139 } else {
140 backing_pref_store_->RemoveValue(update->key, update->flags); 140 backing_pref_store_->RemoveValue(update->key, update->flags);
141 } 141 }
142 } 142 }
143 } 143 }
144 144
145 void PersistentPrefStoreImpl::CommitPendingWrite() { 145 void PersistentPrefStoreImpl::CommitPendingWrite() {
146 backing_pref_store_->CommitPendingWrite(); 146 backing_pref_store_->CommitPendingWrite();
147 } 147 }
148 148
149 void PersistentPrefStoreImpl::SchedulePendingLossyWrites() { 149 void PersistentPrefStoreImpl::SchedulePendingLossyWrites() {
150 backing_pref_store_->SchedulePendingLossyWrites(); 150 backing_pref_store_->SchedulePendingLossyWrites();
151 } 151 }
152 152
153 void PersistentPrefStoreImpl::ClearMutableValues() { 153 void PersistentPrefStoreImpl::ClearMutableValues() {
154 backing_pref_store_->ClearMutableValues(); 154 backing_pref_store_->ClearMutableValues();
155 } 155 }
156 156
157 void PersistentPrefStoreImpl::OnConnectionError(Connection* connection) { 157 void PersistentPrefStoreImpl::OnConnectionError(Connection* connection) {
158 connections_.erase(connection); 158 connections_.erase(connection);
159 } 159 }
160 160
161 } // namespace prefs 161 } // namespace prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698