Index: ipc/ipc_channel_proxy.h |
diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h |
index bda83bb18854299b58c977b6a5a349e76cf4e15b..cde6a89620b38fb695e1a3de40ba0c800eca39d5 100644 |
--- a/ipc/ipc_channel_proxy.h |
+++ b/ipc/ipc_channel_proxy.h |
@@ -22,8 +22,10 @@ |
#include "ipc/ipc_listener.h" |
#include "ipc/ipc_sender.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" |
+#include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" |
namespace base { |
class SingleThreadTaskRunner; |
@@ -209,17 +211,22 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { |
} |
#endif |
+ // Creates a ThreadSafeAssociatedInterfacePtr for |Interface|. This object |
+ // may be used to send messages on the interface from any thread and those |
+ // messages will remain ordered with respect to other messages sent on the |
+ // same thread over other ThreadSafeAssociatedInterfacePtrs associated with |
+ // the same Channel. |
template <typename Interface> |
- using AssociatedInterfaceRetrievedCallback = |
- base::Callback<void(mojo::AssociatedInterfacePtr<Interface>)>; |
- // Creates an AssociatedInterfacePtr to |Interface| on the IO thread and |
- // passes it to |callback|, also invoked on the IO thread. |
- template <typename Interface> |
- void RetrieveAssociatedInterfaceOnIOThread( |
- const AssociatedInterfaceRetrievedCallback<Interface>& callback) { |
- context_->ipc_task_runner()->PostTask( |
- FROM_HERE, base::Bind(&Context::RetrieveAssociatedInterface<Interface>, |
- context_, callback)); |
+ void GetThreadSafeRemoteAssociatedInterface( |
+ scoped_refptr<mojo::ThreadSafeAssociatedInterfacePtr<Interface>>* |
+ out_ptr) { |
+ mojo::AssociatedInterfacePtrInfo<Interface> ptr_info; |
+ mojo::AssociatedInterfaceRequest<Interface> request; |
+ GetAssociatedGroup()->CreateAssociatedInterface( |
+ mojo::AssociatedGroup::WILL_PASS_REQUEST, &ptr_info, &request); |
+ GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); |
+ *out_ptr = mojo::ThreadSafeAssociatedInterfacePtr<Interface>::Create( |
+ std::move(ptr_info), ipc_task_runner()); |
} |
base::SingleThreadTaskRunner* ipc_task_runner() const { |
@@ -251,11 +258,6 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { |
// Sends |message| from appropriate thread. |
void Send(Message* message); |
- // Requests a remote associated interface on the IPC thread. |
- void GetRemoteAssociatedInterface( |
- const std::string& name, |
- mojo::ScopedInterfaceEndpointHandle handle); |
- |
protected: |
friend class base::RefCountedThreadSafe<Context>; |
~Context() override; |
@@ -299,14 +301,6 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { |
void OnSendMessage(std::unique_ptr<Message> message_ptr); |
void OnAddFilter(); |
void OnRemoveFilter(MessageFilter* filter); |
- template <typename Interface> |
- void RetrieveAssociatedInterface( |
- const AssociatedInterfaceRetrievedCallback<Interface>& callback) { |
- mojo::AssociatedInterfacePtr<Interface> interface_ptr; |
- channel_->GetAssociatedInterfaceSupport()->GetRemoteAssociatedInterface( |
- &interface_ptr); |
- callback.Run(std::move(interface_ptr)); |
- } |
// Methods called on the listener thread. |
void AddFilter(MessageFilter* filter); |
@@ -320,6 +314,9 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { |
void ClearChannel(); |
mojo::AssociatedGroup* associated_group() { return &associated_group_; } |
+ mojom::Channel& thread_safe_channel() { |
+ return thread_safe_channel_->proxy(); |
+ } |
void AddGenericAssociatedInterfaceForIOThread( |
const std::string& name, |
@@ -360,6 +357,11 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { |
mojo::AssociatedGroup associated_group_; |
+ // A thread-safe mojom::Channel interface we use to make remote interface |
+ // requests from the proxy thread. |
+ std::unique_ptr<mojo::ThreadSafeForwarder<mojom::Channel>> |
+ thread_safe_channel_; |
+ |
// Holds associated interface binders added by |
// AddGenericAssociatedInterfaceForIOThread until the underlying channel has |
// been initialized. |