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/threading/thread.h" | 10 #include "base/memory/scoped_ptr.h" |
11 | |
12 namespace base { | |
13 class SingleThreadTaskRunner; | |
14 } // namespace base | |
15 | 11 |
16 namespace net { | 12 namespace net { |
17 class URLRequestContextGetter; | 13 class URLRequestContextGetter; |
18 } // namespace net | 14 } // namespace net |
19 | 15 |
20 namespace remoting { | 16 namespace remoting { |
21 | 17 |
22 class AutoThreadTaskRunner; | 18 class AutoThreadTaskRunner; |
23 | 19 |
24 // 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 |
25 // process. This class is virtual only for testing purposes (see below). | 21 // process. This class is virtual only for testing purposes (see below). |
26 class ChromotingHostContext { | 22 class ChromotingHostContext { |
27 public: | 23 public: |
28 // Create a context. | 24 ~ChromotingHostContext(); |
29 ChromotingHostContext( | 25 |
| 26 // Create threads and URLRequestContextGetter for use by a host. |
| 27 // During shutdown the caller should tear-down the ChromotingHostContext and |
| 28 // then continue to run until |ui_task_runner| is no longer referenced. |
| 29 // NULL is returned if any threads fail to start. |
| 30 static scoped_ptr<ChromotingHostContext> Create( |
30 scoped_refptr<AutoThreadTaskRunner> ui_task_runner); | 31 scoped_refptr<AutoThreadTaskRunner> ui_task_runner); |
31 virtual ~ChromotingHostContext(); | |
32 | |
33 // TODO(ajwong): Move the Start method out of this class. Then | |
34 // create a static factory for construction, and destruction. We | |
35 // should be able to remove the need for virtual functions below | |
36 // with that design, while preserving the relative simplicity of | |
37 // this API. | |
38 virtual bool Start(); | |
39 | 32 |
40 // Task runner for the thread used for audio capture and encoding. | 33 // Task runner for the thread used for audio capture and encoding. |
41 virtual base::SingleThreadTaskRunner* audio_task_runner(); | 34 scoped_refptr<AutoThreadTaskRunner> audio_task_runner(); |
42 | |
43 // Task runner for the thread used by the ScreenRecorder to capture | |
44 // the screen. | |
45 virtual base::SingleThreadTaskRunner* video_capture_task_runner(); | |
46 | |
47 // Task runner for the thread used to encode video streams. | |
48 virtual base::SingleThreadTaskRunner* video_encode_task_runner(); | |
49 | 35 |
50 // Task runner for the thread that is used for blocking file | 36 // Task runner for the thread that is used for blocking file |
51 // IO. This thread is used by the URLRequestContext to read proxy | 37 // IO. This thread is used by the URLRequestContext to read proxy |
52 // configuration and by NatConfig to read policy configs. | 38 // configuration and by NatConfig to read policy configs. |
53 virtual base::SingleThreadTaskRunner* file_task_runner(); | 39 scoped_refptr<AutoThreadTaskRunner> file_task_runner(); |
54 | 40 |
55 // Task runner for the thread that is used by the EventExecutor. | 41 // Task runner for the thread that is used by the EventExecutor. |
56 // | 42 // |
57 // TODO(sergeyu): Do we need a separate thread for EventExecutor? | 43 // TODO(sergeyu): Do we need a separate thread for EventExecutor? |
58 // Can we use some other thread instead? | 44 // Can we use some other thread instead? |
59 virtual base::SingleThreadTaskRunner* input_task_runner(); | 45 scoped_refptr<AutoThreadTaskRunner> input_task_runner(); |
60 | 46 |
61 // 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 |
62 // a libjingle message loop, and is the only thread on which | 48 // a libjingle message loop, and is the only thread on which |
63 // libjingle code may be run. | 49 // libjingle code may be run. |
64 virtual base::SingleThreadTaskRunner* network_task_runner(); | 50 scoped_refptr<AutoThreadTaskRunner> network_task_runner(); |
65 | 51 |
66 // Task runner for the thread that is used for the UI. In the NPAPI | 52 // Task runner for the thread that is used for the UI. In the NPAPI |
67 // plugin this corresponds to the main plugin thread. | 53 // plugin this corresponds to the main plugin thread. |
68 virtual base::SingleThreadTaskRunner* ui_task_runner(); | 54 scoped_refptr<AutoThreadTaskRunner> ui_task_runner(); |
69 | 55 |
70 const scoped_refptr<net::URLRequestContextGetter>& | 56 // Task runner for the thread used by the ScreenRecorder to capture |
71 url_request_context_getter(); | 57 // the screen. |
| 58 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner(); |
| 59 |
| 60 // Task runner for the thread used to encode video streams. |
| 61 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner(); |
| 62 |
| 63 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter(); |
72 | 64 |
73 private: | 65 private: |
74 FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop); | 66 ChromotingHostContext(AutoThreadTaskRunner* ui_task_runner); |
75 | 67 |
76 // A thread that hosts audio capture and encoding. | 68 // Thread for audio capture and encoding. |
77 base::Thread audio_thread_; | 69 scoped_refptr<AutoThreadTaskRunner> audio_task_runner_; |
78 | 70 |
79 // A thread that hosts screen capture. | 71 // Thread for I/O operations. |
80 base::Thread video_capture_thread_; | 72 scoped_refptr<AutoThreadTaskRunner> file_task_runner_; |
81 | 73 |
82 // A thread that hosts video encode operations. | 74 // Thread for input injection. |
83 base::Thread video_encode_thread_; | 75 scoped_refptr<AutoThreadTaskRunner> input_task_runner_; |
84 | 76 |
85 // Thread for blocking IO operations. | 77 // Thread for network operations. |
86 base::Thread file_thread_; | 78 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
87 | 79 |
88 // A thread that hosts input injection. | 80 // Caller-supplied UI thread. This is usually the application main thread. |
89 base::Thread input_thread_; | |
90 | |
91 // A thread that hosts all network operations. | |
92 base::Thread network_thread_; | |
93 | |
94 // Task runners wrapping the above threads. These should be declared after | |
95 // the corresponding threads to guarantee proper order of destruction. | |
96 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; | |
97 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_; | |
98 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_; | |
99 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | |
100 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_; | |
101 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | |
102 | |
103 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 81 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
104 | 82 |
| 83 // Thread for screen capture. |
| 84 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner_; |
| 85 |
| 86 // Thread for video encoding. |
| 87 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner_; |
| 88 |
| 89 // Serves URLRequestContexts that use the network and UI task runners. |
105 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 90 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
106 | 91 |
107 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext); | 92 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext); |
108 }; | 93 }; |
109 | 94 |
110 } // namespace remoting | 95 } // namespace remoting |
111 | 96 |
112 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ | 97 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ |
OLD | NEW |