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

Unified Diff: chrome/browser/prefs/active_profile_pref_service.cc

Issue 2772673002: mash: switch to the new pref service (Closed)
Patch Set: Remove no longer needed tests 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/active_profile_pref_service.cc
diff --git a/chrome/browser/prefs/active_profile_pref_service.cc b/chrome/browser/prefs/active_profile_pref_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cd704d2593796a0cc14150dd75bc507fe2b32cd0
--- /dev/null
+++ b/chrome/browser/prefs/active_profile_pref_service.cc
@@ -0,0 +1,58 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/prefs/active_profile_pref_service.h"
+
+#include "chrome/browser/profiles/profile_manager.h"
+#include "content/public/browser/browser_context.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+#include "services/service_manager/public/cpp/connector.h"
+#include "services/service_manager/public/cpp/interface_registry.h"
+
+namespace prefs {
+
+ActiveProfilePrefService::ActiveProfilePrefService() = default;
+
+ActiveProfilePrefService::~ActiveProfilePrefService() = default;
+
+void ActiveProfilePrefService::Connect(mojom::PrefRegistryPtr pref_registry,
+ const ConnectCallback& callback) {
+ auto* connector = content::BrowserContext::GetConnectorFor(
+ ProfileManager::GetActiveUserProfile());
+ connector->BindInterface(mojom::kPrefStoreServiceName, &connector_ptr_);
+ connector_ptr_.set_connection_error_handler(base::Bind(
+ &ActiveProfilePrefService::OnConnectError, base::Unretained(this)));
jonross 2017/03/27 14:26:38 Shutdown can lead to the deletion of ActiveProfile
tibell 2017/03/28 00:34:31 sammc@ who is wiser in the world of Mojo than me g
jonross 2017/03/28 13:57:26 Acknowledged.
+ connector_ptr_->Connect(std::move(pref_registry), callback);
+}
+
+void ActiveProfilePrefService::Create(
+ const service_manager::Identity& remote_identity,
+ prefs::mojom::PrefStoreConnectorRequest request) {
+ connector_bindings_.AddBinding(this, std::move(request));
+}
+
+void ActiveProfilePrefService::OnStart() {}
+
+bool ActiveProfilePrefService::OnConnect(
+ const service_manager::ServiceInfo& remote_info,
+ service_manager::InterfaceRegistry* registry) {
+ // N.B. This check is important as not doing it would allow one user to read
+ // another user's prefs.
+ if (remote_info.identity.user_id() != service_manager::mojom::kRootUserID) {
+ LOG(WARNING) << "Blocked service instance="
+ << remote_info.identity.instance()
+ << ", name=" << remote_info.identity.name()
+ << ", user_id=" << remote_info.identity.user_id()
+ << " from connecting to the active profile's pref service.";
+ return false;
+ }
+ registry->AddInterface<mojom::PrefStoreConnector>(this);
+ return true;
+}
+
+void ActiveProfilePrefService::OnConnectError() {
+ connector_bindings_.CloseAllBindings();
+}
+
+} // namespace prefs

Powered by Google App Engine
This is Rietveld 408576698