Chromium Code Reviews| Index: mojo/public/cpp/bindings/lib/interface_ptr_state.h |
| diff --git a/mojo/public/cpp/bindings/lib/interface_ptr_state.h b/mojo/public/cpp/bindings/lib/interface_ptr_state.h |
| index 78aa02e17635442ae394a7aa9d0109650fbbab1e..58fcdb493246f3ae1b4d8470bff3bf2d3d429483 100644 |
| --- a/mojo/public/cpp/bindings/lib/interface_ptr_state.h |
| +++ b/mojo/public/cpp/bindings/lib/interface_ptr_state.h |
| @@ -18,6 +18,7 @@ |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "base/single_thread_task_runner.h" |
| #include "mojo/public/cpp/bindings/associated_group.h" |
| #include "mojo/public/cpp/bindings/connection_error_callback.h" |
| @@ -31,6 +32,7 @@ |
| #include "mojo/public/cpp/bindings/lib/router.h" |
| #include "mojo/public/cpp/bindings/message_header_validator.h" |
| #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| +#include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" |
| namespace mojo { |
| namespace internal { |
| @@ -209,7 +211,7 @@ class InterfacePtrState<Interface, false> { |
| template <typename Interface> |
| class InterfacePtrState<Interface, true> { |
| public: |
| - InterfacePtrState() : version_(0u) {} |
| + InterfacePtrState() : version_(0u), weak_ptr_factory_(this) {} |
| ~InterfacePtrState() { |
| endpoint_client_.reset(); |
| @@ -331,6 +333,16 @@ class InterfacePtrState<Interface, true> { |
| router_->EnableTestingMode(); |
| } |
| + scoped_refptr<ThreadSafeInterfacePtr<Interface>> GetThreadSafePtr() { |
|
yzshen1
2016/11/11 22:32:10
One thing that seems a little weird about this is
Jay Civelli
2016/11/15 05:02:30
Per our discussion, the ThreadSafeInterfacePtr cl
|
| + ConfigureProxyIfNecessary(); |
| + return new ThreadSafeInterfacePtr<Interface>( |
| + base::ThreadTaskRunnerHandle::Get(), |
| + base::Bind(&InterfacePtrState::ForwardMessage, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + base::Bind(&InterfacePtrState::ForwardMessageWithResponder, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
| + |
| private: |
| using Proxy = typename Interface::Proxy_; |
| @@ -371,6 +383,15 @@ class InterfacePtrState<Interface, true> { |
| callback.Run(version); |
| } |
| + void ForwardMessage(Message message) { |
| + endpoint_client_->Accept(&message); |
| + } |
| + |
| + void ForwardMessageWithResponder(Message message, |
| + std::unique_ptr<MessageReceiver> responder) { |
| + endpoint_client_->AcceptWithResponder(&message, responder.release()); |
| + } |
| + |
| scoped_refptr<MultiplexRouter> router_; |
| std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
| @@ -384,6 +405,8 @@ class InterfacePtrState<Interface, true> { |
| uint32_t version_; |
| + base::WeakPtrFactory<InterfacePtrState> weak_ptr_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); |
| }; |