Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / remoting / host / chromoting_host_context.cc
blobe2943ff329d98f5917aaadb05d892d2521aaaf6a
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
3 // found in the LICENSE file.
5 #include "remoting/host/chromoting_host_context.h"
7 #include "base/bind.h"
8 #include "base/threading/thread_restrictions.h"
9 #include "remoting/base/auto_thread.h"
10 #include "remoting/base/url_request_context_getter.h"
12 namespace remoting {
14 namespace {
16 void DisallowBlockingOperations() {
17 base::ThreadRestrictions::SetIOAllowed(false);
18 base::ThreadRestrictions::DisallowWaiting();
21 } // namespace
23 ChromotingHostContext::ChromotingHostContext(
24 scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
25 scoped_refptr<AutoThreadTaskRunner> audio_task_runner,
26 scoped_refptr<AutoThreadTaskRunner> file_task_runner,
27 scoped_refptr<AutoThreadTaskRunner> input_task_runner,
28 scoped_refptr<AutoThreadTaskRunner> network_task_runner,
29 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner,
30 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner,
31 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
32 : ui_task_runner_(ui_task_runner),
33 audio_task_runner_(audio_task_runner),
34 file_task_runner_(file_task_runner),
35 input_task_runner_(input_task_runner),
36 network_task_runner_(network_task_runner),
37 video_capture_task_runner_(video_capture_task_runner),
38 video_encode_task_runner_(video_encode_task_runner),
39 url_request_context_getter_(url_request_context_getter) {
42 ChromotingHostContext::~ChromotingHostContext() {
45 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Copy() {
46 return make_scoped_ptr(new ChromotingHostContext(
47 ui_task_runner_, audio_task_runner_, file_task_runner_,
48 input_task_runner_, network_task_runner_, video_capture_task_runner_,
49 video_encode_task_runner_, url_request_context_getter_));
52 scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::audio_task_runner()
53 const {
54 return audio_task_runner_;
57 scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::file_task_runner()
58 const {
59 return file_task_runner_;
62 scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::input_task_runner()
63 const {
64 return input_task_runner_;
67 scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::network_task_runner()
68 const {
69 return network_task_runner_;
72 scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::ui_task_runner()
73 const {
74 return ui_task_runner_;
77 scoped_refptr<AutoThreadTaskRunner>
78 ChromotingHostContext::video_capture_task_runner() const {
79 return video_capture_task_runner_;
82 scoped_refptr<AutoThreadTaskRunner>
83 ChromotingHostContext::video_encode_task_runner() const {
84 return video_encode_task_runner_;
87 scoped_refptr<net::URLRequestContextGetter>
88 ChromotingHostContext::url_request_context_getter() const {
89 return url_request_context_getter_;
92 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create(
93 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) {
94 #if defined(OS_WIN)
95 // On Windows the AudioCapturer requires COM, so we run a single-threaded
96 // apartment, which requires a UI thread.
97 scoped_refptr<AutoThreadTaskRunner> audio_task_runner =
98 AutoThread::CreateWithLoopAndComInitTypes(
99 "ChromotingAudioThread", ui_task_runner, base::MessageLoop::TYPE_UI,
100 AutoThread::COM_INIT_STA);
101 #else // !defined(OS_WIN)
102 scoped_refptr<AutoThreadTaskRunner> audio_task_runner =
103 AutoThread::CreateWithType("ChromotingAudioThread", ui_task_runner,
104 base::MessageLoop::TYPE_IO);
105 #endif // !defined(OS_WIN)
106 scoped_refptr<AutoThreadTaskRunner> file_task_runner =
107 AutoThread::CreateWithType("ChromotingFileThread", ui_task_runner,
108 base::MessageLoop::TYPE_IO);
110 scoped_refptr<AutoThreadTaskRunner> network_task_runner =
111 AutoThread::CreateWithType("ChromotingNetworkThread", ui_task_runner,
112 base::MessageLoop::TYPE_IO);
113 network_task_runner->PostTask(FROM_HERE,
114 base::Bind(&DisallowBlockingOperations));
116 return make_scoped_ptr(new ChromotingHostContext(
117 ui_task_runner,
118 audio_task_runner,
119 file_task_runner,
120 AutoThread::CreateWithType("ChromotingInputThread", ui_task_runner,
121 base::MessageLoop::TYPE_IO),
122 network_task_runner,
123 AutoThread::Create("ChromotingCaptureThread", ui_task_runner),
124 AutoThread::Create("ChromotingEncodeThread", ui_task_runner),
125 make_scoped_refptr(
126 new URLRequestContextGetter(network_task_runner, file_task_runner))));
129 #if defined(OS_CHROMEOS)
131 // static
132 scoped_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS(
133 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
134 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
135 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
136 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) {
137 DCHECK(url_request_context_getter.get());
140 // AutoThreadTaskRunner is a TaskRunner with the special property that it will
141 // continue to process tasks until no references remain, at least. The
142 // QuitClosure we usually pass does the simple thing of stopping the
143 // underlying TaskRunner. Since we are re-using browser's threads, we cannot
144 // stop them explicitly. Therefore, base::DoNothing is passed in as the quit
145 // closure.
146 scoped_refptr<AutoThreadTaskRunner> io_auto_task_runner =
147 new AutoThreadTaskRunner(io_task_runner, base::Bind(&base::DoNothing));
148 scoped_refptr<AutoThreadTaskRunner> file_auto_task_runner =
149 new AutoThreadTaskRunner(file_task_runner, base::Bind(&base::DoNothing));
150 scoped_refptr<AutoThreadTaskRunner> ui_auto_task_runner =
151 new AutoThreadTaskRunner(ui_task_runner, base::Bind(&base::DoNothing));
153 // Use browser's file thread as the joiner as it is the only browser-thread
154 // that allows blocking I/O, which is required by thread joining.
155 return make_scoped_ptr(new ChromotingHostContext(
156 ui_auto_task_runner,
157 AutoThread::Create("ChromotingAudioThread", file_auto_task_runner),
158 file_auto_task_runner,
159 ui_auto_task_runner, // input_task_runner
160 io_auto_task_runner, // network_task_runner
161 ui_auto_task_runner, // video_capture_task_runner
162 AutoThread::Create("ChromotingEncodeThread", file_auto_task_runner),
163 url_request_context_getter));
165 #endif // defined(OS_CHROMEOS)
167 } // namespace remoting