Commit 901b0992 authored by kmackay's avatar kmackay Committed by Commit bot

Prevent DCHECK on shutdown of EmbeddedApplicationRunner

When EmbeddedApplicationRunner is destroyed, if the application
instance still has any bound connections, those connections must
be destroyed on the application task runner. Otherwise there is
a DCHECK failure when the binding is destroyed.

BUG=

Review-Url: https://codereview.chromium.org/2188503003
Cr-Commit-Position: refs/heads/master@{#408246}
parent 8c13e2d6
...@@ -52,13 +52,26 @@ class EmbeddedApplicationRunner::Instance ...@@ -52,13 +52,26 @@ class EmbeddedApplicationRunner::Instance
void ShutDown() { void ShutDown() {
DCHECK(runner_thread_checker_.CalledOnValidThread()); DCHECK(runner_thread_checker_.CalledOnValidThread());
if (thread_) { if (!application_task_runner_)
thread_.reset(); return;
application_task_runner_ = nullptr; // 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: 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( void BindServiceRequestOnApplicationThread(
shell::mojom::ServiceRequest request) { shell::mojom::ServiceRequest request) {
DCHECK(application_task_runner_->BelongsToCurrentThread()); DCHECK(application_task_runner_->BelongsToCurrentThread());
...@@ -76,15 +89,6 @@ class EmbeddedApplicationRunner::Instance ...@@ -76,15 +89,6 @@ class EmbeddedApplicationRunner::Instance
new_connection)); 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) { void OnStop(shell::ServiceContext* connection) {
DCHECK(application_task_runner_->BelongsToCurrentThread()); DCHECK(application_task_runner_->BelongsToCurrentThread());
...@@ -102,13 +106,20 @@ class EmbeddedApplicationRunner::Instance ...@@ -102,13 +106,20 @@ class EmbeddedApplicationRunner::Instance
shell_connections_.clear(); shell_connections_.clear();
service_.reset(); service_.reset();
quit_task_runner_->PostTask( if (quit_task_runner_->BelongsToCurrentThread()) {
FROM_HERE, base::Bind(&Instance::QuitOnRunnerThread, this)); QuitOnRunnerThread();
} else {
quit_task_runner_->PostTask(
FROM_HERE, base::Bind(&Instance::QuitOnRunnerThread, this));
}
} }
void QuitOnRunnerThread() { void QuitOnRunnerThread() {
DCHECK(runner_thread_checker_.CalledOnValidThread()); DCHECK(runner_thread_checker_.CalledOnValidThread());
ShutDown(); if (thread_) {
thread_.reset();
application_task_runner_ = nullptr;
}
quit_closure_.Run(); quit_closure_.Run();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment