Chromium Code Reviews| Index: ipc/ipc_channel_proxy.h |
| diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h |
| index bda83bb18854299b58c977b6a5a349e76cf4e15b..bb593671aa82650215d7288b0aece7ea1c341dba 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,23 @@ 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) { |
| + DCHECK(GetAssociatedGroup()); |
| + mojo::AssociatedInterfacePtr<Interface> ptr; |
| + mojom::GenericInterfaceAssociatedRequest request; |
| + request.Bind(mojo::MakeRequest(&ptr, GetAssociatedGroup()).PassHandle()); |
| + context()->thread_safe_channel().GetAssociatedInterface( |
|
yzshen1
2017/02/07 00:06:26
nit: you could call GetGenericRemoteAssociatedInte
Ken Rockot(use gerrit already)
2017/02/07 01:25:32
done (called GetRemoteAssociatedInterface instead)
yzshen1
2017/02/07 06:05:52
Using GetRemoteAssociatedInterface() will setup an
Ken Rockot(use gerrit already)
2017/02/08 00:37:11
Ah good point. Changed to use GetGenericRemoteAsso
|
| + Interface::Name_, std::move(request)); |
| + *out_ptr = mojo::ThreadSafeAssociatedInterfacePtr<Interface>::Create( |
| + ptr.PassInterface(), ipc_task_runner()); |
| } |
| base::SingleThreadTaskRunner* ipc_task_runner() const { |
| @@ -251,11 +259,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 +302,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 +315,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 +358,11 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { |
| mojo::AssociatedGroup associated_group_; |
| + // A thread-safe mojom::Channel interface we ues to make remote interface |
|
yzshen1
2017/02/07 00:06:26
ues -> use please.
Ken Rockot(use gerrit already)
2017/02/07 01:25:32
done
|
| + // 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. |