Compute can_use_lcd_text using property trees.
[chromium-blink-merge.git] / remoting / host / chromoting_host_context.h
blobaf6216acaba1377040d1d3652fda54b81a552dcc
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 #ifndef REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_
6 #define REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
12 namespace base {
13 class SingleThreadTaskRunner;
14 } // namespace base
16 namespace net {
17 class URLRequestContextGetter;
18 } // namespace net
20 namespace remoting {
22 class AutoThreadTaskRunner;
24 // A class that manages threads and running context for the chromoting host
25 // process. This class is virtual only for testing purposes (see below).
26 class ChromotingHostContext {
27 public:
28 // Create threads and URLRequestContextGetter for use by a host.
29 // During shutdown the caller should tear-down the ChromotingHostContext and
30 // then continue to run until |ui_task_runner| is no longer referenced.
31 // nullptr is returned if any threads fail to start.
32 static scoped_ptr<ChromotingHostContext> Create(
33 scoped_refptr<AutoThreadTaskRunner> ui_task_runner);
35 #if defined(OS_CHROMEOS)
36 // Attaches task runners to the relevant browser threads for the chromoting
37 // host. Must be called on the UI thread of the browser process.
38 // remoting::UrlRequestContextGetter returns BasicURLRequestContext under
39 // the hood which spawns two new threads per instance. Since
40 // ChromotingHostContext can be destroyed from any thread, as its owner
41 // (It2MeHost) is ref-counted, joining the created threads during shutdown
42 // violates the "Disallow IO" thread restrictions on some task runners (e.g.
43 // the IO Thread of the browser process).
44 // Instead, we re-use the |url_request_context_getter| in the browser process.
45 static scoped_ptr<ChromotingHostContext> CreateForChromeOS(
46 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
47 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
48 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
49 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
50 #endif // defined(OS_CHROMEOS)
52 ~ChromotingHostContext();
54 scoped_ptr<ChromotingHostContext> Copy();
56 // Task runner for the thread that is used for the UI.
57 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() const;
59 // Task runner for the thread used for audio capture and encoding.
60 scoped_refptr<AutoThreadTaskRunner> audio_task_runner() const;
62 // Task runner for the thread that is used for blocking file
63 // IO. This thread is used by the URLRequestContext to read proxy
64 // configuration and by NatConfig to read policy configs.
65 scoped_refptr<AutoThreadTaskRunner> file_task_runner() const;
67 // Task runner for the thread that is used by the InputInjector.
69 // TODO(sergeyu): Do we need a separate thread for InputInjector?
70 // Can we use some other thread instead?
71 scoped_refptr<AutoThreadTaskRunner> input_task_runner() const;
73 // Task runner for the thread used for network IO. This thread runs
74 // a libjingle message loop, and is the only thread on which
75 // libjingle code may be run.
76 scoped_refptr<AutoThreadTaskRunner> network_task_runner() const;
78 // Task runner for the thread used by the ScreenRecorder to capture
79 // the screen.
80 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const;
82 // Task runner for the thread used to encode video streams.
83 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner() const;
85 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter()
86 const;
88 private:
89 ChromotingHostContext(
90 scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
91 scoped_refptr<AutoThreadTaskRunner> audio_task_runner,
92 scoped_refptr<AutoThreadTaskRunner> file_task_runner,
93 scoped_refptr<AutoThreadTaskRunner> input_task_runner,
94 scoped_refptr<AutoThreadTaskRunner> network_task_runner,
95 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner,
96 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner,
97 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
99 // Caller-supplied UI thread. This is usually the application main thread.
100 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
102 // Thread for audio capture and encoding.
103 scoped_refptr<AutoThreadTaskRunner> audio_task_runner_;
105 // Thread for I/O operations.
106 scoped_refptr<AutoThreadTaskRunner> file_task_runner_;
108 // Thread for input injection.
109 scoped_refptr<AutoThreadTaskRunner> input_task_runner_;
111 // Thread for network operations.
112 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
114 // Thread for screen capture.
115 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner_;
117 // Thread for video encoding.
118 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner_;
120 // Serves URLRequestContexts that use the network and UI task runners.
121 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
123 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext);
126 } // namespace remoting
128 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_