summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-30 02:16:19 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-30 02:16:19 +0000
commitd48d05d90e7b9a7b0da496d6ce8f0e63be7d731b (patch)
tree3e0e03161aee4f8127337411ecd641e1b6e86f55 /remoting
parentba17cdbac1d205211899ddf6df4dcd32bbb5ce1f (diff)
downloadchromium_src-d48d05d90e7b9a7b0da496d6ce8f0e63be7d731b.zip
chromium_src-d48d05d90e7b9a7b0da496d6ce8f0e63be7d731b.tar.gz
chromium_src-d48d05d90e7b9a7b0da496d6ce8f0e63be7d731b.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-land of 11094056, which failed on the valgrind & Windows TSan bots due to ChromotingHostContext.StartAndStop not running its message loop to allow the context's threads join tasks to execute. TBR=alexeypa Review URL: https://chromiumcodereview.appspot.com/11316247 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170360 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/chromoting_host_context.cc126
-rw-r--r--remoting/host/chromoting_host_context.h75
-rw-r--r--remoting/host/chromoting_host_context_unittest.cc30
-rw-r--r--remoting/host/chromoting_host_unittest.cc41
-rw-r--r--remoting/host/desktop_environment_factory.cc1
-rw-r--r--remoting/host/host_mock_objects.cc7
-rw-r--r--remoting/host/host_mock_objects.h17
-rw-r--r--remoting/host/plugin/host_script_object.cc18
-rw-r--r--remoting/host/plugin/host_script_object.h2
-rw-r--r--remoting/host/remoting_me2me_host.cc10
-rw-r--r--remoting/host/win/session_desktop_environment_factory.cc1
11 files changed, 137 insertions, 191 deletions
diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc
index c37704f..8fc4f2a 100644
--- a/remoting/host/chromoting_host_context.cc
+++ b/remoting/host/chromoting_host_context.cc
@@ -7,108 +7,102 @@
#include <string>
#include "base/bind.h"
-#include "base/threading/thread.h"
-#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/base/auto_thread.h"
#include "remoting/host/url_request_context.h"
namespace remoting {
ChromotingHostContext::ChromotingHostContext(
- scoped_refptr<AutoThreadTaskRunner> ui_task_runner)
- : audio_thread_("ChromotingAudioThread"),
- video_capture_thread_("ChromotingCaptureThread"),
- video_encode_thread_("ChromotingEncodeThread"),
- file_thread_("ChromotingFileIOThread"),
- input_thread_("ChromotingInputThread"),
- network_thread_("ChromotingNetworkThread"),
- ui_task_runner_(ui_task_runner) {
+ AutoThreadTaskRunner* ui_task_runner)
+ : ui_task_runner_(ui_task_runner) {
+#if defined(OS_WIN)
+ // On Windows the AudioCapturer requires COM, so we run a single-threaded
+ // apartment, which requires a UI thread.
+ audio_task_runner_ = AutoThread::CreateWithLoopAndComInitTypes(
+ "ChromotingAudioThread", ui_task_runner_, MessageLoop::TYPE_UI,
+ AutoThread::COM_INIT_STA);
+#else // !defined(OS_WIN)
+ audio_task_runner_ = AutoThread::CreateWithType(
+ "ChromotingAudioThread", ui_task_runner_, MessageLoop::TYPE_IO);
+#endif // !defined(OS_WIN)
+
+ video_capture_task_runner_ = AutoThread::Create(
+ "ChromotingCaptureThread", ui_task_runner_);
+ video_encode_task_runner_ = AutoThread::Create(
+ "ChromotingEncodeThread", ui_task_runner_);
+ file_task_runner_ = AutoThread::CreateWithType(
+ "ChromotingFileThread", ui_task_runner_, MessageLoop::TYPE_IO);
+ input_task_runner_ = AutoThread::CreateWithType(
+ "ChromotingInputThread", ui_task_runner_, MessageLoop::TYPE_IO);
+ network_task_runner_ = AutoThread::CreateWithType(
+ "ChromotingNetworkThread", ui_task_runner_, MessageLoop::TYPE_IO);
+
+ url_request_context_getter_ = new URLRequestContextGetter(
+ ui_task_runner_, network_task_runner_);
}
ChromotingHostContext::~ChromotingHostContext() {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
}
-bool ChromotingHostContext::Start() {
- // Start all the threads.
- base::Thread::Options io_thread_options(MessageLoop::TYPE_IO, 0);
-
- bool started = video_capture_thread_.Start() && video_encode_thread_.Start();
-
-#if defined(OS_WIN)
- // On Windows audio capturer needs to run on a UI thread that has COM
- // initialized.
- audio_thread_.init_com_with_mta(false);
- started = started && audio_thread_.Start();
-#else // defined(OS_WIN)
- started = started && audio_thread_.StartWithOptions(io_thread_options);
-#endif // !defined(OS_WIN)
-
- started = started &&
- file_thread_.StartWithOptions(io_thread_options) &&
- input_thread_.StartWithOptions(io_thread_options) &&
- network_thread_.StartWithOptions(io_thread_options);
- if (!started)
- return false;
-
- // Wrap worker threads with |AutoThreadTaskRunner| and have them reference
- // the main thread via |ui_task_runner_|, to ensure that it remain active to
- // Stop() them when no references remain.
- audio_task_runner_ =
- new AutoThreadTaskRunner(audio_thread_.message_loop_proxy(),
- ui_task_runner_);
- video_capture_task_runner_ =
- new AutoThreadTaskRunner(video_capture_thread_.message_loop_proxy(),
- ui_task_runner_);
- video_encode_task_runner_ =
- new AutoThreadTaskRunner(video_encode_thread_.message_loop_proxy(),
- ui_task_runner_);
- file_task_runner_ =
- new AutoThreadTaskRunner(file_thread_.message_loop_proxy(),
- ui_task_runner_);
- input_task_runner_ =
- new AutoThreadTaskRunner(input_thread_.message_loop_proxy(),
- ui_task_runner_);
- network_task_runner_ =
- new AutoThreadTaskRunner(network_thread_.message_loop_proxy(),
- ui_task_runner_);
-
- url_request_context_getter_ = new URLRequestContextGetter(
- ui_task_runner(), network_task_runner());
- return true;
+scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create(
+ scoped_refptr<AutoThreadTaskRunner> ui_task_runner) {
+ DCHECK(ui_task_runner->BelongsToCurrentThread());
+
+ scoped_ptr<ChromotingHostContext> context(
+ new ChromotingHostContext(ui_task_runner));
+ if (!context->audio_task_runner_ ||
+ !context->video_capture_task_runner_ ||
+ !context->video_encode_task_runner_ ||
+ !context->file_task_runner_ ||
+ !context->input_task_runner_ ||
+ !context->network_task_runner_ ||
+ !context->url_request_context_getter_) {
+ context.reset();
+ }
+
+ return context.Pass();
}
-base::SingleThreadTaskRunner* ChromotingHostContext::audio_task_runner() {
+scoped_refptr<AutoThreadTaskRunner>
+ChromotingHostContext::audio_task_runner() {
return audio_task_runner_;
}
-base::SingleThreadTaskRunner*
+scoped_refptr<AutoThreadTaskRunner>
ChromotingHostContext::video_capture_task_runner() {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
return video_capture_task_runner_;
}
-base::SingleThreadTaskRunner*
+scoped_refptr<AutoThreadTaskRunner>
ChromotingHostContext::video_encode_task_runner() {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
return video_encode_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() {
+scoped_refptr<AutoThreadTaskRunner>
+ChromotingHostContext::file_task_runner() {
return file_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::input_task_runner() {
+scoped_refptr<AutoThreadTaskRunner>
+ChromotingHostContext::input_task_runner() {
return input_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() {
+scoped_refptr<AutoThreadTaskRunner>
+ChromotingHostContext::network_task_runner() {
return network_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() {
+scoped_refptr<AutoThreadTaskRunner>
+ChromotingHostContext::ui_task_runner() {
return ui_task_runner_;
}
-const scoped_refptr<net::URLRequestContextGetter>&
+scoped_refptr<net::URLRequestContextGetter>
ChromotingHostContext::url_request_context_getter() {
- DCHECK(url_request_context_getter_.get());
return url_request_context_getter_;
}
diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h
index 68c0802..5735b50 100644
--- a/remoting/host/chromoting_host_context.h
+++ b/remoting/host/chromoting_host_context.h
@@ -7,11 +7,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
-#include "base/threading/thread.h"
-
-namespace base {
-class SingleThreadTaskRunner;
-} // namespace base
+#include "base/memory/scoped_ptr.h"
namespace net {
class URLRequestContextGetter;
@@ -25,83 +21,72 @@ class AutoThreadTaskRunner;
// process. This class is virtual only for testing purposes (see below).
class ChromotingHostContext {
public:
- // Create a context.
- ChromotingHostContext(
- scoped_refptr<AutoThreadTaskRunner> ui_task_runner);
virtual ~ChromotingHostContext();
- // TODO(ajwong): Move the Start method out of this class. Then
- // create a static factory for construction, and destruction. We
- // should be able to remove the need for virtual functions below
- // with that design, while preserving the relative simplicity of
- // this API.
- virtual bool Start();
+ // Create threads and URLRequestContextGetter for use by a host.
+ // During shutdown the caller should tear-down the ChromotingHostContext and
+ // then continue to run until |ui_task_runner| is no longer referenced.
+ // NULL is returned if any threads fail to start.
+ static scoped_ptr<ChromotingHostContext> Create(
+ scoped_refptr<AutoThreadTaskRunner> ui_task_runner);
// Task runner for the thread used for audio capture and encoding.
- virtual base::SingleThreadTaskRunner* audio_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> audio_task_runner();
// Task runner for the thread used by the ScreenRecorder to capture
// the screen.
- virtual base::SingleThreadTaskRunner* video_capture_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner();
// Task runner for the thread used to encode video streams.
- virtual base::SingleThreadTaskRunner* video_encode_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner();
// Task runner for the thread that is used for blocking file
// IO. This thread is used by the URLRequestContext to read proxy
// configuration and by NatConfig to read policy configs.
- virtual base::SingleThreadTaskRunner* file_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> file_task_runner();
// Task runner for the thread that is used by the EventExecutor.
//
// TODO(sergeyu): Do we need a separate thread for EventExecutor?
// Can we use some other thread instead?
- virtual base::SingleThreadTaskRunner* input_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> input_task_runner();
// Task runner for the thread used for network IO. This thread runs
// a libjingle message loop, and is the only thread on which
// libjingle code may be run.
- virtual base::SingleThreadTaskRunner* network_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner();
// Task runner for the thread that is used for the UI. In the NPAPI
// plugin this corresponds to the main plugin thread.
- virtual base::SingleThreadTaskRunner* ui_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> ui_task_runner();
- const scoped_refptr<net::URLRequestContextGetter>&
- url_request_context_getter();
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter();
private:
- FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop);
-
- // A thread that hosts audio capture and encoding.
- base::Thread audio_thread_;
+ ChromotingHostContext(AutoThreadTaskRunner* ui_task_runner);
- // A thread that hosts screen capture.
- base::Thread video_capture_thread_;
+ // Thread for audio capture and encoding.
+ scoped_refptr<AutoThreadTaskRunner> audio_task_runner_;
- // A thread that hosts video encode operations.
- base::Thread video_encode_thread_;
+ // Thread for screen capture.
+ scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner_;
- // Thread for blocking IO operations.
- base::Thread file_thread_;
+ // Thread for video encoding.
+ scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner_;
- // A thread that hosts input injection.
- base::Thread input_thread_;
+ // Thread for I/O operations.
+ scoped_refptr<AutoThreadTaskRunner> file_task_runner_;
- // A thread that hosts all network operations.
- base::Thread network_thread_;
+ // Thread for input injection.
+ scoped_refptr<AutoThreadTaskRunner> input_task_runner_;
- // Task runners wrapping the above threads. These should be declared after
- // the corresponding threads to guarantee proper order of destruction.
- scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
- scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_;
- scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_;
- scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
- scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_;
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
+ // Thread for network operations.
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
+ // Caller-supplied UI thread. This is usually the application main thread.
scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
+ // Serves URLRequestContexts that use the network and UI task runners.
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext);
diff --git a/remoting/host/chromoting_host_context_unittest.cc b/remoting/host/chromoting_host_context_unittest.cc
index 3c3858e..7e1b251 100644
--- a/remoting/host/chromoting_host_context_unittest.cc
+++ b/remoting/host/chromoting_host_context_unittest.cc
@@ -3,7 +3,7 @@
// found in the LICENSE file.
#include "base/message_loop.h"
-#include "base/message_loop_proxy.h"
+#include "base/run_loop.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/host/chromoting_host_context.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,17 +14,25 @@ namespace remoting {
// operates properly and all threads and message loops are valid.
TEST(ChromotingHostContextTest, StartAndStop) {
MessageLoopForUI message_loop;
- ChromotingHostContext context(new AutoThreadTaskRunner(
- base::MessageLoopProxy::current()));
+ base::RunLoop run_loop;
- context.Start();
- EXPECT_TRUE(context.audio_task_runner());
- EXPECT_TRUE(context.video_capture_task_runner());
- EXPECT_TRUE(context.video_encode_task_runner());
- EXPECT_TRUE(context.file_task_runner());
- EXPECT_TRUE(context.input_task_runner());
- EXPECT_TRUE(context.network_task_runner());
- EXPECT_TRUE(context.ui_task_runner());
+ scoped_ptr<ChromotingHostContext> context =
+ ChromotingHostContext::Create(new AutoThreadTaskRunner(
+ message_loop.message_loop_proxy(), run_loop.QuitClosure()));
+
+ EXPECT_TRUE(context);
+ if (!context)
+ return;
+ EXPECT_TRUE(context->audio_task_runner());
+ EXPECT_TRUE(context->video_capture_task_runner());
+ EXPECT_TRUE(context->video_encode_task_runner());
+ EXPECT_TRUE(context->file_task_runner());
+ EXPECT_TRUE(context->input_task_runner());
+ EXPECT_TRUE(context->network_task_runner());
+ EXPECT_TRUE(context->ui_task_runner());
+
+ context.reset();
+ run_loop.Run();
}
} // namespace remoting
diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc
index b983f81..f593c2d 100644
--- a/remoting/host/chromoting_host_unittest.cc
+++ b/remoting/host/chromoting_host_unittest.cc
@@ -118,19 +118,6 @@ class ChromotingHostTest : public testing::Test {
base::Bind(&ChromotingHostTest::QuitMainMessageLoop,
base::Unretained(this)));
- EXPECT_CALL(context_, ui_task_runner())
- .Times(AnyNumber())
- .WillRepeatedly(Return(ui_task_runner_.get()));
- EXPECT_CALL(context_, capture_task_runner())
- .Times(AnyNumber())
- .WillRepeatedly(Return(ui_task_runner_.get()));
- EXPECT_CALL(context_, encode_task_runner())
- .Times(AnyNumber())
- .WillRepeatedly(Return(ui_task_runner_.get()));
- EXPECT_CALL(context_, network_task_runner())
- .Times(AnyNumber())
- .WillRepeatedly(Return(ui_task_runner_.get()));
-
desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
EXPECT_CALL(*desktop_environment_factory_, CreatePtr(_))
.Times(AnyNumber())
@@ -143,18 +130,17 @@ class ChromotingHostTest : public testing::Test {
&signal_strategy_,
desktop_environment_factory_.get(),
scoped_ptr<protocol::SessionManager>(session_manager_),
- context_.audio_task_runner(),
- context_.capture_task_runner(),
- context_.encode_task_runner(),
- context_.network_task_runner());
+ ui_task_runner_, // Audio
+ ui_task_runner_, // Video capture
+ ui_task_runner_, // Video encode
+ ui_task_runner_); // Network
host_->AddStatusObserver(&host_status_observer_);
disconnect_window_ = new MockDisconnectWindow();
continue_window_ = new MockContinueWindow();
local_input_monitor_ = new MockLocalInputMonitor();
it2me_host_user_interface_.reset(
- new MockIt2MeHostUserInterface(context_.network_task_runner(),
- context_.ui_task_runner()));
+ new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_));
it2me_host_user_interface_->InitFrom(
scoped_ptr<DisconnectWindow>(disconnect_window_),
scoped_ptr<ContinueWindow>(continue_window_),
@@ -250,10 +236,10 @@ class ChromotingHostTest : public testing::Test {
protocol::ConnectionToClient* connection_ptr = connection.get();
scoped_refptr<ClientSession> client = new ClientSession(
host_.get(),
- context_.audio_task_runner(),
- context_.capture_task_runner(),
- context_.encode_task_runner(),
- context_.network_task_runner(),
+ ui_task_runner_, // Audio
+ ui_task_runner_, // Video capture
+ ui_task_runner_, // Video encode
+ ui_task_runner_, // Network
connection.Pass(),
desktop_environment_factory_.get(),
base::TimeDelta());
@@ -261,22 +247,22 @@ class ChromotingHostTest : public testing::Test {
connection_ptr->set_input_stub(
client->desktop_environment()->event_executor());
- context_.network_task_runner()->PostTask(
+ ui_task_runner_->PostTask(
FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost,
host_, client));
if (authenticate) {
- context_.network_task_runner()->PostTask(
+ ui_task_runner_->PostTask(
FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated,
client, connection_ptr));
if (!reject) {
- context_.network_task_runner()->PostTask(
+ ui_task_runner_->PostTask(
FROM_HERE,
base::Bind(&ClientSession::OnConnectionChannelsConnected,
client, connection_ptr));
}
} else {
- context_.network_task_runner()->PostTask(
+ ui_task_runner_->PostTask(
FROM_HERE, base::Bind(&ClientSession::OnConnectionClosed,
client, connection_ptr,
protocol::AUTHENTICATION_FAILED));
@@ -443,7 +429,6 @@ class ChromotingHostTest : public testing::Test {
protected:
MessageLoop message_loop_;
scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
- MockChromotingHostContext context_;
MockConnectionToClientEventHandler handler_;
MockSignalStrategy signal_strategy_;
scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_;
diff --git a/remoting/host/desktop_environment_factory.cc b/remoting/host/desktop_environment_factory.cc
index f3299a9..71059e9 100644
--- a/remoting/host/desktop_environment_factory.cc
+++ b/remoting/host/desktop_environment_factory.cc
@@ -4,6 +4,7 @@
#include "remoting/host/desktop_environment_factory.h"
+#include "base/single_thread_task_runner.h"
#include "remoting/host/audio_capturer.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/client_session.h"
diff --git a/remoting/host/host_mock_objects.cc b/remoting/host/host_mock_objects.cc
index 32db03e..0c441c5 100644
--- a/remoting/host/host_mock_objects.cc
+++ b/remoting/host/host_mock_objects.cc
@@ -73,13 +73,6 @@ scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create() {
return scoped_ptr<LocalInputMonitor>(new MockLocalInputMonitor());
}
-MockChromotingHostContext::MockChromotingHostContext()
- : ChromotingHostContext(new AutoThreadTaskRunner(
- base::MessageLoopProxy::current())) {
-}
-
-MockChromotingHostContext::~MockChromotingHostContext() {}
-
MockClientSessionEventHandler::MockClientSessionEventHandler() {}
MockClientSessionEventHandler::~MockClientSessionEventHandler() {}
diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h
index 1fd3a41..5533ec5 100644
--- a/remoting/host/host_mock_objects.h
+++ b/remoting/host/host_mock_objects.h
@@ -85,23 +85,6 @@ class MockContinueWindow : public ContinueWindow {
MOCK_METHOD0(Hide, void());
};
-class MockChromotingHostContext : public ChromotingHostContext {
- public:
- MockChromotingHostContext();
- virtual ~MockChromotingHostContext();
-
- MOCK_METHOD0(Start, bool());
- MOCK_METHOD0(Stop, void());
- MOCK_METHOD0(ui_task_runner, base::SingleThreadTaskRunner*());
- MOCK_METHOD0(capture_task_runner, base::SingleThreadTaskRunner*());
- MOCK_METHOD0(encode_task_runner, base::SingleThreadTaskRunner*());
- MOCK_METHOD0(network_task_runner, base::SingleThreadTaskRunner*());
- MOCK_METHOD0(io_task_runner, base::SingleThreadTaskRunner*());
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockChromotingHostContext);
-};
-
class MockClientSessionEventHandler : public ClientSession::EventHandler {
public:
MockClientSessionEventHandler();
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index 7b82603..f7d84e7 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"
@@ -666,12 +666,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 +685,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 +953,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 +1058,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;
diff --git a/remoting/host/plugin/host_script_object.h b/remoting/host/plugin/host_script_object.h
index 5cc7a6d..22baee5 100644
--- a/remoting/host/plugin/host_script_object.h
+++ b/remoting/host/plugin/host_script_object.h
@@ -287,7 +287,7 @@ class HostNPScriptObject {
// TODO(sergeyu): Replace this thread with
// SequencedWorkerPool. Problem is that SequencedWorkerPool relies
// on MessageLoopProxy::current().
- base::Thread worker_thread_;
+ scoped_refptr<AutoThreadTaskRunner> worker_thread_;
//////////////////////////////////////////////////////////
// Plugin state used for both Ir2Me and Me2Me.
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index 47be4d8..773f4bb 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -1068,13 +1068,11 @@ int main(int argc, char** argv) {
// Create the main message loop and start helper threads.
MessageLoop message_loop(MessageLoop::TYPE_UI);
- base::Closure quit_message_loop = base::Bind(&QuitMessageLoop, &message_loop);
- scoped_ptr<remoting::ChromotingHostContext> context(
- new remoting::ChromotingHostContext(
+ scoped_ptr<remoting::ChromotingHostContext> context =
+ remoting::ChromotingHostContext::Create(
new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(),
- quit_message_loop)));
-
- if (!context->Start())
+ MessageLoop::QuitClosure()));
+ if (context)
return remoting::kInitializationFailed;
// Create & start the HostProcess using these threads.
diff --git a/remoting/host/win/session_desktop_environment_factory.cc b/remoting/host/win/session_desktop_environment_factory.cc
index 7a4e132..4a7306f 100644
--- a/remoting/host/win/session_desktop_environment_factory.cc
+++ b/remoting/host/win/session_desktop_environment_factory.cc
@@ -4,6 +4,7 @@
#include "remoting/host/win/session_desktop_environment_factory.h"
+#include "base/single_thread_task_runner.h"
#include "remoting/host/audio_capturer.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/client_session.h"