summaryrefslogtreecommitdiffstats
path: root/remoting/host/plugin/host_script_object.cc
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-05 23:40:51 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-05 23:40:51 +0000
commit32debfbf3a9e2e5784f34907eaaf1132cfbf02f5 (patch)
tree19d8c1c8a680511c9aaaf615fff14166e11d1cba /remoting/host/plugin/host_script_object.cc
parent0b53a370894631f31d1ef02bac9aaff270da4700 (diff)
downloadchromium_src-32debfbf3a9e2e5784f34907eaaf1132cfbf02f5.zip
chromium_src-32debfbf3a9e2e5784f34907eaaf1132cfbf02f5.tar.gz
chromium_src-32debfbf3a9e2e5784f34907eaaf1132cfbf02f5.tar.bz2
Use AutoThread in ChromotingHostContext & NPAPI plugin.
Callers now create ChromotingHostContext to create a set of threads for host tasks to run on, and pass the threads' TaskRunners to each host component explicitly. The ChromotingHostContext can then be torn down as soon as the caller no longer needs to create new components using the threads, and the threads themselves will exit only when the created components no longer require them. This is a re-re-land of 11094056; the re-land failed due to a rebasing typo, and some over-zealous thread checking in ChromotingHostContext. BUG=145856 TEST=Chromoting IT2Me & Me2Me hosts start correctly, can be connected to, and shutdown cleanly. Unit-tests pass. Review URL: https://chromiumcodereview.appspot.com/11412305 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171358 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/plugin/host_script_object.cc')
-rw-r--r--remoting/host/plugin/host_script_object.cc27
1 files changed, 8 insertions, 19 deletions
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index 7b82603..d863899 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -15,8 +15,8 @@
#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/base/auto_thread.h"
#include "remoting/host/chromoting_host.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/desktop_environment_factory.h"
@@ -114,9 +114,6 @@ class HostNPScriptObject::It2MeImpl
virtual ~It2MeImpl();
- // Used to delete and join the ChromotingHostContext on the UI thread.
- static void DeleteHostContext(scoped_ptr<ChromotingHostContext> context) {}
-
// Updates state of the host. Can be called only on the network thread.
void SetState(State state);
@@ -559,12 +556,6 @@ HostNPScriptObject::It2MeImpl::~It2MeImpl() {
DCHECK(!it2me_host_user_interface_.get());
DCHECK(!desktop_environment_factory_.get());
DCHECK(!policy_watcher_.get());
-
- // We might be getting deleted on one of the threads the |host_context| owns,
- // so we need to post it back to the plugin thread to safely join & delete the
- // threads it contains. This will go away when we move to AutoThread.
- plugin_task_runner_->PostTask(FROM_HERE,
- base::Bind(&It2MeImpl::DeleteHostContext, base::Passed(&host_context_)));
}
void HostNPScriptObject::It2MeImpl::SetState(State state) {
@@ -666,12 +657,13 @@ HostNPScriptObject::HostNPScriptObject(
am_currently_logging_(false),
state_(kDisconnected),
daemon_controller_(DaemonController::Create()),
- worker_thread_("RemotingHostPlugin"),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
weak_ptr_(weak_factory_.GetWeakPtr()) {
DCHECK(plugin_task_runner_->BelongsToCurrentThread());
- worker_thread_.Start();
+ // Create worker thread for encryption key generation.
+ worker_thread_ = AutoThread::Create("ChromotingWorkerThread",
+ plugin_task_runner_);
}
HostNPScriptObject::~HostNPScriptObject() {
@@ -684,9 +676,6 @@ HostNPScriptObject::~HostNPScriptObject() {
it2me_impl_->Disconnect();
it2me_impl_ = NULL;
}
-
- // Stop the worker thread.
- worker_thread_.Stop();
}
bool HostNPScriptObject::HasMethod(const std::string& method_name) {
@@ -955,9 +944,9 @@ bool HostNPScriptObject::Connect(const NPVariant* args,
}
// Create threads for the Chromoting host & desktop environment to use.
- scoped_ptr<ChromotingHostContext> host_context(
- new ChromotingHostContext(plugin_task_runner_));
- if (!host_context->Start()) {
+ scoped_ptr<ChromotingHostContext> host_context =
+ ChromotingHostContext::Create(plugin_task_runner_);
+ if (!host_context) {
SetException("connect: failed to start threads");
return false;
}
@@ -1060,7 +1049,7 @@ bool HostNPScriptObject::GenerateKeyPair(const NPVariant* args,
// TODO(wez): HostNPScriptObject needn't be touched on worker
// thread, so make DoGenerateKeyPair static and pass it a callback
// to run (crbug.com/156257).
- worker_thread_.message_loop_proxy()->PostTask(
+ worker_thread_->PostTask(
FROM_HERE, base::Bind(&HostNPScriptObject::DoGenerateKeyPair,
base::Unretained(this), callback_obj));
return true;