Chromium Code Reviews| Index: mojo/public/cpp/bindings/interface_impl.h |
| diff --git a/mojo/public/cpp/bindings/interface_impl.h b/mojo/public/cpp/bindings/interface_impl.h |
| index 4a78cb4b05a1f11b4380a001aab45fa76e91a8e2..c4ff1ebbe81a894a14d45c5883054bc2dcb21c9f 100644 |
| --- a/mojo/public/cpp/bindings/interface_impl.h |
| +++ b/mojo/public/cpp/bindings/interface_impl.h |
| @@ -19,6 +19,7 @@ template <typename Interface> |
| class InterfaceImpl : public internal::InterfaceImplBase<Interface> { |
| public: |
| typedef typename Interface::Client Client; |
| + typedef Interface ImplementedInterface; |
| InterfaceImpl() : internal_state_(this) {} |
| virtual ~InterfaceImpl() {} |
| @@ -70,14 +71,26 @@ Impl* BindToPipe( |
| Impl* instance, |
| ScopedMessagePipeHandle handle, |
| const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| - instance->internal_state()->Bind(handle.Pass(), waiter); |
| + instance->internal_state()->Bind( |
| + handle.Pass(), waiter, true /* delete_on_error */); |
| + return instance; |
| +} |
| + |
| +template <typename Impl> |
| +Impl* WeakBindToPipe( |
| + Impl* instance, |
| + ScopedMessagePipeHandle handle, |
| + const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| + instance->internal_state()->Bind( |
| + handle.Pass(), waiter, false /* delete_on_error */); |
| return instance; |
| } |
| // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given |
| // InterfacePtr<..>. The instance is returned for convenience in member |
| // initializer lists, etc. If the pipe is closed, the instance's |
| -// OnConnectionError method will be called. |
| +// OnConnectionError method will be called and then the instance will be |
| +// deleted. |
| // |
| // The instance is also bound to the current thread. Its methods will only be |
| // called on the current thread, and if the current thread exits, then it will |
| @@ -89,14 +102,29 @@ Impl* BindToProxy( |
| Impl* instance, |
| InterfacePtr<Interface>* ptr, |
| const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| - instance->internal_state()->BindProxy(ptr, waiter); |
| + instance->internal_state()->BindProxy( |
| + ptr, waiter, true /* delete_on_error */); |
| + return instance; |
| +} |
| + |
| +// Same as BindToProxy but does not delete instance after a channel error. |
|
darin (slow to review)
2014/07/15 18:44:08
nit: it'd be good to standardize on a comment for
|
| +template <typename Impl, typename Interface> |
| +Impl* WeakBindToProxy( |
| + Impl* instance, |
| + InterfacePtr<Interface>* ptr, |
| + const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| + instance->internal_state()->BindProxy( |
| + ptr, waiter, false /* delete_on_error */); |
| return instance; |
| } |
| // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given |
| // InterfaceRequest<..>. The instance is returned for convenience in member |
| -// initializer lists, etc. If the pipe is closed, the instance's |
| -// OnConnectionError method will be called. |
| +// initializer lists, etc. |
| +// |
| +// The bind call passes ownership of the instance to the pipe. If the pipe is |
| +// closed, the instance's OnConnectionError method will be called and then the |
| +// instance will be deleted. |
| // |
| // The instance is also bound to the current thread. Its methods will only be |
| // called on the current thread, and if the current thread exits, then it will |
| @@ -112,6 +140,18 @@ Impl* BindToRequest( |
| return BindToPipe(instance, request->PassMessagePipe(), waiter); |
| } |
| +// This is the same as BindToRequest except that the lifetime of the instance is |
| +// not bound to the pipe. If the pipe is closed, the instance's |
| +// OnConnectionError |
| +// method will be called but the instance will not be deleted. |
| +template <typename Impl, typename Interface> |
| +Impl* WeakBindToRequest( |
| + Impl* instance, |
| + InterfaceRequest<Interface>* request, |
| + const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| + return WeakBindToPipe(instance, request->PassMessagePipe(), waiter); |
| +} |
| + |
| } // namespace mojo |
| #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |