OLD | NEW |
---|---|
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 Loading... | |
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> network_task_runner = | |
100 AutoThread::CreateWithType("ChromotingNetworkThread", ui_task_runner, | |
101 base::MessageLoop::TYPE_IO); | |
102 | |
103 return make_scoped_ptr(new ChromotingHostContext( | |
104 ui_task_runner, | |
105 audio_task_runner, | |
106 file_task_runner, | |
107 AutoThread::CreateWithType("ChromotingInputThread", ui_task_runner, | |
108 base::MessageLoop::TYPE_IO), | |
109 network_task_runner, | |
110 AutoThread::Create("ChromotingCaptureThread", ui_task_runner), | |
111 AutoThread::Create("ChromotingEncodeThread", ui_task_runner), | |
112 make_scoped_refptr( | |
113 new URLRequestContextGetter(network_task_runner, file_task_runner)))); | |
114 } | |
115 | |
116 #if defined(OS_CHROMEOS) | |
117 namespace { | |
118 // Retrieves the task_runner from the browser thread with |id|. | |
119 scoped_refptr<AutoThreadTaskRunner> WrapBrowserThread( | |
120 content::BrowserThread::ID id) { | |
121 // This is a hack. AutoThreadTaskRunner is a TaskRunner with the special | |
Wez
2014/10/29 18:27:51
nit: Remove "This is a hack"
kelvinp
2014/10/29 22:20:17
Done.
| |
122 // property that it will continue to process tasks until no references remain, | |
123 // at least. The QuitClosure we usually pass does the simple thing of stopping | |
124 // the underlying TaskRunner. Since we are re-using the ui_task_runner of the | |
125 // browser thread, we cannot stop it explicitly. Therefore, base::DoNothing | |
126 // is passed in as the quit closure. | |
127 // TODO(kelvinp): Remove the hack (See crbug.com/428187). | |
Wez
2014/10/29 18:27:50
Suggest: Remove... -> Fix this.
kelvinp
2014/10/29 22:20:16
Done.
| |
128 return new AutoThreadTaskRunner( | |
129 content::BrowserThread::GetMessageLoopProxyForThread(id).get(), | |
130 base::Bind(&base::DoNothing)); | |
131 } | |
132 | |
133 } // namespace | |
134 | |
135 // static | |
136 scoped_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS( | |
137 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) { | |
138 DCHECK(url_request_context_getter.get()); | |
139 | |
140 // Use BrowserThread::FILE as the joiner as it is the only browser-thread | |
141 // that allows blocking I/O, which is required by thread joining. | |
142 scoped_refptr<AutoThreadTaskRunner> file_task_runner = | |
143 WrapBrowserThread(content::BrowserThread::FILE); | |
Wez
2014/10/29 18:27:50
Add a reference to the bug for fixing AutoThread s
kelvinp
2014/10/29 22:20:16
Done.
| |
144 | |
145 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = | |
146 WrapBrowserThread(content::BrowserThread::UI); | |
147 | |
148 return make_scoped_ptr(new ChromotingHostContext( | |
149 ui_task_runner, | |
150 AutoThread::CreateWithType("ChromotingAudioThread", file_task_runner, | |
151 base::MessageLoop::TYPE_IO), | |
152 file_task_runner, | |
153 AutoThread::CreateWithType("ChromotingInputThread", file_task_runner, | |
154 base::MessageLoop::TYPE_IO), | |
155 WrapBrowserThread(content::BrowserThread::IO), // network_task_runner | |
156 ui_task_runner, // video_capture_task_runner | |
157 AutoThread::CreateWithType("ChromotingEncodeThread", file_task_runner, | |
158 base::MessageLoop::TYPE_IO), | |
159 url_request_context_getter)); | |
160 } | |
161 #endif // defined(OS_CHROMEOS) | |
162 | |
107 } // namespace remoting | 163 } // namespace remoting |
OLD | NEW |