summaryrefslogtreecommitdiffstats
path: root/remoting/host/plugin
diff options
context:
space:
mode:
authoralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-04 22:27:43 +0000
committeralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-04 22:27:43 +0000
commitef948e69b97c179af5eb69ae318714052230df4f (patch)
treecc76efb6983b1a5868f26769fb654185880f2805 /remoting/host/plugin
parent38091251bfc38e7ae748edbf66b13dd360f68bb4 (diff)
downloadchromium_src-ef948e69b97c179af5eb69ae318714052230df4f.zip
chromium_src-ef948e69b97c179af5eb69ae318714052230df4f.tar.gz
chromium_src-ef948e69b97c179af5eb69ae318714052230df4f.tar.bz2
[Chromoting] Introducing refcount-based life time management of the message loops in the service (daemon) and me2me host (network) processes.
This CL introduces AutoMessageLoop wrapper that provides control over life time of a message loop via scoped_refptr references. This scheme is useful in the cases when shutdown code has to run on a particular thread or when the OS requires resources (such as windows) to be freed before exiting a message loop. The CL switches threads, owned by remoting::HostService, remoting::HostProcess and remoting::ChromotingHostContext, to refcount-based lifetime management. This change required updating tear-down sequences in remoting_me2me_host and the host plugin code. BUG=134694 Review URL: https://chromiumcodereview.appspot.com/10829467 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154827 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/plugin')
-rw-r--r--remoting/host/plugin/host_script_object.cc27
1 files changed, 20 insertions, 7 deletions
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index 118114f..8cffb5e 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(