Index: mojo/public/cpp/bindings/associated_group.h |
diff --git a/mojo/public/cpp/bindings/associated_group.h b/mojo/public/cpp/bindings/associated_group.h |
index b1c692acd2393cb4052cf33747863122078e28dc..d391fc1b755562c479a82637bd04a69d8dd156b1 100644 |
--- a/mojo/public/cpp/bindings/associated_group.h |
+++ b/mojo/public/cpp/bindings/associated_group.h |
@@ -11,6 +11,7 @@ |
#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
#include "mojo/public/cpp/bindings/associated_interface_request.h" |
#include "mojo/public/cpp/bindings/bindings_export.h" |
+#include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
namespace mojo { |
@@ -86,6 +87,33 @@ class MOJO_CPP_BINDINGS_EXPORT AssociatedGroup { |
scoped_refptr<AssociatedGroupController> controller_; |
}; |
+// Creates an associated interface proxy in its own AssociatedGroup. |
+template <typename Interface> |
+AssociatedInterfaceRequest<Interface> GetProxyForTesting( |
yzshen1
2016/11/15 17:39:50
Does it make sense to:
- move this function to ass
Reilly Grant (use Gerrit)
2016/11/15 17:43:11
I tried putting it in associated_interface_ptr_inf
yzshen1
2016/11/15 17:59:35
I meant associated_interface_ptr.h (instead of ass
|
+ AssociatedInterfacePtrInfo<Interface>* ptr_info, |
+ scoped_refptr<base::SingleThreadTaskRunner> runner = |
+ base::ThreadTaskRunnerHandle::Get()) { |
+ MessagePipe pipe; |
+ using internal::MultiplexRouter; |
+ scoped_refptr<MultiplexRouter> router0 = new MultiplexRouter( |
+ std::move(pipe.handle0), MultiplexRouter::MULTI_INTERFACE, true, runner); |
+ scoped_refptr<MultiplexRouter> router1 = new MultiplexRouter( |
+ std::move(pipe.handle1), MultiplexRouter::MULTI_INTERFACE, false, runner); |
+ |
+ AssociatedInterfaceRequest<Interface> request; |
+ router1->CreateAssociatedGroup()->CreateAssociatedInterface( |
+ AssociatedGroup::WILL_PASS_PTR, ptr_info, &request); |
+ |
+ // Emulate passing |ptr_info| across a pipe. |
+ ScopedInterfaceEndpointHandle handle = ptr_info->PassHandle(); |
+ CHECK(!handle.is_local()); |
+ *ptr_info = AssociatedInterfacePtrInfo<Interface>( |
+ router0->CreateLocalEndpointHandle(handle.release()), |
+ ptr_info->version()); |
+ |
+ return request; |
+} |
+ |
} // namespace mojo |
#endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ |