blob: e860c33960a8d34bdbc09e6469160415a2102385 [file] [log] [blame]
[email protected]f47f3bb592012-03-06 02:40:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]92698ce2010-06-28 21:49:302// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4d37c8742010-07-20 00:34:575#ifndef REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_
6#define REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_
[email protected]92698ce2010-06-28 21:49:307
dcheng0765c492016-04-06 22:41:538#include <memory>
9
avic5960f32015-12-22 22:49:4810#include "base/macros.h"
[email protected]3c8cfbe72012-07-03 00:24:1511#include "base/memory/ref_counted.h"
avic5960f32015-12-22 22:49:4812#include "build/build_config.h"
[email protected]df338b7d2012-09-05 19:58:3613
sergeyuf87c35de2015-02-18 02:19:0714namespace base {
15class SingleThreadTaskRunner;
16} // namespace base
17
[email protected]951785562012-05-01 00:40:5018namespace net {
[email protected]e6ed0172012-04-17 19:11:4819class URLRequestContextGetter;
[email protected]951785562012-05-01 00:40:5020} // namespace net
21
Maks Orlovich8db7d0d62018-08-16 19:22:2722namespace network {
23class SharedURLLoaderFactory;
24class TransitionalURLLoaderFactoryOwner;
25} // namespace network
26
[email protected]951785562012-05-01 00:40:5027namespace remoting {
[email protected]b5921652012-10-02 21:26:3928
[email protected]ef948e62012-09-04 22:27:4329class AutoThreadTaskRunner;
[email protected]e6ed0172012-04-17 19:11:4830
[email protected]92698ce2010-06-28 21:49:3031// A class that manages threads and running context for the chromoting host
[email protected]1a6cdf42011-05-18 07:41:0132// process. This class is virtual only for testing purposes (see below).
[email protected]92698ce2010-06-28 21:49:3033class ChromotingHostContext {
34 public:
[email protected]32debfb2012-12-05 23:40:5135 // Create threads and URLRequestContextGetter for use by a host.
36 // During shutdown the caller should tear-down the ChromotingHostContext and
37 // then continue to run until |ui_task_runner| is no longer referenced.
sergeyuc5f104b2015-01-09 19:33:2438 // nullptr is returned if any threads fail to start.
dcheng0765c492016-04-06 22:41:5339 static std::unique_ptr<ChromotingHostContext> Create(
[email protected]32debfb2012-12-05 23:40:5140 scoped_refptr<AutoThreadTaskRunner> ui_task_runner);
[email protected]92698ce2010-06-28 21:49:3041
kelvinp561074cf2014-10-30 21:46:1642#if defined(OS_CHROMEOS)
43 // Attaches task runners to the relevant browser threads for the chromoting
44 // host. Must be called on the UI thread of the browser process.
wjmaclean7f36a61b2015-08-12 07:31:2945 // remoting::UrlRequestContextGetter returns ContainerURLRequestContext under
kelvinp561074cf2014-10-30 21:46:1646 // the hood which spawns two new threads per instance. Since
47 // ChromotingHostContext can be destroyed from any thread, as its owner
48 // (It2MeHost) is ref-counted, joining the created threads during shutdown
49 // violates the "Disallow IO" thread restrictions on some task runners (e.g.
50 // the IO Thread of the browser process).
51 // Instead, we re-use the |url_request_context_getter| in the browser process.
dcheng0765c492016-04-06 22:41:5352 static std::unique_ptr<ChromotingHostContext> CreateForChromeOS(
sergeyuf87c35de2015-02-18 02:19:0753 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
54 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
Scott Violet9778dcd2019-06-20 21:59:3755 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
kelvinp561074cf2014-10-30 21:46:1656#endif // defined(OS_CHROMEOS)
57
58 ~ChromotingHostContext();
59
dcheng0765c492016-04-06 22:41:5360 std::unique_ptr<ChromotingHostContext> Copy();
kelvinp561074cf2014-10-30 21:46:1661
62 // Task runner for the thread that is used for the UI.
lukasza806efecb2015-01-12 19:01:0763 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() const;
kelvinp561074cf2014-10-30 21:46:1664
[email protected]ef948e62012-09-04 22:27:4365 // Task runner for the thread used for audio capture and encoding.
lukasza806efecb2015-01-12 19:01:0766 scoped_refptr<AutoThreadTaskRunner> audio_task_runner() const;
[email protected]ef948e62012-09-04 22:27:4367
[email protected]3c8cfbe72012-07-03 00:24:1568 // Task runner for the thread that is used for blocking file
69 // IO. This thread is used by the URLRequestContext to read proxy
70 // configuration and by NatConfig to read policy configs.
lukasza806efecb2015-01-12 19:01:0771 scoped_refptr<AutoThreadTaskRunner> file_task_runner() const;
[email protected]3c8cfbe72012-07-03 00:24:1572
[email protected]b0b72f112013-03-24 03:42:4273 // Task runner for the thread that is used by the InputInjector.
[email protected]b5921652012-10-02 21:26:3974 //
[email protected]b0b72f112013-03-24 03:42:4275 // TODO(sergeyu): Do we need a separate thread for InputInjector?
[email protected]b5921652012-10-02 21:26:3976 // Can we use some other thread instead?
lukasza806efecb2015-01-12 19:01:0777 scoped_refptr<AutoThreadTaskRunner> input_task_runner() const;
[email protected]b5921652012-10-02 21:26:3978
[email protected]ef948e62012-09-04 22:27:4379 // Task runner for the thread used for network IO. This thread runs
80 // a libjingle message loop, and is the only thread on which
81 // libjingle code may be run.
lukasza806efecb2015-01-12 19:01:0782 scoped_refptr<AutoThreadTaskRunner> network_task_runner() const;
[email protected]ef948e62012-09-04 22:27:4383
[email protected]32debfb2012-12-05 23:40:5184 // Task runner for the thread used by the ScreenRecorder to capture
85 // the screen.
lukasza806efecb2015-01-12 19:01:0786 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const;
[email protected]32debfb2012-12-05 23:40:5187
88 // Task runner for the thread used to encode video streams.
lukasza806efecb2015-01-12 19:01:0789 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner() const;
[email protected]32debfb2012-12-05 23:40:5190
lukasza806efecb2015-01-12 19:01:0791 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter()
92 const;
[email protected]92698ce2010-06-28 21:49:3093
Maks Orlovich8db7d0d62018-08-16 19:22:2794 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory();
95
[email protected]92698ce2010-06-28 21:49:3096 private:
kelvinp561074cf2014-10-30 21:46:1697 ChromotingHostContext(
98 scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
99 scoped_refptr<AutoThreadTaskRunner> audio_task_runner,
100 scoped_refptr<AutoThreadTaskRunner> file_task_runner,
101 scoped_refptr<AutoThreadTaskRunner> input_task_runner,
102 scoped_refptr<AutoThreadTaskRunner> network_task_runner,
103 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner,
104 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner,
Scott Violet9778dcd2019-06-20 21:59:37105 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
kelvinp561074cf2014-10-30 21:46:16106
107 // Caller-supplied UI thread. This is usually the application main thread.
108 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
[email protected]92698ce2010-06-28 21:49:30109
[email protected]32debfb2012-12-05 23:40:51110 // Thread for audio capture and encoding.
111 scoped_refptr<AutoThreadTaskRunner> audio_task_runner_;
[email protected]92698ce2010-06-28 21:49:30112
[email protected]32debfb2012-12-05 23:40:51113 // Thread for I/O operations.
114 scoped_refptr<AutoThreadTaskRunner> file_task_runner_;
[email protected]92698ce2010-06-28 21:49:30115
[email protected]32debfb2012-12-05 23:40:51116 // Thread for input injection.
117 scoped_refptr<AutoThreadTaskRunner> input_task_runner_;
[email protected]ef948e62012-09-04 22:27:43118
[email protected]32debfb2012-12-05 23:40:51119 // Thread for network operations.
120 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
[email protected]cec4d7a2012-04-17 05:26:29121
[email protected]32debfb2012-12-05 23:40:51122 // Thread for screen capture.
123 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner_;
124
125 // Thread for video encoding.
126 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner_;
127
128 // Serves URLRequestContexts that use the network and UI task runners.
[email protected]951785562012-05-01 00:40:50129 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
[email protected]e6ed0172012-04-17 19:11:48130
Maks Orlovich8db7d0d62018-08-16 19:22:27131 // Makes a SharedURLLoaderFactory out of |url_request_context_getter_|
132 std::unique_ptr<network::TransitionalURLLoaderFactoryOwner>
133 url_loader_factory_owner_;
134
[email protected]92698ce2010-06-28 21:49:30135 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext);
136};
137
138} // namespace remoting
139
[email protected]92698ce2010-06-28 21:49:30140#endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_