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

Unified Diff: services/preferences/pref_store_manager_impl.cc

Issue 2791903003: Pref service: have Mash and Chrome connect to the right pref stores (Closed)
Patch Set: Don't require clients to specify the default store, but allow it 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 side-by-side diff with in-line comments
Download patch
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..73b54f57b5552af9094c69e7856cf6cc527b2ce2 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"
@@ -21,7 +22,7 @@ namespace {
using ConnectCallback = mojom::PrefStoreConnector::ConnectCallback;
using PrefStorePtrs =
- std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStorePtr>;
+ std::unordered_map<PrefValueStore::PrefStoreType, mojom::PrefStore*>;
// Used to make sure all pref stores have been registered before replying to any
// Connect calls.
@@ -114,11 +115,20 @@ PrefStoreManagerImpl::PrefStoreManagerImpl(
defaults_,
mojo::MakeRequest(&pref_store_ptrs_[PrefValueStore::DEFAULT_STORE]))),
worker_pool_(std::move(worker_pool)) {
+ expected_pref_stores_.erase(PrefValueStore::USER_STORE);
expected_pref_stores_.insert(PrefValueStore::DEFAULT_STORE);
}
PrefStoreManagerImpl::~PrefStoreManagerImpl() = default;
+struct PrefStoreManagerImpl::PendingConnect {
+ mojom::PrefRegistryPtr pref_registry;
+ // Pref stores the caller already is connected to (and hence we won't
+ // connect to these).
+ std::vector<PrefValueStore::PrefStoreType> already_connected_types;
+ ConnectCallback callback;
+};
+
void PrefStoreManagerImpl::Register(PrefValueStore::PrefStoreType type,
mojom::PrefStorePtr pref_store_ptr) {
if (expected_pref_stores_.count(type) == 0) {
@@ -139,13 +149,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)));
+ {std::move(pref_registry), already_connected_types, callback});
}
}
@@ -211,12 +223,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 +245,20 @@ 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_) {
+ const bool already_connected =
+ std::find(already_connected_types.begin(),
Bernhard Bauer 2017/04/05 10:04:32 Nit: base::ContainsValue() (from base/stl_util.h)
tibell 2017/04/06 01:05:52 Done.
+ already_connected_types.end(),
+ entry.first) != already_connected_types.end();
+ if (!already_connected) {
+ ptrs.insert(std::make_pair(entry.first, entry.second.get()));
+ }
+ }
ConnectionBarrier::Create(
- pref_store_ptrs_,
+ ptrs,
persistent_pref_store_->CreateConnection(
PersistentPrefStoreImpl::ObservedPrefs(observed_prefs.begin(),
observed_prefs.end())),
« no previous file with comments | « services/preferences/pref_store_manager_impl.h ('k') | services/preferences/public/cpp/persistent_pref_store_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698