Chromium Code Reviews| 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 1f83dcde3c6b5cac3e911324757c444b62f31c6a..b89c95fcbbe34d1c93e2bda3a39e2aaf1d5eaa7c 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,13 @@ HostNPScriptObject::~HostNPScriptObject() { |
| // unregister it from this thread). |
| it2me_host_user_interface_.reset(); |
| - // Stops all threads. |
| + host_context_->Stop(); |
|
Wez
2012/08/30 23:56:43
nit: Add comment "Release the context's TaskRunner
alexeypa (please no reviews)
2012/08/31 19:57:36
This is now apparent from the method's name.
|
| + |
| + // |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 +152,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; |
| @@ -871,13 +883,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: |
| @@ -906,7 +917,7 @@ void HostNPScriptObject::DisconnectInternal() { |
| void HostNPScriptObject::OnShutdownFinished() { |
| DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| - disconnected_event_.Signal(); |
| + desktop_environment_.reset(); |
| } |
| void HostNPScriptObject::OnPolicyUpdate( |