Chromium Code Reviews| Index: services/preferences/pref_store_manager_impl.cc |
| diff --git a/services/preferences/pref_store_manager_impl.cc b/services/preferences/pref_store_manager_impl.cc |
| index 8c428ee7f474c527fdc8e20e4e71be2a801ab38a..ca0ea378f1f3845afeb9f13a15800bb216c42877 100644 |
| --- a/services/preferences/pref_store_manager_impl.cc |
| +++ b/services/preferences/pref_store_manager_impl.cc |
| @@ -4,6 +4,7 @@ |
| #include "services/preferences/pref_store_manager_impl.h" |
| +#include <algorithm> |
| #include <utility> |
| #include "base/memory/ref_counted.h" |
| @@ -20,8 +21,8 @@ namespace prefs { |
| namespace { |
| using ConnectCallback = mojom::PrefStoreConnector::ConnectCallback; |
| -using PrefStorePtrs = |
| - std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>; |
| +using PrefStorePtrs = std::unordered_map<PrefValueStore::PrefStoreType, |
| + const mojom::PrefStorePtr&>; |
|
Sam McNally
2017/04/03 10:09:31
mojom::PrefStore*
tibell
2017/04/04 04:05:59
Done.
|
| // Used to make sure all pref stores have been registered before replying to any |
| // Connect calls. |
| @@ -119,6 +120,19 @@ PrefStoreManagerImpl::PrefStoreManagerImpl( |
| PrefStoreManagerImpl::~PrefStoreManagerImpl() = default; |
| +PrefStoreManagerImpl::PendingConnect::PendingConnect( |
| + mojom::PrefRegistryPtr pref_registry_in, |
| + std::vector<PrefValueStore::PrefStoreType> already_connected_types_in, |
| + const ConnectCallback& callback_in) |
| + : pref_registry(std::move(pref_registry_in)), |
| + already_connected_types(std::move(already_connected_types_in)), |
| + callback(callback_in) {} |
| + |
| +PrefStoreManagerImpl::PendingConnect::PendingConnect(PendingConnect&& other) = |
| + default; |
| + |
| +PrefStoreManagerImpl::PendingConnect::~PendingConnect() = default; |
| + |
| void PrefStoreManagerImpl::Register(PrefValueStore::PrefStoreType type, |
| mojom::PrefStorePtr pref_store_ptr) { |
| if (expected_pref_stores_.count(type) == 0) { |
| @@ -139,13 +153,15 @@ void PrefStoreManagerImpl::Register(PrefValueStore::PrefStoreType type, |
| } |
| } |
| -void PrefStoreManagerImpl::Connect(mojom::PrefRegistryPtr pref_registry, |
| - const ConnectCallback& callback) { |
| +void PrefStoreManagerImpl::Connect( |
| + mojom::PrefRegistryPtr pref_registry, |
| + const std::vector<PrefValueStore::PrefStoreType>& already_connected_types, |
| + const ConnectCallback& callback) { |
| if (AllConnected()) { |
| - ConnectImpl(std::move(pref_registry), callback); |
| + ConnectImpl(std::move(pref_registry), already_connected_types, callback); |
| } else { |
| - pending_connects_.push_back( |
| - std::make_pair(callback, std::move(pref_registry))); |
| + pending_connects_.emplace_back(std::move(pref_registry), |
| + already_connected_types, callback); |
| } |
| } |
| @@ -211,12 +227,15 @@ bool PrefStoreManagerImpl::AllConnected() const { |
| void PrefStoreManagerImpl::ProcessPendingConnects() { |
| for (auto& connect : pending_connects_) |
| - ConnectImpl(std::move(connect.second), connect.first); |
| + ConnectImpl(std::move(connect.pref_registry), |
| + connect.already_connected_types, connect.callback); |
| pending_connects_.clear(); |
| } |
| -void PrefStoreManagerImpl::ConnectImpl(mojom::PrefRegistryPtr pref_registry, |
| - const ConnectCallback& callback) { |
| +void PrefStoreManagerImpl::ConnectImpl( |
| + mojom::PrefRegistryPtr pref_registry, |
| + const std::vector<PrefValueStore::PrefStoreType>& already_connected_types, |
| + const ConnectCallback& callback) { |
| std::vector<std::string> observed_prefs; |
| for (auto& registration : pref_registry->registrations) { |
| observed_prefs.push_back(registration.first); |
| @@ -230,8 +249,18 @@ void PrefStoreManagerImpl::ConnectImpl(mojom::PrefRegistryPtr pref_registry, |
| else |
| defaults_->SetDefaultValue(key, std::move(default_value)); |
| } |
| + |
| + // Only connect to pref stores the client isn't already connected to. |
| + PrefStorePtrs ptrs; |
| + for (const auto& entry : pref_store_ptrs_) { |
| + if (std::find(already_connected_types.begin(), |
| + already_connected_types.end(), |
| + entry.first) == already_connected_types.end()) { |
| + ptrs.insert(entry); |
| + } |
| + } |
| ConnectionBarrier::Create( |
| - pref_store_ptrs_, |
| + ptrs, |
| persistent_pref_store_->CreateConnection( |
| PersistentPrefStoreImpl::ObservedPrefs(observed_prefs.begin(), |
| observed_prefs.end())), |