Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: remoting/host/chromoting_host_context.cc

Issue 10829467: [Chromoting] Introducing refcount-based life time management of the message loops in the service (d… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/chromoting_host_context.h ('k') | remoting/host/chromoting_host_context_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/chromoting_host_context.cc
diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc
index b1105676cfd743ba251712d83e8deb446428ec65..3aa26af5c30607401d3b58342cd0033c0aec1f84 100644
--- a/remoting/host/chromoting_host_context.cc
+++ b/remoting/host/chromoting_host_context.cc
@@ -8,24 +8,36 @@
#include "base/bind.h"
#include "base/threading/thread.h"
+#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/host/url_request_context.h"
namespace remoting {
ChromotingHostContext::ChromotingHostContext(
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
- : network_thread_("ChromotingNetworkThread"),
+ scoped_refptr<AutoThreadTaskRunner> ui_task_runner)
+ : audio_thread_("ChromotingAudioThread"),
capture_thread_("ChromotingCaptureThread"),
- encode_thread_("ChromotingEncodeThread"),
- audio_thread_("ChromotingAudioThread"),
desktop_thread_("ChromotingDesktopThread"),
+ encode_thread_("ChromotingEncodeThread"),
file_thread_("ChromotingFileIOThread"),
+ network_thread_("ChromotingNetworkThread"),
ui_task_runner_(ui_task_runner) {
}
ChromotingHostContext::~ChromotingHostContext() {
}
+void ChromotingHostContext::ReleaseTaskRunners() {
+ url_request_context_getter_ = NULL;
+ audio_task_runner_ = NULL;
+ capture_task_runner_ = NULL;
+ desktop_task_runner_ = NULL;
+ encode_task_runner_ = NULL;
+ file_task_runner_ = NULL;
+ network_task_runner_ = NULL;
+ ui_task_runner_ = NULL;
+}
+
bool ChromotingHostContext::Start() {
// Start all the threads.
bool started = capture_thread_.Start() && encode_thread_.Start() &&
@@ -39,40 +51,62 @@ bool ChromotingHostContext::Start() {
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_);
+ capture_task_runner_ =
+ new AutoThreadTaskRunner(capture_thread_.message_loop_proxy(),
+ ui_task_runner_);
+ desktop_task_runner_ =
+ new AutoThreadTaskRunner(desktop_thread_.message_loop_proxy(),
+ ui_task_runner_);
+ encode_task_runner_ =
+ new AutoThreadTaskRunner(encode_thread_.message_loop_proxy(),
+ ui_task_runner_);
+ file_task_runner_ =
+ new AutoThreadTaskRunner(file_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(),
static_cast<MessageLoopForIO*>(file_thread_.message_loop()));
return true;
}
+base::SingleThreadTaskRunner* ChromotingHostContext::audio_task_runner() {
+ return audio_task_runner_;
+}
+
base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() {
- return capture_thread_.message_loop_proxy();
+ return capture_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() {
- return encode_thread_.message_loop_proxy();
+base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() {
+ return desktop_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::audio_task_runner() {
- return audio_thread_.message_loop_proxy();
+base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() {
+ return encode_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() {
- return network_thread_.message_loop_proxy();
+base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() {
+ return file_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() {
- return desktop_thread_.message_loop_proxy();
+base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() {
+ return network_task_runner_;
}
base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() {
return ui_task_runner_;
}
-base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() {
- return file_thread_.message_loop_proxy();
-}
-
const scoped_refptr<net::URLRequestContextGetter>&
ChromotingHostContext::url_request_context_getter() {
DCHECK(url_request_context_getter_.get());
« no previous file with comments | « remoting/host/chromoting_host_context.h ('k') | remoting/host/chromoting_host_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698