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

Unified Diff: content/common/mojo/embedded_application_runner.cc

Issue 2188503003: Prevent DCHECK on shutdown of EmbeddedApplicationRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: don't post whan already on the correct thread Created 4 years, 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/mojo/embedded_application_runner.cc
diff --git a/content/common/mojo/embedded_application_runner.cc b/content/common/mojo/embedded_application_runner.cc
index 5d7abed900d54549082faca86bd848afaba85048..4f4ecff7746ce6fc1f636e45fddb5c7d5344620e 100644
--- a/content/common/mojo/embedded_application_runner.cc
+++ b/content/common/mojo/embedded_application_runner.cc
@@ -52,13 +52,26 @@ class EmbeddedApplicationRunner::Instance
void ShutDown() {
DCHECK(runner_thread_checker_.CalledOnValidThread());
- if (thread_) {
- thread_.reset();
- application_task_runner_ = nullptr;
+ if (!application_task_runner_)
+ return;
+ // Any extant ServiceContexts must be destroyed on the application thread.
+ if (application_task_runner_->BelongsToCurrentThread()) {
+ Quit();
+ } else {
+ application_task_runner_->PostTask(FROM_HERE,
+ base::Bind(&Instance::Quit, this));
}
}
private:
+ friend class base::RefCountedThreadSafe<Instance>;
+
+ ~Instance() {
+ // If this instance had its own thread, it MUST be explicitly destroyed by
+ // QuitOnRunnerThread() by the time this destructor is run.
+ DCHECK(!thread_);
+ }
+
void BindServiceRequestOnApplicationThread(
shell::mojom::ServiceRequest request) {
DCHECK(application_task_runner_->BelongsToCurrentThread());
@@ -76,15 +89,6 @@ class EmbeddedApplicationRunner::Instance
new_connection));
}
- private:
- friend class base::RefCountedThreadSafe<Instance>;
-
- ~Instance() {
- // If this instance had its own thread, it MUST be explicitly destroyed by
- // ShutDown() on the runner's thread by the time this destructor is run.
- DCHECK(!thread_);
- }
-
void OnStop(shell::ServiceContext* connection) {
DCHECK(application_task_runner_->BelongsToCurrentThread());
@@ -102,13 +106,20 @@ class EmbeddedApplicationRunner::Instance
shell_connections_.clear();
service_.reset();
- quit_task_runner_->PostTask(
- FROM_HERE, base::Bind(&Instance::QuitOnRunnerThread, this));
+ if (quit_task_runner_->BelongsToCurrentThread()) {
+ QuitOnRunnerThread();
+ } else {
+ quit_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&Instance::QuitOnRunnerThread, this));
+ }
}
void QuitOnRunnerThread() {
DCHECK(runner_thread_checker_.CalledOnValidThread());
- ShutDown();
+ if (thread_) {
+ thread_.reset();
+ application_task_runner_ = nullptr;
+ }
quit_closure_.Run();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698