Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: mojo/public/cpp/bindings/lib/interface_endpoint_client.cc

Issue 2358693002: Mojo C++ bindings: make InterfaceEndpointClient observe message loop destruction. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/interface_endpoint_client.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « mojo/public/cpp/bindings/interface_endpoint_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698