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..06396b1cb09be54dcd2a0758daf1f99025d104e7 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; |
darin (slow to review)
2014/07/15 06:10:38
The name of this typedef bugs me a bit. Interface
jamesr
2014/07/15 18:07:22
yeah, it's used in two places total so I went with
|
InterfaceImpl() : internal_state_(this) {} |
virtual ~InterfaceImpl() {} |
@@ -70,7 +71,18 @@ 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; |
} |
@@ -95,8 +107,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 |
@@ -112,6 +127,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 |
darin (slow to review)
2014/07/15 06:10:38
nit: OnChannelError -> 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_ |