Update content setting for app banners to store more information.
[chromium-blink-merge.git] / remoting / host / chromoting_host_context.cc
blob319cc77f1784f17a2b392d90eda5a372d646df76
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/threading/thread_restrictions.h"
8 #include "content/public/browser/browser_thread.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)
130 namespace {
131 // Retrieves the task_runner from the browser thread with |id|.
132 scoped_refptr<AutoThreadTaskRunner> WrapBrowserThread(
133 content::BrowserThread::ID id) {
134 // AutoThreadTaskRunner is a TaskRunner with the special property that it will
135 // continue to process tasks until no references remain, at least. The
136 // QuitClosure we usually pass does the simple thing of stopping the
137 // underlying TaskRunner. Since we are re-using the ui_task_runner of the
138 // browser thread, we cannot stop it explicitly. Therefore, base::DoNothing
139 // is passed in as the quit closure.
140 // TODO(kelvinp): Fix this (See crbug.com/428187).
141 return new AutoThreadTaskRunner(
142 content::BrowserThread::GetMessageLoopProxyForThread(id).get(),
143 base::Bind(&base::DoNothing));
146 } // namespace
148 // static
149 scoped_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS(
150 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
151 DCHECK(url_request_context_getter.get());
153 // Use BrowserThread::FILE as the joiner as it is the only browser-thread
154 // that allows blocking I/O, which is required by thread joining.
155 // TODO(kelvinp): Fix AutoThread so that it can be joinable on task runners
156 // that disallow I/O (crbug.com/428466).
157 scoped_refptr<AutoThreadTaskRunner> file_task_runner =
158 WrapBrowserThread(content::BrowserThread::FILE);
160 scoped_refptr<AutoThreadTaskRunner> ui_task_runner =
161 WrapBrowserThread(content::BrowserThread::UI);
163 return make_scoped_ptr(new ChromotingHostContext(
164 ui_task_runner,
165 AutoThread::CreateWithType("ChromotingAudioThread", file_task_runner,
166 base::MessageLoop::TYPE_IO),
167 file_task_runner,
168 AutoThread::CreateWithType("ChromotingInputThread", file_task_runner,
169 base::MessageLoop::TYPE_IO),
170 WrapBrowserThread(content::BrowserThread::IO), // network_task_runner
171 ui_task_runner, // video_capture_task_runner
172 AutoThread::CreateWithType("ChromotingEncodeThread", file_task_runner,
173 base::MessageLoop::TYPE_IO),
174 url_request_context_getter));
176 #endif // defined(OS_CHROMEOS)
178 } // namespace remoting