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

Side by Side Diff: services/service_manager/public/cpp/lib/connector_impl.cc

Issue 2775483003: Use public Service Manager Connector API in Blink (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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/service_manager/public/cpp/lib/connector_impl.h" 5 #include "services/service_manager/public/cpp/lib/connector_impl.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "services/service_manager/public/cpp/identity.h" 8 #include "services/service_manager/public/cpp/identity.h"
9 #include "services/service_manager/public/cpp/lib/connection_impl.h" 9 #include "services/service_manager/public/cpp/lib/connection_impl.h"
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return std::move(connection); 69 return std::move(connection);
70 } 70 }
71 71
72 void ConnectorImpl::BindInterface( 72 void ConnectorImpl::BindInterface(
73 const Identity& target, 73 const Identity& target,
74 const std::string& interface_name, 74 const std::string& interface_name,
75 mojo::ScopedMessagePipeHandle interface_pipe) { 75 mojo::ScopedMessagePipeHandle interface_pipe) {
76 if (!BindConnectorIfNecessary()) 76 if (!BindConnectorIfNecessary())
77 return; 77 return;
78 78
79 if (!local_binder_overrides_.empty() && 79 auto service_overrides_iter = local_binder_overrides_.find(target.name());
80 local_binder_overrides_.count(interface_name)) { 80 if (service_overrides_iter != local_binder_overrides_.end()) {
81 local_binder_overrides_[interface_name].Run(std::move(interface_pipe)); 81 auto override_iter = service_overrides_iter->second.find(interface_name);
82 return; 82 if (override_iter != service_overrides_iter->second.end()) {
83 override_iter->second.Run(std::move(interface_pipe));
84 return;
85 }
83 } 86 }
84 87
85 connector_->BindInterface(target, interface_name, std::move(interface_pipe), 88 connector_->BindInterface(target, interface_name, std::move(interface_pipe),
86 base::Bind(&EmptyBindCallback)); 89 base::Bind(&EmptyBindCallback));
87 } 90 }
88 91
89 std::unique_ptr<Connector> ConnectorImpl::Clone() { 92 std::unique_ptr<Connector> ConnectorImpl::Clone() {
90 if (!BindConnectorIfNecessary()) 93 if (!BindConnectorIfNecessary())
91 return nullptr; 94 return nullptr;
92 95
93 mojom::ConnectorPtr connector; 96 mojom::ConnectorPtr connector;
94 mojom::ConnectorRequest request(&connector); 97 mojom::ConnectorRequest request(&connector);
95 connector_->Clone(std::move(request)); 98 connector_->Clone(std::move(request));
96 return base::MakeUnique<ConnectorImpl>(connector.PassInterface()); 99 return base::MakeUnique<ConnectorImpl>(connector.PassInterface());
97 } 100 }
98 101
99 void ConnectorImpl::BindConnectorRequest(mojom::ConnectorRequest request) { 102 void ConnectorImpl::BindConnectorRequest(mojom::ConnectorRequest request) {
100 if (!BindConnectorIfNecessary()) 103 if (!BindConnectorIfNecessary())
101 return; 104 return;
102 connector_->Clone(std::move(request)); 105 connector_->Clone(std::move(request));
103 } 106 }
104 107
105 base::WeakPtr<Connector> ConnectorImpl::GetWeakPtr() { 108 base::WeakPtr<Connector> ConnectorImpl::GetWeakPtr() {
106 return weak_factory_.GetWeakPtr(); 109 return weak_factory_.GetWeakPtr();
107 } 110 }
108 111
109 void ConnectorImpl::OverrideBinderForTesting(const std::string& interface_name, 112 void ConnectorImpl::OverrideBinderForTesting(const std::string& service_name,
113 const std::string& interface_name,
110 const TestApi::Binder& binder) { 114 const TestApi::Binder& binder) {
111 local_binder_overrides_[interface_name] = binder; 115 local_binder_overrides_[service_name][interface_name] = binder;
112 } 116 }
113 117
114 void ConnectorImpl::ClearBinderOverrides() { 118 void ConnectorImpl::ClearBinderOverrides() {
115 local_binder_overrides_.clear(); 119 local_binder_overrides_.clear();
116 } 120 }
117 121
118 bool ConnectorImpl::BindConnectorIfNecessary() { 122 bool ConnectorImpl::BindConnectorIfNecessary() {
119 // Bind this object to the current thread the first time it is used to 123 // Bind this object to the current thread the first time it is used to
120 // connect. 124 // connect.
121 if (!connector_.is_bound()) { 125 if (!connector_.is_bound()) {
(...skipping 16 matching lines...) Expand all
138 return true; 142 return true;
139 } 143 }
140 144
141 std::unique_ptr<Connector> Connector::Create(mojom::ConnectorRequest* request) { 145 std::unique_ptr<Connector> Connector::Create(mojom::ConnectorRequest* request) {
142 mojom::ConnectorPtr proxy; 146 mojom::ConnectorPtr proxy;
143 *request = mojo::MakeRequest(&proxy); 147 *request = mojo::MakeRequest(&proxy);
144 return base::MakeUnique<ConnectorImpl>(proxy.PassInterface()); 148 return base::MakeUnique<ConnectorImpl>(proxy.PassInterface());
145 } 149 }
146 150
147 } // namespace service_manager 151 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/lib/connector_impl.h ('k') | third_party/WebKit/Source/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698