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..8204f3074090809047d93114af6dbcfb97e6d741 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 Implements; |
|
jamesr
2014/07/14 21:21:44
this is a little bit strange but without it I'm no
|
| InterfaceImpl() : internal_state_(this) {} |
| virtual ~InterfaceImpl() {} |
| @@ -69,8 +70,9 @@ template <typename Impl> |
| Impl* BindToPipe( |
|
darin (slow to review)
2014/07/14 21:34:06
Instead of exposing the enum (which is a bit awkwa
|
| Impl* instance, |
| ScopedMessagePipeHandle handle, |
| - const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| - instance->internal_state()->Bind(handle.Pass(), waiter); |
| + const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter(), |
| + OnConnectionErrorBehavior behavior = DELETE_ON_ERROR) { |
| + instance->internal_state()->Bind(handle.Pass(), waiter, behavior); |
| return instance; |
| } |
| @@ -95,8 +97,11 @@ Impl* BindToProxy( |
| // 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 |
| @@ -104,6 +109,9 @@ Impl* BindToProxy( |
| // |
| // Before returning, the instance will receive a SetClient call, providing it |
| // with a proxy to the client on the other end of the pipe. |
| +// |
| +// (Aside: If we were using C++11, the type of the first parameter would be |
| +// std::unique_ptr<Impl>). |
| template <typename Impl, typename Interface> |
| Impl* BindToRequest( |
| Impl* instance, |
| @@ -112,6 +120,17 @@ 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 OnChannelError |
| +// 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 BindToPipe(instance, request->PassMessagePipe(), waiter, DO_NOTHING); |
| +} |
| + |
| } // namespace mojo |
| #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |