Chromium Code Reviews| Index: mojo/public/cpp/bindings/associated_binding.h |
| diff --git a/mojo/public/cpp/bindings/associated_binding.h b/mojo/public/cpp/bindings/associated_binding.h |
| index a7a7c822869b414eb33fd63bde32f5a3e1f89de8..55359ec4fa4401183a185161dab5a54c739b6187 100644 |
| --- a/mojo/public/cpp/bindings/associated_binding.h |
| +++ b/mojo/public/cpp/bindings/associated_binding.h |
| @@ -22,6 +22,7 @@ |
| #include "mojo/public/cpp/bindings/connection_error_callback.h" |
| #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
| #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
| +#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h" |
| #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| namespace mojo { |
| @@ -38,22 +39,23 @@ class MessageReceiver; |
| // single thread for the purposes of task scheduling. Please note that incoming |
| // synchrounous method calls may not be run from this task runner, when they |
| // reenter outgoing synchrounous calls on the same thread. |
| -template <typename Interface> |
| +template <typename Interface, |
| + typename ImplRefTraits = RawPtrImplRefTraits<Interface>> |
| class AssociatedBinding { |
| public: |
| + using ImplPointerType = typename ImplRefTraits::PointerType; |
| + |
| // Constructs an incomplete associated binding that will use the |
| // implementation |impl|. It may be completed with a subsequent call to the |
| // |Bind| method. Does not take ownership of |impl|, which must outlive this |
| // object. |
| - explicit AssociatedBinding(Interface* impl) : impl_(impl) { |
| - stub_.set_sink(impl_); |
| - } |
| + explicit AssociatedBinding(ImplPointerType impl) { stub_.set_sink(impl); } |
|
Sam McNally
2016/10/09 22:57:56
Pass by const ref or std::move(impl). I could see
Ken Rockot(use gerrit already)
2016/10/10 05:38:39
Done (std::move)
I had the same thought about Str
|
| // Constructs a completed associated binding of |impl|. The output |ptr_info| |
| // should be passed through the message pipe endpoint referred to by |
| // |associated_group| to setup the corresponding asssociated interface |
| // pointer. |impl| must outlive this object. |
| - AssociatedBinding(Interface* impl, |
| + AssociatedBinding(ImplPointerType impl, |
| AssociatedInterfacePtrInfo<Interface>* ptr_info, |
| AssociatedGroup* associated_group, |
| scoped_refptr<base::SingleThreadTaskRunner> runner = |
| @@ -64,7 +66,7 @@ class AssociatedBinding { |
| // Constructs a completed associated binding of |impl|. |impl| must outlive |
| // the binding. |
| - AssociatedBinding(Interface* impl, |
| + AssociatedBinding(ImplPointerType impl, |
| AssociatedInterfaceRequest<Interface> request, |
| scoped_refptr<base::SingleThreadTaskRunner> runner = |
| base::ThreadTaskRunnerHandle::Get()) |
| @@ -166,7 +168,7 @@ class AssociatedBinding { |
| } |
| // Returns the interface implementation that was previously specified. |
| - Interface* impl() { return impl_; } |
| + Interface* impl() { return ImplRefTraits::GetRawPointer(stub_.sink()); } |
| // Indicates whether the associated binding has been completed. |
| bool is_bound() const { return !!endpoint_client_; } |
| @@ -187,9 +189,7 @@ class AssociatedBinding { |
| private: |
| std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
| - |
| - typename Interface::Stub_ stub_; |
| - Interface* impl_; |
| + typename Interface::template Stub_<ImplRefTraits> stub_; |
| DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); |
| }; |