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 50d62a10738387d37e217c5fd15c1224f4c824fc..c220e9a43eb2e6e53afa6e56c6e359bc9e7f0e67 100644 |
--- a/content/common/mojo/embedded_application_runner.cc |
+++ b/content/common/mojo/embedded_application_runner.cc |
@@ -9,6 +9,7 @@ |
#include "base/bind.h" |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
+#include "base/single_thread_task_runner.h" |
#include "base/thread_task_runner_handle.h" |
#include "base/threading/thread_checker.h" |
#include "services/shell/public/cpp/shell_connection.h" |
@@ -19,8 +20,11 @@ class EmbeddedApplicationRunner::Instance |
: public base::RefCountedThreadSafe<Instance> { |
public: |
explicit Instance( |
- const EmbeddedApplicationRunner::FactoryCallback& callback) |
- : factory_callback_(callback) { |
+ const EmbeddedApplicationRunner::FactoryCallback& callback, |
+ const base::Closure& quit_closure) |
+ : factory_callback_(callback), |
+ quit_closure_(quit_closure), |
+ quit_task_runner_(base::ThreadTaskRunnerHandle::Get()) { |
// This object may be used exclusively from a single thread which may be |
// different from the one that created it. |
thread_checker_.DetachFromThread(); |
@@ -56,14 +60,18 @@ class EmbeddedApplicationRunner::Instance |
} |
} |
- if (shell_connections_.empty()) |
+ if (shell_connections_.empty()) { |
shell_client_.reset(); |
+ quit_task_runner_->PostTask(FROM_HERE, quit_closure_); |
+ } |
} |
base::ThreadChecker thread_checker_; |
const FactoryCallback factory_callback_; |
std::unique_ptr<shell::ShellClient> shell_client_; |
std::vector<std::unique_ptr<shell::ShellConnection>> shell_connections_; |
+ const base::Closure quit_closure_; |
+ const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_; |
DISALLOW_COPY_AND_ASSIGN(Instance); |
}; |
@@ -73,7 +81,10 @@ EmbeddedApplicationRunner::EmbeddedApplicationRunner( |
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
: application_task_runner_( |
task_runner ? task_runner : base::ThreadTaskRunnerHandle::Get()), |
- instance_(new Instance(callback)) { |
+ weak_factory_(this) { |
+ instance_ = new Instance(callback, |
+ base::Bind(&EmbeddedApplicationRunner::OnQuit, |
+ weak_factory_.GetWeakPtr())); |
} |
EmbeddedApplicationRunner::~EmbeddedApplicationRunner() { |
@@ -87,4 +98,13 @@ void EmbeddedApplicationRunner::BindShellClientRequest( |
base::Passed(&request))); |
} |
+void EmbeddedApplicationRunner::SetQuitClosure( |
+ const base::Closure& quit_closure) { |
+ quit_closure_ = quit_closure; |
+} |
+ |
+void EmbeddedApplicationRunner::OnQuit() { |
+ quit_closure_.Run(); |
+} |
+ |
} // namespace content |