OLD | NEW |
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/pref_store_manager_impl.h" | 5 #include "services/preferences/pref_store_manager_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
13 #include "components/prefs/default_pref_store.h" | 13 #include "components/prefs/default_pref_store.h" |
14 #include "components/prefs/pref_value_store.h" | 14 #include "components/prefs/pref_value_store.h" |
15 #include "mojo/public/cpp/bindings/interface_request.h" | 15 #include "mojo/public/cpp/bindings/interface_request.h" |
16 #include "services/preferences/persistent_pref_store_factory.h" | 16 #include "services/preferences/persistent_pref_store_factory.h" |
17 #include "services/preferences/persistent_pref_store_impl.h" | 17 #include "services/preferences/persistent_pref_store_impl.h" |
18 #include "services/preferences/public/cpp/pref_store_impl.h" | 18 #include "services/preferences/public/cpp/pref_store_impl.h" |
19 #include "services/service_manager/public/cpp/interface_registry.h" | 19 #include "services/service_manager/public/cpp/service_info.h" |
20 | 20 |
21 namespace prefs { | 21 namespace prefs { |
22 namespace { | 22 namespace { |
23 | 23 |
24 using ConnectCallback = mojom::PrefStoreConnector::ConnectCallback; | 24 using ConnectCallback = mojom::PrefStoreConnector::ConnectCallback; |
25 using PrefStorePtrs = | 25 using PrefStorePtrs = |
26 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStore*>; | 26 std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStore*>; |
27 | 27 |
28 // Used to make sure all pref stores have been registered before replying to any | 28 // Used to make sure all pref stores have been registered before replying to any |
29 // Connect calls. | 29 // Connect calls. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 mojo::MakeRequest(&pref_store_ptrs_[PrefValueStore::DEFAULT_STORE]))), | 117 mojo::MakeRequest(&pref_store_ptrs_[PrefValueStore::DEFAULT_STORE]))), |
118 worker_pool_(std::move(worker_pool)) { | 118 worker_pool_(std::move(worker_pool)) { |
119 DCHECK( | 119 DCHECK( |
120 base::ContainsValue(expected_pref_stores_, PrefValueStore::USER_STORE) && | 120 base::ContainsValue(expected_pref_stores_, PrefValueStore::USER_STORE) && |
121 base::ContainsValue(expected_pref_stores_, PrefValueStore::DEFAULT_STORE)) | 121 base::ContainsValue(expected_pref_stores_, PrefValueStore::DEFAULT_STORE)) |
122 << "expected_pref_stores must always include PrefValueStore::USER_STORE " | 122 << "expected_pref_stores must always include PrefValueStore::USER_STORE " |
123 "and PrefValueStore::DEFAULT_STORE."; | 123 "and PrefValueStore::DEFAULT_STORE."; |
124 // The user store is not actually connected to in the implementation, but | 124 // The user store is not actually connected to in the implementation, but |
125 // accessed directly. | 125 // accessed directly. |
126 expected_pref_stores_.erase(PrefValueStore::USER_STORE); | 126 expected_pref_stores_.erase(PrefValueStore::USER_STORE); |
| 127 registry_.AddInterface<prefs::mojom::PrefStoreConnector>(this); |
| 128 registry_.AddInterface<prefs::mojom::PrefStoreRegistry>(this); |
| 129 registry_.AddInterface<prefs::mojom::PrefServiceControl>(this); |
127 } | 130 } |
128 | 131 |
129 PrefStoreManagerImpl::~PrefStoreManagerImpl() = default; | 132 PrefStoreManagerImpl::~PrefStoreManagerImpl() = default; |
130 | 133 |
131 struct PrefStoreManagerImpl::PendingConnect { | 134 struct PrefStoreManagerImpl::PendingConnect { |
132 mojom::PrefRegistryPtr pref_registry; | 135 mojom::PrefRegistryPtr pref_registry; |
133 // Pref stores the caller already is connected to (and hence we won't | 136 // Pref stores the caller already is connected to (and hence we won't |
134 // connect to these). | 137 // connect to these). |
135 std::vector<PrefValueStore::PrefStoreType> already_connected_types; | 138 std::vector<PrefValueStore::PrefStoreType> already_connected_types; |
136 ConnectCallback callback; | 139 ConnectCallback callback; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 std::move(configuration), worker_pool_.get(), | 204 std::move(configuration), worker_pool_.get(), |
202 base::Bind(&PrefStoreManagerImpl::OnPersistentPrefStoreReady, | 205 base::Bind(&PrefStoreManagerImpl::OnPersistentPrefStoreReady, |
203 base::Unretained(this))); | 206 base::Unretained(this))); |
204 DCHECK(persistent_pref_store_); | 207 DCHECK(persistent_pref_store_); |
205 if (AllConnected()) | 208 if (AllConnected()) |
206 ProcessPendingConnects(); | 209 ProcessPendingConnects(); |
207 } | 210 } |
208 | 211 |
209 void PrefStoreManagerImpl::OnStart() {} | 212 void PrefStoreManagerImpl::OnStart() {} |
210 | 213 |
211 bool PrefStoreManagerImpl::OnConnect( | 214 void PrefStoreManagerImpl::OnBindInterface( |
212 const service_manager::ServiceInfo& remote_info, | 215 const service_manager::ServiceInfo& source_info, |
213 service_manager::InterfaceRegistry* registry) { | 216 const std::string& interface_name, |
214 registry->AddInterface<prefs::mojom::PrefStoreConnector>(this); | 217 mojo::ScopedMessagePipeHandle interface_pipe) { |
215 registry->AddInterface<prefs::mojom::PrefStoreRegistry>(this); | 218 registry_.BindInterface(source_info.identity, interface_name, |
216 registry->AddInterface<prefs::mojom::PrefServiceControl>(this); | 219 std::move(interface_pipe)); |
217 return true; | |
218 } | 220 } |
219 | 221 |
220 void PrefStoreManagerImpl::OnPrefStoreDisconnect( | 222 void PrefStoreManagerImpl::OnPrefStoreDisconnect( |
221 PrefValueStore::PrefStoreType type) { | 223 PrefValueStore::PrefStoreType type) { |
222 DVLOG(1) << "Deregistering pref store: " << type; | 224 DVLOG(1) << "Deregistering pref store: " << type; |
223 pref_store_ptrs_.erase(type); | 225 pref_store_ptrs_.erase(type); |
224 } | 226 } |
225 | 227 |
226 bool PrefStoreManagerImpl::AllConnected() const { | 228 bool PrefStoreManagerImpl::AllConnected() const { |
227 return pref_store_ptrs_.size() == expected_pref_stores_.size() && | 229 return pref_store_ptrs_.size() == expected_pref_stores_.size() && |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 271 } |
270 | 272 |
271 void PrefStoreManagerImpl::OnPersistentPrefStoreReady() { | 273 void PrefStoreManagerImpl::OnPersistentPrefStoreReady() { |
272 DVLOG(1) << "PersistentPrefStore ready"; | 274 DVLOG(1) << "PersistentPrefStore ready"; |
273 if (AllConnected()) { | 275 if (AllConnected()) { |
274 ProcessPendingConnects(); | 276 ProcessPendingConnects(); |
275 } | 277 } |
276 } | 278 } |
277 | 279 |
278 } // namespace prefs | 280 } // namespace prefs |
OLD | NEW |