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

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: Address feedbacks Created 6 years, 2 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
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 "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 AutoThreadTaskRunner* file_task_runner,
17 AutoThreadTaskRunner* input_task_runner,
18 AutoThreadTaskRunner* network_task_runner,
19 AutoThreadTaskRunner* video_capture_task_runner,
20 net::URLRequestContextGetter* url_request_context_getter,
21 policy::PolicyService* policy_service)
22 : ui_task_runner_(ui_task_runner),
23 file_task_runner_(file_task_runner),
24 input_task_runner_(input_task_runner),
25 network_task_runner_(network_task_runner),
26 video_capture_task_runner_(video_capture_task_runner),
27 url_request_context_getter_(url_request_context_getter),
28 policy_service_(policy_service) {
29
18 #if defined(OS_WIN) 30 #if defined(OS_WIN)
19 // On Windows the AudioCapturer requires COM, so we run a single-threaded 31 // On Windows the AudioCapturer requires COM, so we run a single-threaded
20 // apartment, which requires a UI thread. 32 // apartment, which requires a UI thread.
21 audio_task_runner_ = 33 audio_task_runner_ =
22 AutoThread::CreateWithLoopAndComInitTypes("ChromotingAudioThread", 34 AutoThread::CreateWithLoopAndComInitTypes("ChromotingAudioThread",
23 ui_task_runner_, 35 ui_task_runner,
24 base::MessageLoop::TYPE_UI, 36 base::MessageLoop::TYPE_UI,
25 AutoThread::COM_INIT_STA); 37 AutoThread::COM_INIT_STA);
26 #else // !defined(OS_WIN) 38 #else // !defined(OS_WIN)
27 audio_task_runner_ = AutoThread::CreateWithType( 39 audio_task_runner_ = AutoThread::CreateWithType(
28 "ChromotingAudioThread", ui_task_runner_, base::MessageLoop::TYPE_IO); 40 "ChromotingAudioThread", ui_task_runner, base::MessageLoop::TYPE_IO);
29 #endif // !defined(OS_WIN) 41 #endif // !defined(OS_WIN)
30 42 video_encode_task_runner_ =
31 file_task_runner_ = AutoThread::CreateWithType( 43 AutoThread::Create("ChromotingEncodeThread", ui_task_runner);
Wez 2014/10/17 17:58:00 It's strange to have some of the task runners pass
kelvinp 2014/10/20 00:21:16 Done.
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 } 44 }
45 45
46 ChromotingHostContext::~ChromotingHostContext() { 46 ChromotingHostContext::~ChromotingHostContext() {
47 } 47 }
48 48
49 // static
49 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create( 50 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create(
50 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) { 51 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) {
51 DCHECK(ui_task_runner->BelongsToCurrentThread()); 52 scoped_refptr<AutoThreadTaskRunner> file_task_runner =
53 AutoThread::CreateWithType(
54 "ChromotingFileThread", ui_task_runner, base::MessageLoop::TYPE_IO);
55 scoped_refptr<AutoThreadTaskRunner> input_task_runner =
56 AutoThread::CreateWithType(
57 "ChromotingInputThread", ui_task_runner, base::MessageLoop::TYPE_IO);
58 scoped_refptr<AutoThreadTaskRunner> network_task_runner =
59 AutoThread::CreateWithType("ChromotingNetworkThread",
60 ui_task_runner,
61 base::MessageLoop::TYPE_IO);
62 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner =
63 AutoThread::Create("ChromotingCaptureThread", ui_task_runner);
64 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
65 new URLRequestContextGetter(network_task_runner, file_task_runner);
52 66
53 scoped_ptr<ChromotingHostContext> context( 67 scoped_ptr<ChromotingHostContext> context(
54 new ChromotingHostContext(ui_task_runner.get())); 68 new ChromotingHostContext(ui_task_runner.get(),
Wez 2014/10/17 17:58:00 Don't use .get() here.
kelvinp 2014/10/20 00:21:16 Done.
55 if (!context->audio_task_runner_.get() || !context->file_task_runner_.get() || 69 file_task_runner.get(),
56 !context->input_task_runner_.get() || 70 input_task_runner.get(),
57 !context->network_task_runner_.get() || 71 network_task_runner.get(),
58 !context->video_capture_task_runner_.get() || 72 video_capture_task_runner.get(),
59 !context->video_encode_task_runner_.get() || 73 url_request_context_getter.get(),
60 !context->url_request_context_getter_.get()) { 74 NULL));
75
76 if (!context->VerifyInitialized()) {
61 context.reset(); 77 context.reset();
62 } 78 }
63 79
64 return context.Pass(); 80 return context.Pass();
65 } 81 }
66 82
83 namespace {
Wez 2014/10/17 17:58:00 Since this is a single function definition, use st
kelvinp 2014/10/20 00:21:16 What is the benefits of using a single function de
84 // Retrieves the task_runner from the browser thread with |id|. Must be called
85 // on the UI thread of the browser process.
86 AutoThreadTaskRunner* GetTaskRunner(content::BrowserThread::ID id) {
87 #if defined(OS_CHROMEOS)
Wez 2014/10/17 17:58:00 Why not #ifdef# the entire contents of CreateForCh
kelvinp 2014/10/20 00:21:16 I have moved the chromeos factory to a separate fi
88 return new AutoThreadTaskRunner(
89 content::BrowserThread::GetMessageLoopProxyForThread(id).get(),
90 base::Bind(&base::DoNothing));
91 #else
92 NOTIMPLEMENTED();
93 return nullptr;
94 #endif // !defined(OS_CHROMEOS)
95 }
96
97 } // namespace
98
99 // static
100 scoped_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS(
101 scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
102 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
103 policy::PolicyService* policy_service) {
104 DCHECK(url_request_context_getter.get());
105 DCHECK(policy_service);
106
107 scoped_refptr<AutoThreadTaskRunner> file_task_runner =
108 GetTaskRunner(content::BrowserThread::FILE);
109 scoped_refptr<AutoThreadTaskRunner> input_task_runner =
110 AutoThread::CreateWithType(
111 "ChromotingInputThread", ui_task_runner, base::MessageLoop::TYPE_IO);
112 scoped_refptr<AutoThreadTaskRunner> network_task_runner =
113 GetTaskRunner(content::BrowserThread::IO);
114 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner =
115 GetTaskRunner(content::BrowserThread::UI);
116
117 scoped_ptr<ChromotingHostContext> context(
118 new ChromotingHostContext(ui_task_runner.get(),
119 file_task_runner.get(),
120 input_task_runner.get(),
121 network_task_runner.get(),
122 video_capture_task_runner.get(),
123 url_request_context_getter.get(),
124 policy_service));
125 if (!context->VerifyInitialized()) {
126 context.reset();
127 }
128
129 return context.Pass();
130 }
131
132 bool ChromotingHostContext::VerifyInitialized() {
133 return audio_task_runner_.get() && file_task_runner_.get() &&
134 input_task_runner_.get() && network_task_runner_.get() &&
135 video_capture_task_runner_.get() && video_encode_task_runner_.get() &&
136 url_request_context_getter_.get();
Wez 2014/10/17 17:58:00 The comment in the header indicates that this test
kelvinp 2014/10/20 00:21:16 Done.
137 }
138
67 scoped_refptr<AutoThreadTaskRunner> 139 scoped_refptr<AutoThreadTaskRunner>
68 ChromotingHostContext::audio_task_runner() { 140 ChromotingHostContext::audio_task_runner() {
69 return audio_task_runner_; 141 return audio_task_runner_;
70 } 142 }
71 143
72 scoped_refptr<AutoThreadTaskRunner> 144 scoped_refptr<AutoThreadTaskRunner>
73 ChromotingHostContext::file_task_runner() { 145 ChromotingHostContext::file_task_runner() {
74 return file_task_runner_; 146 return file_task_runner_;
75 } 147 }
76 148
(...skipping 20 matching lines...) Expand all
97 scoped_refptr<AutoThreadTaskRunner> 169 scoped_refptr<AutoThreadTaskRunner>
98 ChromotingHostContext::video_encode_task_runner() { 170 ChromotingHostContext::video_encode_task_runner() {
99 return video_encode_task_runner_; 171 return video_encode_task_runner_;
100 } 172 }
101 173
102 scoped_refptr<net::URLRequestContextGetter> 174 scoped_refptr<net::URLRequestContextGetter>
103 ChromotingHostContext::url_request_context_getter() { 175 ChromotingHostContext::url_request_context_getter() {
104 return url_request_context_getter_; 176 return url_request_context_getter_;
105 } 177 }
106 178
179 policy::PolicyService* ChromotingHostContext::policy_service() {
180 return policy_service_;
181 }
182
107 } // namespace remoting 183 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698