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

Side by Side Diff: services/preferences/public/cpp/persistent_pref_store_client.cc

Issue 2777483002: Pref service: Add initial support for pref registration. (Closed)
Patch Set: rebase Created 3 years, 9 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/public/cpp/persistent_pref_store_client.h" 5 #include "services/preferences/public/cpp/persistent_pref_store_client.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/prefs/pref_registry.h"
11 #include "services/preferences/public/cpp/pref_registry_serializer.h"
10 12
11 namespace prefs { 13 namespace prefs {
12 14
13 PersistentPrefStoreClient::PersistentPrefStoreClient( 15 PersistentPrefStoreClient::PersistentPrefStoreClient(
14 mojom::PrefStoreConnectorPtr connector) 16 mojom::PrefStoreConnectorPtr connector,
15 : connector_(std::move(connector)) { 17 scoped_refptr<PrefRegistry> pref_registry)
18 : connector_(std::move(connector)),
19 pref_registry_(std::move(pref_registry)) {
16 DCHECK(connector_); 20 DCHECK(connector_);
17 } 21 }
18 22
19 PersistentPrefStoreClient::PersistentPrefStoreClient( 23 PersistentPrefStoreClient::PersistentPrefStoreClient(
20 mojom::PersistentPrefStoreConnectionPtr connection) { 24 mojom::PersistentPrefStoreConnectionPtr connection) {
21 OnConnect(std::move(connection), 25 OnConnect(std::move(connection),
22 std::unordered_map<PrefValueStore::PrefStoreType, 26 std::unordered_map<PrefValueStore::PrefStoreType,
23 prefs::mojom::PrefStoreConnectionPtr>()); 27 prefs::mojom::PrefStoreConnectionPtr>());
24 } 28 }
25 29
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 PersistentPrefStore::PrefReadError PersistentPrefStoreClient::GetReadError() 75 PersistentPrefStore::PrefReadError PersistentPrefStoreClient::GetReadError()
72 const { 76 const {
73 return read_error_; 77 return read_error_;
74 } 78 }
75 79
76 PersistentPrefStore::PrefReadError PersistentPrefStoreClient::ReadPrefs() { 80 PersistentPrefStore::PrefReadError PersistentPrefStoreClient::ReadPrefs() {
77 mojom::PersistentPrefStoreConnectionPtr connection; 81 mojom::PersistentPrefStoreConnectionPtr connection;
78 std::unordered_map<PrefValueStore::PrefStoreType, 82 std::unordered_map<PrefValueStore::PrefStoreType,
79 prefs::mojom::PrefStoreConnectionPtr> 83 prefs::mojom::PrefStoreConnectionPtr>
80 other_pref_stores; 84 other_pref_stores;
81 if (!connector_->Connect(&connection, &other_pref_stores)) { 85 if (!connector_->Connect(SerializePrefRegistry(*pref_registry_), &connection,
86 &other_pref_stores)) {
82 NOTREACHED(); 87 NOTREACHED();
83 } 88 }
84 89 pref_registry_ = nullptr;
85 OnConnect(std::move(connection), std::move(other_pref_stores)); 90 OnConnect(std::move(connection), std::move(other_pref_stores));
86 return read_error_; 91 return read_error_;
87 } 92 }
88 93
89 void PersistentPrefStoreClient::ReadPrefsAsync( 94 void PersistentPrefStoreClient::ReadPrefsAsync(
90 ReadErrorDelegate* error_delegate) { 95 ReadErrorDelegate* error_delegate) {
91 error_delegate_.reset(error_delegate); 96 error_delegate_.reset(error_delegate);
92 connector_->Connect(base::Bind(&PersistentPrefStoreClient::OnConnect, 97 connector_->Connect(SerializePrefRegistry(*pref_registry_),
98 base::Bind(&PersistentPrefStoreClient::OnConnect,
93 base::Unretained(this))); 99 base::Unretained(this)));
100 pref_registry_ = nullptr;
94 } 101 }
95 102
96 void PersistentPrefStoreClient::CommitPendingWrite() { 103 void PersistentPrefStoreClient::CommitPendingWrite() {
97 DCHECK(pref_store_); 104 DCHECK(pref_store_);
98 pref_store_->CommitPendingWrite(); 105 pref_store_->CommitPendingWrite();
99 } 106 }
100 107
101 void PersistentPrefStoreClient::SchedulePendingLossyWrites() { 108 void PersistentPrefStoreClient::SchedulePendingLossyWrites() {
102 DCHECK(pref_store_); 109 DCHECK(pref_store_);
103 return pref_store_->SchedulePendingLossyWrites(); 110 return pref_store_->SchedulePendingLossyWrites();
(...skipping 26 matching lines...) Expand all
130 137
131 if (connection->pref_store_connection) { 138 if (connection->pref_store_connection) {
132 Init(std::move(connection->pref_store_connection->initial_prefs), true, 139 Init(std::move(connection->pref_store_connection->initial_prefs), true,
133 std::move(connection->pref_store_connection->observer)); 140 std::move(connection->pref_store_connection->observer));
134 } else { 141 } else {
135 Init(nullptr, false, nullptr); 142 Init(nullptr, false, nullptr);
136 } 143 }
137 } 144 }
138 145
139 } // namespace prefs 146 } // namespace prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698