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

Side by Side Diff: chrome/browser/prefs/active_profile_pref_service.cc

Issue 2795883002: Eliminate OnConnect usage (Closed)
Patch Set: . 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/prefs/active_profile_pref_service.h ('k') | chrome/browser/ui/ash/ash_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/prefs/active_profile_pref_service.h" 5 #include "chrome/browser/prefs/active_profile_pref_service.h"
6 6
7 #include "chrome/browser/profiles/profile_manager.h" 7 #include "chrome/browser/profiles/profile_manager.h"
8 #include "content/public/browser/browser_context.h" 8 #include "content/public/browser/browser_context.h"
9 #include "mojo/public/cpp/bindings/interface_request.h" 9 #include "mojo/public/cpp/bindings/interface_request.h"
10 #include "services/service_manager/public/cpp/connector.h" 10 #include "services/service_manager/public/cpp/connector.h"
11 #include "services/service_manager/public/cpp/interface_registry.h"
12 11
13 ActiveProfilePrefService::ActiveProfilePrefService() = default; 12 ActiveProfilePrefService::ActiveProfilePrefService() {
13 registry_.AddInterface<prefs::mojom::PrefStoreConnector>(this);
14 }
14 15
15 ActiveProfilePrefService::~ActiveProfilePrefService() = default; 16 ActiveProfilePrefService::~ActiveProfilePrefService() = default;
16 17
17 void ActiveProfilePrefService::Connect( 18 void ActiveProfilePrefService::Connect(
18 prefs::mojom::PrefRegistryPtr pref_registry, 19 prefs::mojom::PrefRegistryPtr pref_registry,
19 const std::vector<PrefValueStore::PrefStoreType>& already_connected_types, 20 const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
20 const ConnectCallback& callback) { 21 const ConnectCallback& callback) {
21 auto* connector = content::BrowserContext::GetConnectorFor( 22 auto* connector = content::BrowserContext::GetConnectorFor(
22 ProfileManager::GetActiveUserProfile()); 23 ProfileManager::GetActiveUserProfile());
23 connector->BindInterface(prefs::mojom::kServiceName, &connector_ptr_); 24 connector->BindInterface(prefs::mojom::kServiceName, &connector_ptr_);
24 connector_ptr_.set_connection_error_handler(base::Bind( 25 connector_ptr_.set_connection_error_handler(base::Bind(
25 &ActiveProfilePrefService::OnConnectError, base::Unretained(this))); 26 &ActiveProfilePrefService::OnConnectError, base::Unretained(this)));
26 connector_ptr_->Connect(std::move(pref_registry), already_connected_types, 27 connector_ptr_->Connect(std::move(pref_registry), already_connected_types,
27 callback); 28 callback);
28 } 29 }
29 30
30 void ActiveProfilePrefService::Create( 31 void ActiveProfilePrefService::Create(
31 const service_manager::Identity& remote_identity, 32 const service_manager::Identity& remote_identity,
32 prefs::mojom::PrefStoreConnectorRequest request) { 33 prefs::mojom::PrefStoreConnectorRequest request) {
33 connector_bindings_.AddBinding(this, std::move(request)); 34 connector_bindings_.AddBinding(this, std::move(request));
34 } 35 }
35 36
36 void ActiveProfilePrefService::OnStart() {} 37 void ActiveProfilePrefService::OnStart() {}
37 38
38 bool ActiveProfilePrefService::OnConnect( 39 void ActiveProfilePrefService::OnBindInterface(
39 const service_manager::ServiceInfo& remote_info, 40 const service_manager::ServiceInfo& source_info,
40 service_manager::InterfaceRegistry* registry) { 41 const std::string& interface_name,
42 mojo::ScopedMessagePipeHandle interface_pipe) {
41 // N.B. This check is important as not doing it would allow one user to read 43 // N.B. This check is important as not doing it would allow one user to read
42 // another user's prefs. 44 // another user's prefs.
43 if (remote_info.identity.user_id() != service_manager::mojom::kRootUserID) { 45 // TODO(beng): This should be obsoleted by Service Manager user id routing.
46 if (source_info.identity.user_id() != service_manager::mojom::kRootUserID) {
44 LOG(WARNING) << "Blocked service instance=" 47 LOG(WARNING) << "Blocked service instance="
45 << remote_info.identity.instance() 48 << source_info.identity.instance()
46 << ", name=" << remote_info.identity.name() 49 << ", name=" << source_info.identity.name()
47 << ", user_id=" << remote_info.identity.user_id() 50 << ", user_id=" << source_info.identity.user_id()
48 << " from connecting to the active profile's pref service."; 51 << " from connecting to the active profile's pref service.";
49 return false; 52 return;
50 } 53 }
51 registry->AddInterface<prefs::mojom::PrefStoreConnector>(this); 54 registry_.BindInterface(source_info.identity, interface_name,
52 return true; 55 std::move(interface_pipe));
53 } 56 }
54 57
55 void ActiveProfilePrefService::OnConnectError() { 58 void ActiveProfilePrefService::OnConnectError() {
56 connector_bindings_.CloseAllBindings(); 59 connector_bindings_.CloseAllBindings();
57 } 60 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/active_profile_pref_service.h ('k') | chrome/browser/ui/ash/ash_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698