| Index: remoting/host/plugin/host_script_object.cc
|
| diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
|
| index 118114ff6f2a91f05cf2a7d0f1bdb6853149563c..8cffb5e4842b980c67dd3802c07dc576044459b3 100644
|
| --- a/remoting/host/plugin/host_script_object.cc
|
| +++ b/remoting/host/plugin/host_script_object.cc
|
| @@ -15,6 +15,7 @@
|
| #include "base/utf_string_conversions.h"
|
| #include "base/values.h"
|
| #include "net/base/net_util.h"
|
| +#include "remoting/base/auto_thread_task_runner.h"
|
| #include "remoting/base/auth_token_util.h"
|
| #include "remoting/host/chromoting_host.h"
|
| #include "remoting/host/chromoting_host_context.h"
|
| @@ -106,6 +107,10 @@ HostNPScriptObject::~HostNPScriptObject() {
|
|
|
| HostLogHandler::UnregisterLoggingScriptObject(this);
|
|
|
| + // Stop the message loop. Any attempt to post a task to
|
| + // |context_.ui_task_runner()| will result in a CHECK() after this point.
|
| + // TODO(alexeypa): Enable posting messages to |plugin_task_runner_| during
|
| + // shutdown to avoid this hack.
|
| plugin_task_runner_->Detach();
|
|
|
| // Stop listening for policy updates.
|
| @@ -121,9 +126,7 @@ HostNPScriptObject::~HostNPScriptObject() {
|
| // here because |host_context_| needs to be stopped on the plugin
|
| // thread, but the plugin thread may not exist after the instance
|
| // is destroyed.
|
| - disconnected_event_.Reset();
|
| DisconnectInternal();
|
| - disconnected_event_.Wait();
|
|
|
| // UI needs to be shut down on the UI thread before we destroy the
|
| // host context (because it depends on the context object), but
|
| @@ -132,7 +135,15 @@ HostNPScriptObject::~HostNPScriptObject() {
|
| // unregister it from this thread).
|
| it2me_host_user_interface_.reset();
|
|
|
| - // Stops all threads.
|
| + // Release the context's TaskRunner references for the threads, so they can
|
| + // exit when no objects need them.
|
| + host_context_->ReleaseTaskRunners();
|
| +
|
| + // |disconnected_event_| is signalled when the last reference to the plugin
|
| + // thread is dropped.
|
| + disconnected_event_.Wait();
|
| +
|
| + // Stop all threads.
|
| host_context_.reset();
|
| }
|
|
|
| @@ -143,7 +154,10 @@ bool HostNPScriptObject::Init() {
|
| DCHECK(plugin_task_runner_->BelongsToCurrentThread());
|
| VLOG(2) << "Init";
|
|
|
| - host_context_.reset(new ChromotingHostContext(plugin_task_runner_));
|
| + host_context_.reset(new ChromotingHostContext(new AutoThreadTaskRunner(
|
| + plugin_task_runner_,
|
| + base::Bind(&base::WaitableEvent::Signal,
|
| + base::Unretained(&disconnected_event_)))));
|
| if (!host_context_->Start()) {
|
| host_context_.reset();
|
| return false;
|
| @@ -878,13 +892,12 @@ void HostNPScriptObject::DisconnectInternal() {
|
|
|
| switch (state_) {
|
| case kDisconnected:
|
| - disconnected_event_.Signal();
|
| return;
|
|
|
| case kStarting:
|
| + desktop_environment_.reset();
|
| SetState(kDisconnecting);
|
| SetState(kDisconnected);
|
| - disconnected_event_.Signal();
|
| return;
|
|
|
| case kDisconnecting:
|
| @@ -913,7 +926,7 @@ void HostNPScriptObject::DisconnectInternal() {
|
| void HostNPScriptObject::OnShutdownFinished() {
|
| DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
|
|
|
| - disconnected_event_.Signal();
|
| + desktop_environment_.reset();
|
| }
|
|
|
| void HostNPScriptObject::OnPolicyUpdate(
|
|
|