Chromium Code Reviews| Index: mojo/public/cpp/bindings/lib/interface_impl_internal.h |
| diff --git a/mojo/public/cpp/bindings/lib/interface_impl_internal.h b/mojo/public/cpp/bindings/lib/interface_impl_internal.h |
| index 1c912661fd96a95d41661add0ad664f05ce063b3..044c31dd8583f53c8a694d3df53f69750a398ba6 100644 |
| --- a/mojo/public/cpp/bindings/lib/interface_impl_internal.h |
| +++ b/mojo/public/cpp/bindings/lib/interface_impl_internal.h |
| @@ -13,6 +13,7 @@ |
| #include "mojo/public/cpp/system/macros.h" |
| namespace mojo { |
| + |
| namespace internal { |
| template <typename Interface> |
| @@ -29,8 +30,7 @@ class InterfaceImplState : public ErrorHandler { |
| typedef typename Interface::Client Client; |
| explicit InterfaceImplState(InterfaceImplBase<Interface>* instance) |
| - : router_(NULL), |
| - proxy_(NULL) { |
| + : router_(NULL), proxy_(NULL) { |
| assert(instance); |
| stub_.set_sink(instance); |
| } |
| @@ -48,11 +48,12 @@ class InterfaceImplState : public ErrorHandler { |
| const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| MessagePipe pipe; |
| ptr->Bind(pipe.handle0.Pass(), waiter); |
| - Bind(pipe.handle1.Pass(), waiter); |
| + Bind(pipe.handle1.Pass(), waiter, DELETE_ON_ERROR); |
| } |
| void Bind(ScopedMessagePipeHandle handle, |
| - const MojoAsyncWaiter* waiter) { |
| + const MojoAsyncWaiter* waiter, |
| + OnConnectionErrorBehavior behavior) { |
| assert(!router_); |
| FilterChain filters; |
| @@ -65,6 +66,7 @@ class InterfaceImplState : public ErrorHandler { |
| router_->set_error_handler(this); |
| proxy_ = new typename Client::Proxy_(router_); |
| + behavior_ = behavior; |
| instance()->OnConnectionEstablished(); |
| } |
| @@ -83,12 +85,21 @@ class InterfaceImplState : public ErrorHandler { |
| } |
| virtual void OnConnectionError() MOJO_OVERRIDE { |
| + // If the connection error behavior is DO_NOTHING the instance might delete |
| + // itself in the OnConnectionError handler, which would in turn delete this. |
| + // Save the error behavior before invoking the error handler so we can |
| + // correctly decide what to do. |
| + OnConnectionErrorBehavior behavior = behavior_; |
| instance()->OnConnectionError(); |
| + if (behavior == DELETE_ON_ERROR) { |
|
DaveMoore
2014/07/15 00:08:29
Nit: no braces
|
| + delete instance(); |
| + } |
| } |
| Router* router_; |
| typename Client::Proxy_* proxy_; |
| typename Interface::Stub_ stub_; |
| + OnConnectionErrorBehavior behavior_; |
| MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); |
| }; |