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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/chromoting_host_context.h" 5 #include "remoting/host/chromoting_host_context.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "remoting/base/auto_thread_task_runner.h"
11 #include "remoting/host/url_request_context.h" 12 #include "remoting/host/url_request_context.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 15
15 ChromotingHostContext::ChromotingHostContext( 16 ChromotingHostContext::ChromotingHostContext(
16 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) 17 scoped_refptr<AutoThreadTaskRunner> ui_task_runner)
17 : network_thread_("ChromotingNetworkThread"), 18 : audio_thread_("ChromotingAudioThread"),
18 capture_thread_("ChromotingCaptureThread"), 19 capture_thread_("ChromotingCaptureThread"),
20 desktop_thread_("ChromotingDesktopThread"),
19 encode_thread_("ChromotingEncodeThread"), 21 encode_thread_("ChromotingEncodeThread"),
20 audio_thread_("ChromotingAudioThread"),
21 desktop_thread_("ChromotingDesktopThread"),
22 file_thread_("ChromotingFileIOThread"), 22 file_thread_("ChromotingFileIOThread"),
23 network_thread_("ChromotingNetworkThread"),
23 ui_task_runner_(ui_task_runner) { 24 ui_task_runner_(ui_task_runner) {
24 } 25 }
25 26
26 ChromotingHostContext::~ChromotingHostContext() { 27 ChromotingHostContext::~ChromotingHostContext() {
27 } 28 }
28 29
30 void ChromotingHostContext::ReleaseTaskRunners() {
31 url_request_context_getter_ = NULL;
32 audio_task_runner_ = NULL;
33 capture_task_runner_ = NULL;
34 desktop_task_runner_ = NULL;
35 encode_task_runner_ = NULL;
36 file_task_runner_ = NULL;
37 network_task_runner_ = NULL;
38 ui_task_runner_ = NULL;
39 }
40
29 bool ChromotingHostContext::Start() { 41 bool ChromotingHostContext::Start() {
30 // Start all the threads. 42 // Start all the threads.
31 bool started = capture_thread_.Start() && encode_thread_.Start() && 43 bool started = capture_thread_.Start() && encode_thread_.Start() &&
32 audio_thread_.StartWithOptions(base::Thread::Options( 44 audio_thread_.StartWithOptions(base::Thread::Options(
33 MessageLoop::TYPE_IO, 0)) && 45 MessageLoop::TYPE_IO, 0)) &&
34 network_thread_.StartWithOptions(base::Thread::Options( 46 network_thread_.StartWithOptions(base::Thread::Options(
35 MessageLoop::TYPE_IO, 0)) && 47 MessageLoop::TYPE_IO, 0)) &&
36 desktop_thread_.Start() && 48 desktop_thread_.Start() &&
37 file_thread_.StartWithOptions( 49 file_thread_.StartWithOptions(
38 base::Thread::Options(MessageLoop::TYPE_IO, 0)); 50 base::Thread::Options(MessageLoop::TYPE_IO, 0));
39 if (!started) 51 if (!started)
40 return false; 52 return false;
41 53
54 // Wrap worker threads with |AutoThreadTaskRunner| and have them reference
55 // the main thread via |ui_task_runner_|, to ensure that it remain active to
56 // Stop() them when no references remain.
57 audio_task_runner_ =
58 new AutoThreadTaskRunner(audio_thread_.message_loop_proxy(),
59 ui_task_runner_);
60 capture_task_runner_ =
61 new AutoThreadTaskRunner(capture_thread_.message_loop_proxy(),
62 ui_task_runner_);
63 desktop_task_runner_ =
64 new AutoThreadTaskRunner(desktop_thread_.message_loop_proxy(),
65 ui_task_runner_);
66 encode_task_runner_ =
67 new AutoThreadTaskRunner(encode_thread_.message_loop_proxy(),
68 ui_task_runner_);
69 file_task_runner_ =
70 new AutoThreadTaskRunner(file_thread_.message_loop_proxy(),
71 ui_task_runner_);
72
73 network_task_runner_ =
74 new AutoThreadTaskRunner(network_thread_.message_loop_proxy(),
75 ui_task_runner_);
42 url_request_context_getter_ = new URLRequestContextGetter( 76 url_request_context_getter_ = new URLRequestContextGetter(
43 ui_task_runner(), network_task_runner(), 77 ui_task_runner(), network_task_runner(),
44 static_cast<MessageLoopForIO*>(file_thread_.message_loop())); 78 static_cast<MessageLoopForIO*>(file_thread_.message_loop()));
45 return true; 79 return true;
46 } 80 }
47 81
82 base::SingleThreadTaskRunner* ChromotingHostContext::audio_task_runner() {
83 return audio_task_runner_;
84 }
85
48 base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() { 86 base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() {
49 return capture_thread_.message_loop_proxy(); 87 return capture_task_runner_;
88 }
89
90 base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() {
91 return desktop_task_runner_;
50 } 92 }
51 93
52 base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() { 94 base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() {
53 return encode_thread_.message_loop_proxy(); 95 return encode_task_runner_;
54 } 96 }
55 97
56 base::SingleThreadTaskRunner* ChromotingHostContext::audio_task_runner() { 98 base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() {
57 return audio_thread_.message_loop_proxy(); 99 return file_task_runner_;
58 } 100 }
59 101
60 base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() { 102 base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() {
61 return network_thread_.message_loop_proxy(); 103 return network_task_runner_;
62 }
63
64 base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() {
65 return desktop_thread_.message_loop_proxy();
66 } 104 }
67 105
68 base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() { 106 base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() {
69 return ui_task_runner_; 107 return ui_task_runner_;
70 } 108 }
71 109
72 base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() {
73 return file_thread_.message_loop_proxy();
74 }
75
76 const scoped_refptr<net::URLRequestContextGetter>& 110 const scoped_refptr<net::URLRequestContextGetter>&
77 ChromotingHostContext::url_request_context_getter() { 111 ChromotingHostContext::url_request_context_getter() {
78 DCHECK(url_request_context_getter_.get()); 112 DCHECK(url_request_context_getter_.get());
79 return url_request_context_getter_; 113 return url_request_context_getter_;
80 } 114 }
81 115
82 } // namespace remoting 116 } // namespace remoting
OLDNEW
« 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