Chromium Code Reviews| Index: ipc/ipc_channel.h |
| diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h |
| index 09baf6cf14044ecc32315789b9ee84915bea36b6..1c834014630fcebe2863c6d9f9f271f776defa18 100644 |
| --- a/ipc/ipc_channel.h |
| +++ b/ipc/ipc_channel.h |
| @@ -18,6 +18,10 @@ |
| #include "ipc/ipc_channel_handle.h" |
| #include "ipc/ipc_endpoint.h" |
| #include "ipc/ipc_message.h" |
| +#include "mojo/public/cpp/bindings/associated_group.h" |
| +#include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
| +#include "mojo/public/cpp/bindings/associated_interface_request.h" |
| +#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| #if defined(OS_POSIX) |
| #include <sys/types.h> |
| @@ -181,6 +185,49 @@ class IPC_EXPORT Channel : public Endpoint { |
| // Get its own process id. This value is told to the peer. |
| virtual base::ProcessId GetSelfPID() const = 0; |
|
yzshen1
2016/07/13 17:38:42
It seems cleaner to me to group associated interfa
|
| + // Accesses the AssociatedGroup used to associate new interface endpoints with |
| + // this Channel. |
| + // |
| + // NOTE: Not all implementations support this. |
| + virtual mojo::AssociatedGroup* GetAssociatedGroup(); |
| + |
| + // Adds an interface factory to this channel for interface |name|. |
| + // |
| + // NOTE: Not all implementations support this. |
| + using GenericAssociatedInterfaceFactory = |
| + base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; |
| + virtual void AddGenericAssociatedInterface( |
| + const std::string& name, |
| + const GenericAssociatedInterfaceFactory& factory); |
| + |
| + template <typename Interface> |
| + using AssociatedInterfaceFactory = |
| + base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>; |
| + |
| + template <typename Interface> |
| + void AddAssociatedInterface( |
| + const AssociatedInterfaceFactory<Interface>& factory) { |
| + AddGenericAssociatedInterface( |
| + Interface::Name_, |
| + base::Bind(&BindAssociatedInterfaceRequest<Interface>, factory)); |
| + } |
| + |
| + // Requests an associated interface from the remote endpoint. |
| + // |
| + // NOTE: Not all implementations support this. |
| + virtual void GetGenericRemoteAssociatedInterface( |
| + const std::string& name, |
| + mojo::ScopedInterfaceEndpointHandle handle); |
| + |
| + // Acquires an associated interface proxied to the remote endpoint. |
| + template <typename Interface> |
| + void GetRemoteAssociatedInterface( |
| + mojo::AssociatedInterfacePtr<Interface>* proxy) { |
| + mojo::AssociatedInterfaceRequest<Interface> request = |
| + mojo::GetProxy(proxy, GetAssociatedGroup()); |
| + GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); |
| + } |
| + |
| // Overridden from ipc::Sender. |
| // Send a message over the Channel to the listener on the other end. |
| // |
| @@ -279,6 +326,15 @@ class IPC_EXPORT Channel : public Endpoint { |
| void WillConnect(); |
| private: |
| + template <typename Interface> |
| + static void BindAssociatedInterfaceRequest( |
| + const AssociatedInterfaceFactory<Interface>& factory, |
| + mojo::ScopedInterfaceEndpointHandle handle) { |
| + mojo::AssociatedInterfaceRequest<Interface> request; |
| + request.Bind(std::move(handle)); |
| + factory.Run(std::move(request)); |
| + } |
| + |
| bool did_start_connect_ = false; |
| }; |