OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 &handle1); | 225 &handle1); |
226 | 226 |
227 ptr_info->set_handle(std::move(handle0)); | 227 ptr_info->set_handle(std::move(handle0)); |
228 ptr_info->set_version(0); | 228 ptr_info->set_version(0); |
229 | 229 |
230 AssociatedInterfaceRequest<Interface> request; | 230 AssociatedInterfaceRequest<Interface> request; |
231 request.Bind(std::move(handle1)); | 231 request.Bind(std::move(handle1)); |
232 return request; | 232 return request; |
233 } | 233 } |
234 | 234 |
235 // Like |GetProxy|, but the interface is never associated with any other | 235 // Like MakeRequest() above, but it creates a dedicated message pipe. The |
236 // interface. The returned request can be bound directly to the corresponding | 236 // returned request can be bound directly to an implementation, without being |
237 // associated interface implementation, without first passing it through a | 237 // first passed through a message pipe endpoint. |
238 // message pipe endpoint. | |
239 // | 238 // |
240 // This function has two main uses: | 239 // This function has two main uses: |
241 // | 240 // |
242 // * In testing, where the returned request is bound to e.g. a mock and there | 241 // * In testing, where the returned request is bound to e.g. a mock and there |
243 // are no other interfaces involved. | 242 // are no other interfaces involved. |
244 // | 243 // |
245 // * When discarding messages sent on an interface, which can be done by | 244 // * When discarding messages sent on an interface, which can be done by |
246 // discarding the returned request. | 245 // discarding the returned request. |
247 template <typename Interface> | 246 template <typename Interface> |
248 AssociatedInterfaceRequest<Interface> GetIsolatedProxy( | 247 AssociatedInterfaceRequest<Interface> MakeIsolatedRequest( |
249 AssociatedInterfacePtr<Interface>* ptr) { | 248 AssociatedInterfacePtr<Interface>* ptr) { |
250 MessagePipe pipe; | 249 MessagePipe pipe; |
251 scoped_refptr<internal::MultiplexRouter> router0 = | 250 scoped_refptr<internal::MultiplexRouter> router0 = |
252 new internal::MultiplexRouter(std::move(pipe.handle0), | 251 new internal::MultiplexRouter(std::move(pipe.handle0), |
253 internal::MultiplexRouter::MULTI_INTERFACE, | 252 internal::MultiplexRouter::MULTI_INTERFACE, |
254 false, base::ThreadTaskRunnerHandle::Get()); | 253 false, base::ThreadTaskRunnerHandle::Get()); |
255 scoped_refptr<internal::MultiplexRouter> router1 = | 254 scoped_refptr<internal::MultiplexRouter> router1 = |
256 new internal::MultiplexRouter(std::move(pipe.handle1), | 255 new internal::MultiplexRouter(std::move(pipe.handle1), |
257 internal::MultiplexRouter::MULTI_INTERFACE, | 256 internal::MultiplexRouter::MULTI_INTERFACE, |
258 true, base::ThreadTaskRunnerHandle::Get()); | 257 true, base::ThreadTaskRunnerHandle::Get()); |
259 | 258 |
260 ScopedInterfaceEndpointHandle endpoint0, endpoint1; | 259 ScopedInterfaceEndpointHandle endpoint0, endpoint1; |
261 ScopedInterfaceEndpointHandle::CreatePairPendingAssociation(&endpoint0, | 260 ScopedInterfaceEndpointHandle::CreatePairPendingAssociation(&endpoint0, |
262 &endpoint1); | 261 &endpoint1); |
263 InterfaceId id = router1->AssociateInterface(std::move(endpoint0)); | 262 InterfaceId id = router1->AssociateInterface(std::move(endpoint0)); |
264 endpoint0 = router0->CreateLocalEndpointHandle(id); | 263 endpoint0 = router0->CreateLocalEndpointHandle(id); |
265 | 264 |
266 ptr->Bind(AssociatedInterfacePtrInfo<Interface>(std::move(endpoint0), | 265 ptr->Bind(AssociatedInterfacePtrInfo<Interface>(std::move(endpoint0), |
267 Interface::Version_)); | 266 Interface::Version_)); |
268 | 267 |
269 AssociatedInterfaceRequest<Interface> request; | 268 AssociatedInterfaceRequest<Interface> request; |
270 request.Bind(std::move(endpoint1)); | 269 request.Bind(std::move(endpoint1)); |
271 return request; | 270 return request; |
272 } | 271 } |
273 | 272 |
274 // Creates an associated interface proxy in its own AssociatedGroup. | |
275 // TODO(yzshen): Rename GetIsolatedProxy() to MakeIsolatedRequest(), and change | |
276 // all callsites of this function to directly use that. | |
277 template <typename Interface> | |
278 AssociatedInterfaceRequest<Interface> MakeRequestForTesting( | |
279 AssociatedInterfacePtr<Interface>* ptr) { | |
280 return GetIsolatedProxy(ptr); | |
281 } | |
282 | |
283 } // namespace mojo | 273 } // namespace mojo |
284 | 274 |
285 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ | 275 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
OLD | NEW |