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..da1055de535bb71445541320ab274be536bd5fe1 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() {} |
@@ -57,12 +58,15 @@ class InterfaceImpl : public internal::InterfaceImplBase<Interface> { |
// Takes an instance of an InterfaceImpl<..> subclass and binds it to the given |
// MessagePipe. The instance is returned for convenience in member initializer |
-// lists, etc. If the pipe is closed, the instance's OnConnectionError method |
-// will be called. |
+// lists, etc. |
+// |
+// 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 |
-// also be deleted, and along with it, its end point of the pipe will be closed. |
+// called on the current thread, and if the current thread exits, then the end |
+// point of the pipe will be closed and the error handler's OnConnectionError |
+// method will be called. |
// |
// Before returning, the instance's OnConnectionEstablished method is called. |
template <typename Impl> |
@@ -70,14 +74,25 @@ Impl* BindToPipe( |
Impl* instance, |
ScopedMessagePipeHandle handle, |
const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
- instance->internal_state()->Bind(handle.Pass(), waiter); |
+ instance->internal_state()->Bind(handle.Pass(), true, waiter); |
+ return instance; |
+} |
+ |
+// Like BindToPipe but does not delete the instance after a channel error. |
+template <typename Impl> |
+Impl* WeakBindToPipe( |
+ Impl* instance, |
+ ScopedMessagePipeHandle handle, |
+ const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
+ instance->internal_state()->Bind(handle.Pass(), false, waiter); |
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 +104,25 @@ Impl* BindToProxy( |
Impl* instance, |
InterfacePtr<Interface>* ptr, |
const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
- instance->internal_state()->BindProxy(ptr, waiter); |
+ instance->internal_state()->BindProxy(ptr, true, waiter); |
+ return instance; |
+} |
+ |
+// Like BindToProxy but does not delete the instance after a channel error. |
+template <typename Impl, typename Interface> |
+Impl* WeakBindToProxy( |
+ Impl* instance, |
+ InterfacePtr<Interface>* ptr, |
+ const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
+ instance->internal_state()->BindProxy(ptr, false, waiter); |
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. |
+// 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 +138,15 @@ Impl* BindToRequest( |
return BindToPipe(instance, request->PassMessagePipe(), waiter); |
} |
+// Like BindToRequest but does not delete the instance after a channel error. |
+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_ |