From 506f92fa27652f8e9cd5be3ea75a408f0890e975 Mon Sep 17 00:00:00 2001 From: rockot Date: Tue, 22 Mar 2016 18:32:18 -0700 Subject: Make ChannelMojo Send thread-safe Changes ChannelMojo to write outgoing Receive requests directly to the pipe rather than using its AssociatedInterfacePtr. The associated interface ID is still included in each outgoing message. This lets us mark ChannelMojo::Send as thread-safe, avoiding a thread-hop when sending IPCs through IPC::ChannelProxy. BUG=595082 Review URL: https://codereview.chromium.org/1825543002 Cr-Commit-Position: refs/heads/master@{#382762} --- mojo/public/cpp/bindings/associated_interface_ptr.h | 3 +++ mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h | 6 ++++++ mojo/public/cpp/bindings/lib/interface_endpoint_client.cc | 5 +++++ mojo/public/cpp/bindings/lib/interface_endpoint_client.h | 1 + 4 files changed, 15 insertions(+) (limited to 'mojo') diff --git a/mojo/public/cpp/bindings/associated_interface_ptr.h b/mojo/public/cpp/bindings/associated_interface_ptr.h index d3a848a..48caad6 100644 --- a/mojo/public/cpp/bindings/associated_interface_ptr.h +++ b/mojo/public/cpp/bindings/associated_interface_ptr.h @@ -79,6 +79,9 @@ class AssociatedInterfacePtr { // Returns the version number of the interface that the remote side supports. uint32_t version() const { return internal_state_.version(); } + // Returns the internal interface ID of this associated interface. + uint32_t interface_id() const { return internal_state_.interface_id(); } + // Queries the max version that the remote side supports. On completion, the // result will be returned as the input of |callback|. The version number of // this object will also be updated. diff --git a/mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h b/mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h index f792884..1b9e35c 100644 --- a/mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h +++ b/mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h @@ -19,6 +19,7 @@ #include "mojo/public/cpp/bindings/lib/interface_id.h" #include "mojo/public/cpp/bindings/lib/multiplex_router.h" #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" +#include "mojo/public/cpp/system/message_pipe.h" namespace mojo { namespace internal { @@ -40,6 +41,11 @@ class AssociatedInterfacePtrState { uint32_t version() const { return version_; } + uint32_t interface_id() const { + DCHECK(is_bound()); + return endpoint_client_->interface_id(); + } + void QueryVersion(const Callback& callback) { // It is safe to capture |this| because the callback won't be run after this // object goes away. diff --git a/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc b/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc index 58bc885..8094ad0 100644 --- a/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc +++ b/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc @@ -149,6 +149,11 @@ AssociatedGroup* InterfaceEndpointClient::associated_group() { return associated_group_.get(); } +uint32_t InterfaceEndpointClient::interface_id() const { + DCHECK(thread_checker_.CalledOnValidThread()); + return handle_.id(); +} + ScopedInterfaceEndpointHandle InterfaceEndpointClient::PassHandle() { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(!has_pending_responders()); diff --git a/mojo/public/cpp/bindings/lib/interface_endpoint_client.h b/mojo/public/cpp/bindings/lib/interface_endpoint_client.h index 12ecbcc..548ca38 100644 --- a/mojo/public/cpp/bindings/lib/interface_endpoint_client.h +++ b/mojo/public/cpp/bindings/lib/interface_endpoint_client.h @@ -60,6 +60,7 @@ class InterfaceEndpointClient : public MessageReceiverWithResponder { MultiplexRouter* router() const { return handle_.router(); } AssociatedGroup* associated_group(); + uint32_t interface_id() const; // After this call the object is in an invalid state and shouldn't be reused. ScopedInterfaceEndpointHandle PassHandle(); -- cgit v1.1