| Index: mojo/public/cpp/bindings/lib/interface_endpoint_client.cc
|
| diff --git a/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc b/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc
|
| index 6140cde5399374583bfef8d7cb53c0408e680d1c..df16ecfaeea4bfe11562d4e2f54be8a563ca8b90 100644
|
| --- a/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc
|
| +++ b/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc
|
| @@ -159,11 +159,15 @@ InterfaceEndpointClient::InterfaceEndpointClient(
|
| handle_, this, task_runner_);
|
| if (expect_sync_requests)
|
| controller_->AllowWokenUpBySyncWatchOnSameThread();
|
| +
|
| + base::MessageLoop::current()->AddDestructionObserver(this);
|
| }
|
|
|
| InterfaceEndpointClient::~InterfaceEndpointClient() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| + StopObservingIfNecessary();
|
| +
|
| if (handle_.is_valid())
|
| handle_.group_controller()->DetachEndpointClient(handle_);
|
| }
|
| @@ -336,4 +340,17 @@ bool InterfaceEndpointClient::HandleValidatedMessage(Message* message) {
|
| }
|
| }
|
|
|
| +void InterfaceEndpointClient::StopObservingIfNecessary() {
|
| + if (!observing_message_loop_destruction_)
|
| + return;
|
| +
|
| + observing_message_loop_destruction_ = false;
|
| + base::MessageLoop::current()->RemoveDestructionObserver(this);
|
| +}
|
| +
|
| +void InterfaceEndpointClient::WillDestroyCurrentMessageLoop() {
|
| + StopObservingIfNecessary();
|
| + NotifyError();
|
| +}
|
| +
|
| } // namespace mojo
|
|
|