| Index: ipc/ipc_channel.h
|
| diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h
|
| index 09baf6cf14044ecc32315789b9ee84915bea36b6..1fc9c6c531bbd3d43440be292f169a7b38bc54d6 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>
|
| @@ -93,6 +97,62 @@ class IPC_EXPORT Channel : public Endpoint {
|
| CLOSE_FD_MESSAGE_TYPE = HELLO_MESSAGE_TYPE - 1
|
| };
|
|
|
| + // Helper interface a Channel may implement to expose support for associated
|
| + // Mojo interfaces.
|
| + class IPC_EXPORT AssociatedInterfaceSupport {
|
| + public:
|
| + using GenericAssociatedInterfaceFactory =
|
| + base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>;
|
| +
|
| + virtual ~AssociatedInterfaceSupport() {}
|
| +
|
| + // Accesses the AssociatedGroup used to associate new interface endpoints
|
| + // with this Channel.
|
| + virtual mojo::AssociatedGroup* GetAssociatedGroup() = 0;
|
| +
|
| + // Adds an interface factory to this channel for interface |name|.
|
| + virtual void AddGenericAssociatedInterface(
|
| + const std::string& name,
|
| + const GenericAssociatedInterfaceFactory& factory) = 0;
|
| +
|
| + // Requests an associated interface from the remote endpoint.
|
| + virtual void GetGenericRemoteAssociatedInterface(
|
| + const std::string& name,
|
| + mojo::ScopedInterfaceEndpointHandle handle) = 0;
|
| +
|
| + // Template helper to add an interface factory to this channel.
|
| + 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));
|
| + }
|
| +
|
| + // Template helper to request a remote associated interface.
|
| + template <typename Interface>
|
| + void GetRemoteAssociatedInterface(
|
| + mojo::AssociatedInterfacePtr<Interface>* proxy) {
|
| + mojo::AssociatedInterfaceRequest<Interface> request =
|
| + mojo::GetProxy(proxy, GetAssociatedGroup());
|
| + GetGenericRemoteAssociatedInterface(
|
| + Interface::Name_, request.PassHandle());
|
| + }
|
| +
|
| + 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));
|
| + }
|
| + };
|
| +
|
| // The maximum message size in bytes. Attempting to receive a message of this
|
| // size or bigger results in a channel error.
|
| static const size_t kMaximumMessageSize = 128 * 1024 * 1024;
|
| @@ -181,6 +241,11 @@ class IPC_EXPORT Channel : public Endpoint {
|
| // Get its own process id. This value is told to the peer.
|
| virtual base::ProcessId GetSelfPID() const = 0;
|
|
|
| + // Gets a helper for associating Mojo interfaces with this Channel.
|
| + //
|
| + // NOTE: Not all implementations support this.
|
| + virtual AssociatedInterfaceSupport* GetAssociatedInterfaceSupport();
|
| +
|
| // Overridden from ipc::Sender.
|
| // Send a message over the Channel to the listener on the other end.
|
| //
|
|
|