Adds associated interface support to IPC::Channel
Provides a way of registering associated interface bindings with
an IPC::Channel endpoint and acquiring proxies to remote interfaces
on the other side.
Support for this is exposed by IPC::Channel but only implemented
in IPC::ChannelMojo.
This is part a series of CLs to support Channel-associated interfaces.
BUG=612500
Committed: https://crrev.com/dc88e5075878f16cde23b910d2ce19aa862129e4
Review-Url: https://codereview.chromium.org/2137353002
Cr-Original-Commit-Position: refs/heads/master@{#405316}
Cr-Commit-Position: refs/heads/master@{#405364}
diff --git a/ipc/ipc_channel_mojo.cc b/ipc/ipc_channel_mojo.cc
index 22efa3a..70a12f4 100644
--- a/ipc/ipc_channel_mojo.cc
+++ b/ipc/ipc_channel_mojo.cc
@@ -307,6 +307,14 @@
listener_->OnChannelError();
}
+void ChannelMojo::OnAssociatedInterfaceRequest(
+ const std::string& name,
+ mojo::ScopedInterfaceEndpointHandle handle) {
+ auto iter = associated_interfaces_.find(name);
+ if (iter != associated_interfaces_.end())
+ iter->second.Run(std::move(handle));
+}
+
void ChannelMojo::InitMessageReader(mojom::ChannelAssociatedPtrInfo sender,
mojom::ChannelAssociatedRequest receiver,
base::ProcessId peer_pid) {
@@ -392,6 +400,9 @@
return bootstrap_->GetSelfPID();
}
+Channel::AssociatedInterfaceSupport*
+ChannelMojo::GetAssociatedInterfaceSupport() { return this; }
+
void ChannelMojo::OnMessageReceived(const Message& message) {
TRACE_EVENT2("ipc,toplevel", "ChannelMojo::OnMessageReceived",
"class", IPC_MESSAGE_ID_CLASS(message.type()),
@@ -468,4 +479,23 @@
return MOJO_RESULT_OK;
}
+mojo::AssociatedGroup* ChannelMojo::GetAssociatedGroup() {
+ DCHECK(bootstrap_);
+ return bootstrap_->GetAssociatedGroup();
+}
+
+void ChannelMojo::AddGenericAssociatedInterface(
+ const std::string& name,
+ const GenericAssociatedInterfaceFactory& factory) {
+ auto result = associated_interfaces_.insert({ name, factory });
+ DCHECK(result.second);
+}
+
+void ChannelMojo::GetGenericRemoteAssociatedInterface(
+ const std::string& name,
+ mojo::ScopedInterfaceEndpointHandle handle) {
+ DCHECK(message_reader_);
+ message_reader_->GetRemoteInterface(name, std::move(handle));
+}
+
} // namespace IPC