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 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
17 #include "mojo/public/cpp/bindings/associated_group.h" | 17 #include "mojo/public/cpp/bindings/associated_group.h" |
18 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 18 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
19 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 19 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
20 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h" | 20 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h" |
| 21 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 22 #include "mojo/public/cpp/system/message_pipe.h" |
21 | 23 |
22 namespace mojo { | 24 namespace mojo { |
23 | 25 |
24 // Represents the client side of an associated interface. It is similar to | 26 // Represents the client side of an associated interface. It is similar to |
25 // InterfacePtr, except that it doesn't own a message pipe handle. | 27 // InterfacePtr, except that it doesn't own a message pipe handle. |
26 template <typename Interface> | 28 template <typename Interface> |
27 class AssociatedInterfacePtr { | 29 class AssociatedInterfacePtr { |
28 public: | 30 public: |
29 // Constructs an unbound AssociatedInterfacePtr. | 31 // Constructs an unbound AssociatedInterfacePtr. |
30 AssociatedInterfacePtr() {} | 32 AssociatedInterfacePtr() {} |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 base::ThreadTaskRunnerHandle::Get()) { | 204 base::ThreadTaskRunnerHandle::Get()) { |
203 AssociatedInterfaceRequest<Interface> request; | 205 AssociatedInterfaceRequest<Interface> request; |
204 AssociatedInterfacePtrInfo<Interface> ptr_info; | 206 AssociatedInterfacePtrInfo<Interface> ptr_info; |
205 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, | 207 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, |
206 &ptr_info, &request); | 208 &ptr_info, &request); |
207 | 209 |
208 ptr->Bind(std::move(ptr_info), std::move(runner)); | 210 ptr->Bind(std::move(ptr_info), std::move(runner)); |
209 return request; | 211 return request; |
210 } | 212 } |
211 | 213 |
| 214 // Creates an associated interface proxy which casts its messages into the void. |
| 215 template <typename Interface> |
| 216 void GetDummyProxyForTesting(AssociatedInterfacePtr<Interface>* proxy) { |
| 217 MessagePipe pipe; |
| 218 scoped_refptr<internal::MultiplexRouter> router = |
| 219 new internal::MultiplexRouter(false, std::move(pipe.handle0), |
| 220 base::ThreadTaskRunnerHandle::Get()); |
| 221 std::unique_ptr<AssociatedGroup> group = router->CreateAssociatedGroup(); |
| 222 GetProxy(proxy, group.get()); |
| 223 } |
| 224 |
212 } // namespace mojo | 225 } // namespace mojo |
213 | 226 |
214 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ | 227 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
OLD | NEW |