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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // Creates an associated interface. The output |ptr| should be used locally | 205 // Creates an associated interface. The output |ptr| should be used locally |
206 // while the returned request should be passed through the message pipe endpoint | 206 // while the returned request should be passed through the message pipe endpoint |
207 // referred to by |associated_group| to setup the corresponding asssociated | 207 // referred to by |associated_group| to setup the corresponding asssociated |
208 // interface implementation at the remote side. | 208 // interface implementation at the remote side. |
209 // | 209 // |
210 // NOTE: |ptr| should NOT be used to make calls before the request is sent. | 210 // NOTE: |ptr| should NOT be used to make calls before the request is sent. |
211 // Violating that will cause the message pipe to be closed. On the other hand, | 211 // Violating that will cause the message pipe to be closed. On the other hand, |
212 // as soon as the request is sent, |ptr| is usable. There is no need to wait | 212 // as soon as the request is sent, |ptr| is usable. There is no need to wait |
213 // until the request is bound to an implementation at the remote side. | 213 // until the request is bound to an implementation at the remote side. |
214 template <typename Interface> | 214 template <typename Interface> |
215 AssociatedInterfaceRequest<Interface> GetProxy( | 215 AssociatedInterfaceRequest<Interface> MakeRequest( |
216 AssociatedInterfacePtr<Interface>* ptr, | 216 AssociatedInterfacePtr<Interface>* ptr, |
217 AssociatedGroup* group, | 217 AssociatedGroup* group, |
218 scoped_refptr<base::SingleThreadTaskRunner> runner = | 218 scoped_refptr<base::SingleThreadTaskRunner> runner = |
219 base::ThreadTaskRunnerHandle::Get()) { | 219 base::ThreadTaskRunnerHandle::Get()) { |
220 AssociatedInterfaceRequest<Interface> request; | 220 AssociatedInterfaceRequest<Interface> request; |
221 AssociatedInterfacePtrInfo<Interface> ptr_info; | 221 AssociatedInterfacePtrInfo<Interface> ptr_info; |
222 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, | 222 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, |
223 &ptr_info, &request); | 223 &ptr_info, &request); |
224 | 224 |
225 ptr->Bind(std::move(ptr_info), std::move(runner)); | 225 ptr->Bind(std::move(ptr_info), std::move(runner)); |
226 return request; | 226 return request; |
227 } | 227 } |
228 | 228 |
229 // Creates an associated interface proxy in its own AssociatedGroup. | 229 // Creates an associated interface proxy in its own AssociatedGroup. |
230 template <typename Interface> | 230 template <typename Interface> |
231 AssociatedInterfaceRequest<Interface> GetProxyForTesting( | 231 AssociatedInterfaceRequest<Interface> MakeRequestForTesting( |
232 AssociatedInterfacePtr<Interface>* ptr, | 232 AssociatedInterfacePtr<Interface>* ptr, |
233 scoped_refptr<base::SingleThreadTaskRunner> runner = | 233 scoped_refptr<base::SingleThreadTaskRunner> runner = |
234 base::ThreadTaskRunnerHandle::Get()) { | 234 base::ThreadTaskRunnerHandle::Get()) { |
235 MessagePipe pipe; | 235 MessagePipe pipe; |
236 using internal::MultiplexRouter; | 236 using internal::MultiplexRouter; |
237 scoped_refptr<MultiplexRouter> router0 = new MultiplexRouter( | 237 scoped_refptr<MultiplexRouter> router0 = new MultiplexRouter( |
238 std::move(pipe.handle0), MultiplexRouter::MULTI_INTERFACE, true, runner); | 238 std::move(pipe.handle0), MultiplexRouter::MULTI_INTERFACE, true, runner); |
239 scoped_refptr<MultiplexRouter> router1 = new MultiplexRouter( | 239 scoped_refptr<MultiplexRouter> router1 = new MultiplexRouter( |
240 std::move(pipe.handle1), MultiplexRouter::MULTI_INTERFACE, false, runner); | 240 std::move(pipe.handle1), MultiplexRouter::MULTI_INTERFACE, false, runner); |
241 | 241 |
(...skipping 15 matching lines...) Expand all Loading... |
257 | 257 |
258 // Creates an associated interface proxy which casts its messages into the void. | 258 // Creates an associated interface proxy which casts its messages into the void. |
259 template <typename Interface> | 259 template <typename Interface> |
260 void GetDummyProxyForTesting(AssociatedInterfacePtr<Interface>* proxy) { | 260 void GetDummyProxyForTesting(AssociatedInterfacePtr<Interface>* proxy) { |
261 MessagePipe pipe; | 261 MessagePipe pipe; |
262 scoped_refptr<internal::MultiplexRouter> router = | 262 scoped_refptr<internal::MultiplexRouter> router = |
263 new internal::MultiplexRouter(std::move(pipe.handle0), | 263 new internal::MultiplexRouter(std::move(pipe.handle0), |
264 internal::MultiplexRouter::MULTI_INTERFACE, | 264 internal::MultiplexRouter::MULTI_INTERFACE, |
265 false, base::ThreadTaskRunnerHandle::Get()); | 265 false, base::ThreadTaskRunnerHandle::Get()); |
266 std::unique_ptr<AssociatedGroup> group = router->CreateAssociatedGroup(); | 266 std::unique_ptr<AssociatedGroup> group = router->CreateAssociatedGroup(); |
267 GetProxy(proxy, group.get()); | 267 MakeRequest(proxy, group.get()); |
268 } | 268 } |
269 | 269 |
270 } // namespace mojo | 270 } // namespace mojo |
271 | 271 |
272 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ | 272 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
OLD | NEW |