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