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 "components/policy/core/common/policy_service.h" |
8 | 8 #include "content/public/browser/browser_thread.h" |
9 #include "base/bind.h" | |
10 #include "remoting/base/auto_thread.h" | 9 #include "remoting/base/auto_thread.h" |
11 #include "remoting/base/url_request_context_getter.h" | 10 #include "remoting/base/url_request_context_getter.h" |
12 | 11 |
13 namespace remoting { | 12 namespace remoting { |
14 | 13 |
15 ChromotingHostContext::ChromotingHostContext( | 14 ChromotingHostContext::ChromotingHostContext( |
16 AutoThreadTaskRunner* ui_task_runner) | 15 AutoThreadTaskRunner* ui_task_runner) |
17 : ui_task_runner_(ui_task_runner) { | 16 : ui_task_runner_(ui_task_runner), policy_service_(NULL) { |
18 #if defined(OS_WIN) | |
19 // On Windows the AudioCapturer requires COM, so we run a single-threaded | |
20 // apartment, which requires a UI thread. | |
21 audio_task_runner_ = | |
22 AutoThread::CreateWithLoopAndComInitTypes("ChromotingAudioThread", | |
23 ui_task_runner_, | |
24 base::MessageLoop::TYPE_UI, | |
25 AutoThread::COM_INIT_STA); | |
26 #else // !defined(OS_WIN) | |
27 audio_task_runner_ = AutoThread::CreateWithType( | |
28 "ChromotingAudioThread", ui_task_runner_, base::MessageLoop::TYPE_IO); | |
29 #endif // !defined(OS_WIN) | |
30 | |
31 file_task_runner_ = AutoThread::CreateWithType( | |
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 } | 17 } |
45 | 18 |
46 ChromotingHostContext::~ChromotingHostContext() { | 19 ChromotingHostContext::~ChromotingHostContext() { |
47 } | 20 } |
48 | 21 |
22 // static | |
49 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create( | 23 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create( |
50 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) { | 24 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) { |
51 DCHECK(ui_task_runner->BelongsToCurrentThread()); | |
52 | |
53 scoped_ptr<ChromotingHostContext> context( | 25 scoped_ptr<ChromotingHostContext> context( |
54 new ChromotingHostContext(ui_task_runner.get())); | 26 new ChromotingHostContext(ui_task_runner.get())); |
55 if (!context->audio_task_runner_.get() || !context->file_task_runner_.get() || | 27 |
56 !context->input_task_runner_.get() || | 28 #if defined(OS_WIN) |
57 !context->network_task_runner_.get() || | 29 // On Windows the AudioCapturer requires COM, so we run a single-threaded |
58 !context->video_capture_task_runner_.get() || | 30 // apartment, which requires a UI thread. |
59 !context->video_encode_task_runner_.get() || | 31 context->audio_task_runner_ = |
60 !context->url_request_context_getter_.get()) { | 32 AutoThread::CreateWithLoopAndComInitTypes("ChromotingAudioThread", |
33 ui_task_runner, | |
34 base::MessageLoop::TYPE_UI, | |
35 AutoThread::COM_INIT_STA); | |
36 #else // !defined(OS_WIN) | |
37 context->audio_task_runner_ = AutoThread::CreateWithType( | |
Jamie
2014/10/14 01:18:41
This code reads a lot like a ctor. Could you add e
kelvinp
2014/10/15 23:03:09
I spoke to wez. He suggested instead of joining o
| |
38 "ChromotingAudioThread", ui_task_runner, base::MessageLoop::TYPE_IO); | |
39 #endif // !defined(OS_WIN) | |
40 | |
41 context->file_task_runner_ = AutoThread::CreateWithType( | |
42 "ChromotingFileThread", ui_task_runner, base::MessageLoop::TYPE_IO); | |
43 context->input_task_runner_ = AutoThread::CreateWithType( | |
44 "ChromotingInputThread", ui_task_runner, base::MessageLoop::TYPE_IO); | |
45 context->network_task_runner_ = AutoThread::CreateWithType( | |
46 "ChromotingNetworkThread", ui_task_runner, base::MessageLoop::TYPE_IO); | |
47 context->video_capture_task_runner_ = | |
48 AutoThread::Create("ChromotingCaptureThread", ui_task_runner); | |
49 context->video_encode_task_runner_ = AutoThread::Create( | |
50 "ChromotingEncodeThread", ui_task_runner); | |
51 | |
52 context->url_request_context_getter_ = new URLRequestContextGetter( | |
53 context->network_task_runner_, context->file_task_runner_); | |
54 | |
55 if (!context->VerifyInitialized()) { | |
61 context.reset(); | 56 context.reset(); |
62 } | 57 } |
63 | 58 |
64 return context.Pass(); | 59 return context.Pass(); |
65 } | 60 } |
66 | 61 |
62 namespace { | |
63 // Retrieves the task_runner from the browser thread with |id|. Must be called | |
64 // on the UI thread of the browser process. | |
Jamie
2014/10/14 01:18:41
This comment implies that CreateOnChromeOS must al
kelvinp
2014/10/15 23:03:09
Done.
| |
65 AutoThreadTaskRunner* GetTaskRunner(content::BrowserThread::ID id) { | |
66 #if defined(OS_CHROMEOS) | |
67 return new AutoThreadTaskRunner( | |
68 content::BrowserThread::GetMessageLoopProxyForThread(id).get(), | |
69 base::Bind(&base::DoNothing)); | |
70 #else | |
71 NOTIMPLEMENTED(); | |
72 return nullptr; | |
73 #endif // !defined(OS_CHROMEOS) | |
74 } | |
75 | |
76 } // namespace | |
77 | |
78 // static | |
79 scoped_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS( | |
80 scoped_refptr<AutoThreadTaskRunner> ui_task_runner, | |
81 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | |
82 policy::PolicyService* policy_service) { | |
83 DCHECK(url_request_context_getter.get()); | |
84 DCHECK(policy_service); | |
85 | |
86 scoped_ptr<ChromotingHostContext> context( | |
87 new ChromotingHostContext(ui_task_runner.get())); | |
88 // Thread assignments and re-using existing browser sources | |
89 // (URLRequestContextGetter) must be performed on the UI thread of the | |
90 // browser process. | |
91 context->file_task_runner_ = GetTaskRunner(content::BrowserThread::FILE); | |
92 context->network_task_runner_ = GetTaskRunner(content::BrowserThread::IO); | |
93 context->video_capture_task_runner_ = | |
94 GetTaskRunner(content::BrowserThread::UI); | |
95 | |
96 context->url_request_context_getter_ = url_request_context_getter; | |
97 | |
98 // Thread joining is blocking and it can only be done on threads that allows | |
Jamie
2014/10/14 01:18:41
s/allows/allow/
kelvinp
2014/10/15 23:03:09
Done.
| |
99 // blocking I/O. Uses the |file_task_runner| as the joiner. | |
100 context->input_task_runner_ = | |
101 AutoThread::CreateWithType("ChromotingInputThread", | |
102 context->file_task_runner_, | |
103 base::MessageLoop::TYPE_IO); | |
104 context->audio_task_runner_ = | |
105 AutoThread::CreateWithType("ChromotingAudioThread", | |
106 context->file_task_runner_, | |
107 base::MessageLoop::TYPE_IO); | |
108 context->video_encode_task_runner_ = | |
109 AutoThread::Create("ChromotingEncodeThread", context->file_task_runner_); | |
110 | |
111 context->policy_service_ = policy_service; | |
112 | |
113 if (!context->VerifyInitialized()) { | |
114 context.reset(); | |
115 } | |
116 | |
117 return context.Pass(); | |
118 } | |
119 | |
120 bool ChromotingHostContext::VerifyInitialized() { | |
121 return audio_task_runner_.get() && file_task_runner_.get() && | |
122 input_task_runner_.get() && network_task_runner_.get() && | |
123 video_capture_task_runner_.get() && video_encode_task_runner_.get() && | |
124 url_request_context_getter_.get(); | |
125 } | |
126 | |
67 scoped_refptr<AutoThreadTaskRunner> | 127 scoped_refptr<AutoThreadTaskRunner> |
68 ChromotingHostContext::audio_task_runner() { | 128 ChromotingHostContext::audio_task_runner() { |
69 return audio_task_runner_; | 129 return audio_task_runner_; |
70 } | 130 } |
71 | 131 |
72 scoped_refptr<AutoThreadTaskRunner> | 132 scoped_refptr<AutoThreadTaskRunner> |
73 ChromotingHostContext::file_task_runner() { | 133 ChromotingHostContext::file_task_runner() { |
74 return file_task_runner_; | 134 return file_task_runner_; |
75 } | 135 } |
76 | 136 |
(...skipping 20 matching lines...) Expand all Loading... | |
97 scoped_refptr<AutoThreadTaskRunner> | 157 scoped_refptr<AutoThreadTaskRunner> |
98 ChromotingHostContext::video_encode_task_runner() { | 158 ChromotingHostContext::video_encode_task_runner() { |
99 return video_encode_task_runner_; | 159 return video_encode_task_runner_; |
100 } | 160 } |
101 | 161 |
102 scoped_refptr<net::URLRequestContextGetter> | 162 scoped_refptr<net::URLRequestContextGetter> |
103 ChromotingHostContext::url_request_context_getter() { | 163 ChromotingHostContext::url_request_context_getter() { |
104 return url_request_context_getter_; | 164 return url_request_context_getter_; |
105 } | 165 } |
106 | 166 |
167 policy::PolicyService* ChromotingHostContext::policy_service() { | |
168 return policy_service_; | |
169 } | |
170 | |
107 } // namespace remoting | 171 } // namespace remoting |
OLD | NEW |