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

Unified Diff: services/preferences/pref_store_manager_impl.cc

Issue 2856083002: Pref service: support for incognito prefs (Closed)
Patch Set: Rebase Created 3 years, 7 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 8232baf5d4a8fa7e6e3e868ba7c920c46ce5a200..ea6636fc965b1319539f9e735cd26e5075fc7039 100644
--- a/services/preferences/pref_store_manager_impl.cc
+++ b/services/preferences/pref_store_manager_impl.cc
@@ -15,6 +15,7 @@
#include "mojo/public/cpp/bindings/interface_request.h"
#include "services/preferences/persistent_pref_store_factory.h"
#include "services/preferences/persistent_pref_store_impl.h"
+#include "services/preferences/public/cpp/pref_store_client.h"
#include "services/preferences/public/cpp/pref_store_impl.h"
#include "services/service_manager/public/cpp/bind_source_info.h"
@@ -128,9 +129,13 @@ PrefStoreManagerImpl::PrefStoreManagerImpl(
base::ContainsValue(expected_pref_stores_, PrefValueStore::DEFAULT_STORE))
<< "expected_pref_stores must always include PrefValueStore::USER_STORE "
"and PrefValueStore::DEFAULT_STORE.";
- // The user store is not actually connected to in the implementation, but
- // accessed directly.
+ // The user store is not actually registered or connected to in the
+ // implementation, but accessed directly.
expected_pref_stores_.erase(PrefValueStore::USER_STORE);
+ DVLOG(1) << "Expecting " << expected_pref_stores_.size()
+ << " pref store(s) to register";
+ // This store is done in-process so it's already "registered":
+ DVLOG(1) << "Registering pref store: " << PrefValueStore::DEFAULT_STORE;
registry_.AddInterface<prefs::mojom::PrefStoreConnector>(
base::Bind(&PrefStoreManagerImpl::BindPrefStoreConnectorRequest,
base::Unretained(this)));
@@ -142,7 +147,10 @@ PrefStoreManagerImpl::PrefStoreManagerImpl(
base::Unretained(this)));
}
-PrefStoreManagerImpl::~PrefStoreManagerImpl() = default;
+PrefStoreManagerImpl::~PrefStoreManagerImpl() {
+ // For logging consistency:
+ DVLOG(1) << "Deregistering pref store: " << PrefValueStore::DEFAULT_STORE;
+}
struct PrefStoreManagerImpl::PendingConnect {
mojom::PrefRegistryPtr pref_registry;
@@ -176,6 +184,15 @@ void PrefStoreManagerImpl::Connect(
mojom::PrefRegistryPtr pref_registry,
const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
const ConnectCallback& callback) {
+ DVLOG(1) << "Will connect to "
+ << expected_pref_stores_.size() - already_connected_types.size()
+ << " pref store(s)";
+ if (incognito_connector_ &&
+ !base::ContainsValue(already_connected_types,
+ PrefValueStore::INCOGNITO_STORE)) {
+ incognito_connector_->ConnectToUserPrefStore(
+ mojo::MakeRequest(&pref_store_ptrs_[PrefValueStore::INCOGNITO_STORE]));
+ }
if (AllConnected()) {
ConnectImpl(std::move(pref_registry), already_connected_types, callback);
} else {
@@ -184,6 +201,13 @@ void PrefStoreManagerImpl::Connect(
}
}
+void PrefStoreManagerImpl::ConnectToUserPrefStore(
+ mojom::PrefStoreRequest request) {
+ pending_ro_persistent_pref_store_requests_.push_back(std::move(request));
+ if (AllConnected())
+ ProcessPendingConnects();
+}
+
void PrefStoreManagerImpl::BindPrefStoreConnectorRequest(
const service_manager::BindSourceInfo& source_info,
prefs::mojom::PrefStoreConnectorRequest request) {
@@ -213,6 +237,13 @@ void PrefStoreManagerImpl::Init(
mojom::PersistentPrefStoreConfigurationPtr configuration) {
DCHECK(!persistent_pref_store_);
+ if (configuration->is_incognito_configuration()) {
+ DCHECK(expected_pref_stores_.count(PrefValueStore::INCOGNITO_STORE))
+ << "expected_pref_stores must include PrefValueStore::INCOGNITO_STORE "
+ << "when creating an incognito instance";
+ incognito_connector_ =
+ std::move(configuration->get_incognito_configuration()->connector);
+ }
persistent_pref_store_ = CreatePersistentPrefStore(
std::move(configuration), worker_pool_.get(),
base::Bind(&PrefStoreManagerImpl::OnPersistentPrefStoreReady,
@@ -239,21 +270,28 @@ void PrefStoreManagerImpl::OnPrefStoreDisconnect(
}
bool PrefStoreManagerImpl::AllConnected() const {
+ DCHECK_LE(pref_store_ptrs_.size(), expected_pref_stores_.size());
return pref_store_ptrs_.size() == expected_pref_stores_.size() &&
persistent_pref_store_ && persistent_pref_store_->initialized();
}
void PrefStoreManagerImpl::ProcessPendingConnects() {
+ DCHECK(persistent_pref_store_);
for (auto& connect : pending_connects_)
ConnectImpl(std::move(connect.pref_registry),
connect.already_connected_types, connect.callback);
pending_connects_.clear();
+ ro_persistent_pref_store_bindings_.reset(
+ new mojo::BindingSet<mojom::PrefStore>());
+ for (auto& request : pending_ro_persistent_pref_store_requests_) {
+ ro_persistent_pref_store_bindings_->AddBinding(persistent_pref_store_.get(),
+ std::move(request));
+ }
+ pending_ro_persistent_pref_store_requests_.clear();
}
-void PrefStoreManagerImpl::ConnectImpl(
- mojom::PrefRegistryPtr pref_registry,
- const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
- const ConnectCallback& callback) {
+std::vector<std::string> PrefStoreManagerImpl::RegisterPrefs(
+ mojom::PrefRegistryPtr pref_registry) {
std::vector<std::string> observed_prefs;
for (auto& registration : pref_registry->registrations) {
observed_prefs.push_back(registration.first);
@@ -267,7 +305,15 @@ void PrefStoreManagerImpl::ConnectImpl(
else
defaults_->SetDefaultValue(key, std::move(default_value));
}
+ return observed_prefs;
+}
+void PrefStoreManagerImpl::ConnectImpl(
+ mojom::PrefRegistryPtr pref_registry,
+ const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
+ const ConnectCallback& callback) {
+ std::vector<std::string> observed_prefs =
+ RegisterPrefs(std::move(pref_registry));
// Only connect to pref stores the client isn't already connected to.
PrefStorePtrs ptrs;
for (const auto& entry : pref_store_ptrs_) {
« no previous file with comments | « services/preferences/pref_store_manager_impl.h ('k') | services/preferences/public/cpp/preferences_struct_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698