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

Side by Side Diff: remoting/host/chromoting_host_context.cc

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ChromotingHostContext cleanup Created 6 years, 1 month 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
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 "content/public/browser/browser_thread.h"
8
9 #include "base/bind.h"
10 #include "remoting/base/auto_thread.h" 8 #include "remoting/base/auto_thread.h"
11 #include "remoting/base/url_request_context_getter.h" 9 #include "remoting/base/url_request_context_getter.h"
12 10
13 namespace remoting { 11 namespace remoting {
14 12
15 ChromotingHostContext::ChromotingHostContext( 13 ChromotingHostContext::ChromotingHostContext(
16 AutoThreadTaskRunner* ui_task_runner) 14 scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
17 : ui_task_runner_(ui_task_runner) { 15 scoped_refptr<AutoThreadTaskRunner> audio_task_runner,
18 #if defined(OS_WIN) 16 scoped_refptr<AutoThreadTaskRunner> file_task_runner,
19 // On Windows the AudioCapturer requires COM, so we run a single-threaded 17 scoped_refptr<AutoThreadTaskRunner> input_task_runner,
20 // apartment, which requires a UI thread. 18 scoped_refptr<AutoThreadTaskRunner> network_task_runner,
21 audio_task_runner_ = 19 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner,
22 AutoThread::CreateWithLoopAndComInitTypes("ChromotingAudioThread", 20 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner,
23 ui_task_runner_, 21 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
24 base::MessageLoop::TYPE_UI, 22 : ui_task_runner_(ui_task_runner),
25 AutoThread::COM_INIT_STA); 23 audio_task_runner_(audio_task_runner),
26 #else // !defined(OS_WIN) 24 file_task_runner_(file_task_runner),
27 audio_task_runner_ = AutoThread::CreateWithType( 25 input_task_runner_(input_task_runner),
28 "ChromotingAudioThread", ui_task_runner_, base::MessageLoop::TYPE_IO); 26 network_task_runner_(network_task_runner),
29 #endif // !defined(OS_WIN) 27 video_capture_task_runner_(video_capture_task_runner),
30 28 video_encode_task_runner_(video_encode_task_runner),
31 file_task_runner_ = AutoThread::CreateWithType( 29 url_request_context_getter_(url_request_context_getter) {
32 "ChromotingFileThread", ui_task_runner_, base::MessageLoop::TYPE_IO);
33 input_task_runner_ = AutoThread::CreateWithType(
34 "ChromotingInputThread", ui_task_runner_, base::MessageLoop::TYPE_IO);
35 network_task_runner_ = AutoThread::CreateWithType(
36 "ChromotingNetworkThread", ui_task_runner_, base::MessageLoop::TYPE_IO);
37 video_capture_task_runner_ =
38 AutoThread::Create("ChromotingCaptureThread", ui_task_runner_);
39 video_encode_task_runner_ = AutoThread::Create(
40 "ChromotingEncodeThread", ui_task_runner_);
41
42 url_request_context_getter_ = new URLRequestContextGetter(
43 network_task_runner_, file_task_runner_);
44 } 30 }
45 31
46 ChromotingHostContext::~ChromotingHostContext() { 32 ChromotingHostContext::~ChromotingHostContext() {
47 } 33 }
48 34
49 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create( 35 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Copy() {
50 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) { 36 return make_scoped_ptr(new ChromotingHostContext(
51 DCHECK(ui_task_runner->BelongsToCurrentThread()); 37 ui_task_runner_, audio_task_runner_, file_task_runner_,
52 38 input_task_runner_, network_task_runner_, video_capture_task_runner_,
53 scoped_ptr<ChromotingHostContext> context( 39 video_encode_task_runner_, url_request_context_getter_));
54 new ChromotingHostContext(ui_task_runner.get()));
55 if (!context->audio_task_runner_.get() || !context->file_task_runner_.get() ||
56 !context->input_task_runner_.get() ||
57 !context->network_task_runner_.get() ||
58 !context->video_capture_task_runner_.get() ||
59 !context->video_encode_task_runner_.get() ||
60 !context->url_request_context_getter_.get()) {
61 context.reset();
62 }
63
64 return context.Pass();
65 } 40 }
66 41
67 scoped_refptr<AutoThreadTaskRunner> 42 scoped_refptr<AutoThreadTaskRunner>
68 ChromotingHostContext::audio_task_runner() { 43 ChromotingHostContext::audio_task_runner() {
69 return audio_task_runner_; 44 return audio_task_runner_;
70 } 45 }
71 46
72 scoped_refptr<AutoThreadTaskRunner> 47 scoped_refptr<AutoThreadTaskRunner>
73 ChromotingHostContext::file_task_runner() { 48 ChromotingHostContext::file_task_runner() {
74 return file_task_runner_; 49 return file_task_runner_;
(...skipping 22 matching lines...) Expand all
97 scoped_refptr<AutoThreadTaskRunner> 72 scoped_refptr<AutoThreadTaskRunner>
98 ChromotingHostContext::video_encode_task_runner() { 73 ChromotingHostContext::video_encode_task_runner() {
99 return video_encode_task_runner_; 74 return video_encode_task_runner_;
100 } 75 }
101 76
102 scoped_refptr<net::URLRequestContextGetter> 77 scoped_refptr<net::URLRequestContextGetter>
103 ChromotingHostContext::url_request_context_getter() { 78 ChromotingHostContext::url_request_context_getter() {
104 return url_request_context_getter_; 79 return url_request_context_getter_;
105 } 80 }
106 81
82 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create(
83 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) {
84 #if defined(OS_WIN)
85 // On Windows the AudioCapturer requires COM, so we run a single-threaded
86 // apartment, which requires a UI thread.
87 scoped_refptr<AutoThreadTaskRunner> audio_task_runner =
88 AutoThread::CreateWithLoopAndComInitTypes(
89 "ChromotingAudioThread", ui_task_runner, base::MessageLoop::TYPE_UI,
90 AutoThread::COM_INIT_STA);
91 #else // !defined(OS_WIN)
92 scoped_refptr<AutoThreadTaskRunner> audio_task_runner =
93 AutoThread::CreateWithType("ChromotingAudioThread", ui_task_runner,
94 base::MessageLoop::TYPE_IO);
95 #endif // !defined(OS_WIN)
96 scoped_refptr<AutoThreadTaskRunner> file_task_runner =
97 AutoThread::CreateWithType("ChromotingFileThread", ui_task_runner,
98 base::MessageLoop::TYPE_IO);
99 scoped_refptr<AutoThreadTaskRunner> input_task_runner =
100 AutoThread::CreateWithType("ChromotingInputThread", ui_task_runner,
101 base::MessageLoop::TYPE_IO);
102 scoped_refptr<AutoThreadTaskRunner> network_task_runner =
103 AutoThread::CreateWithType("ChromotingNetworkThread", ui_task_runner,
104 base::MessageLoop::TYPE_IO);
105 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner =
106 AutoThread::Create("ChromotingCaptureThread", ui_task_runner);
107 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
108 new URLRequestContextGetter(network_task_runner, file_task_runner);
109 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner =
110 AutoThread::Create("ChromotingEncodeThread", ui_task_runner);
111
112 return make_scoped_ptr(new ChromotingHostContext(
113 ui_task_runner, audio_task_runner, file_task_runner, input_task_runner,
114 network_task_runner, video_capture_task_runner, video_encode_task_runner,
115 url_request_context_getter));
Wez 2014/10/24 00:28:48 nit: Rather than create them all in temporaries an
kelvinp 2014/10/24 21:39:41 Done.
116 }
117
118 #if defined(OS_CHROMEOS)
119 namespace {
120 // Retrieves the task_runner from the browser thread with |id|. Must be called
121 // on the UI thread of the browser process.
Wez 2014/10/24 00:28:47 nit: the latter is a req of the GetMessageLoopProx
kelvinp 2014/10/24 21:39:41 Done.
122 AutoThreadTaskRunner* GetTaskRunner(content::BrowserThread::ID id) {
123 return new AutoThreadTaskRunner(
124 content::BrowserThread::GetMessageLoopProxyForThread(id).get(),
125 base::Bind(&base::DoNothing));
Wez 2014/10/24 00:28:47 nit: add brief comment explaining the issue w/ usi
kelvinp 2014/10/24 21:39:41 Done.
126 }
127
128 } // namespace
129
130 // static
131 scoped_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS(
132 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
133 DCHECK(url_request_context_getter.get());
134
135 scoped_refptr<AutoThreadTaskRunner> ui_task_runner =
136 GetTaskRunner(content::BrowserThread::UI);
137 scoped_refptr<AutoThreadTaskRunner> file_task_runner =
138 GetTaskRunner(content::BrowserThread::FILE);
139 scoped_refptr<AutoThreadTaskRunner> network_task_runner =
140 GetTaskRunner(content::BrowserThread::IO);
141 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner =
142 GetTaskRunner(content::BrowserThread::UI);
143
144 // Use the |file_task_runner| as the joiner as it is the only browser-thread
145 // that allows blocking I/O, which is required by thread joining.
Wez 2014/10/24 00:28:48 I thought we had fixed AutoThread?
kelvinp 2014/10/24 21:39:41 Close but not yet. We agreed to separate that in
Wez 2014/10/24 23:29:26 I meant land that separate CL so you don't need to
kelvinp 2014/10/29 01:22:51 I will create a separate CL.
146 scoped_refptr<AutoThreadTaskRunner> audio_task_runner =
147 AutoThread::CreateWithType("ChromotingAudioThread", file_task_runner,
148 base::MessageLoop::TYPE_IO);
149 scoped_refptr<AutoThreadTaskRunner> input_task_runner =
150 AutoThread::CreateWithType("ChromotingInputThread", file_task_runner,
151 base::MessageLoop::TYPE_IO);
152 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner =
153 AutoThread::CreateWithType("ChromotingEncodeThread", file_task_runner,
154 base::MessageLoop::TYPE_IO);
155
156 return make_scoped_ptr(new ChromotingHostContext(
157 ui_task_runner, audio_task_runner, file_task_runner, input_task_runner,
158 network_task_runner,
159 ui_task_runner, // |video_capture_task_runner|
160 video_encode_task_runner, url_request_context_getter));
Wez 2014/10/24 00:28:48 More readable to have one line per task-runner her
kelvinp 2014/10/24 21:39:41 Done.
161 }
162 #endif // defined(OS_CHROMEOS)
163
107 } // namespace remoting 164 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698