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. | |
29 ChromotingHostContext( | |
30 scoped_refptr<AutoThreadTaskRunner> ui_task_runner); | |
31 virtual ~ChromotingHostContext(); | 24 virtual ~ChromotingHostContext(); |
alexeypa (please no reviews)
2012/12/03 20:34:23
nit: the destructor does not have to be virtual if
Wez
2012/12/03 22:38:46
Done.
| |
32 | 25 |
33 // TODO(ajwong): Move the Start method out of this class. Then | 26 // Create threads and URLRequestContextGetter for use by a host. |
34 // create a static factory for construction, and destruction. We | 27 // During shutdown the caller should tear-down the ChromotingHostContext and |
35 // should be able to remove the need for virtual functions below | 28 // then continue to run until |ui_task_runner| is no longer referenced. |
36 // with that design, while preserving the relative simplicity of | 29 // NULL is returned if any threads fail to start. |
37 // this API. | 30 static scoped_ptr<ChromotingHostContext> Create( |
38 virtual bool Start(); | 31 scoped_refptr<AutoThreadTaskRunner> ui_task_runner); |
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 | 35 |
43 // Task runner for the thread used by the ScreenRecorder to capture | 36 // Task runner for the thread used by the ScreenRecorder to capture |
44 // the screen. | 37 // the screen. |
45 virtual base::SingleThreadTaskRunner* video_capture_task_runner(); | 38 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner(); |
46 | 39 |
47 // Task runner for the thread used to encode video streams. | 40 // Task runner for the thread used to encode video streams. |
48 virtual base::SingleThreadTaskRunner* video_encode_task_runner(); | 41 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner(); |
49 | 42 |
50 // Task runner for the thread that is used for blocking file | 43 // Task runner for the thread that is used for blocking file |
51 // IO. This thread is used by the URLRequestContext to read proxy | 44 // IO. This thread is used by the URLRequestContext to read proxy |
52 // configuration and by NatConfig to read policy configs. | 45 // configuration and by NatConfig to read policy configs. |
53 virtual base::SingleThreadTaskRunner* file_task_runner(); | 46 scoped_refptr<AutoThreadTaskRunner> file_task_runner(); |
54 | 47 |
55 // Task runner for the thread that is used by the EventExecutor. | 48 // Task runner for the thread that is used by the EventExecutor. |
56 // | 49 // |
57 // TODO(sergeyu): Do we need a separate thread for EventExecutor? | 50 // TODO(sergeyu): Do we need a separate thread for EventExecutor? |
58 // Can we use some other thread instead? | 51 // Can we use some other thread instead? |
59 virtual base::SingleThreadTaskRunner* input_task_runner(); | 52 scoped_refptr<AutoThreadTaskRunner> input_task_runner(); |
60 | 53 |
61 // Task runner for the thread used for network IO. This thread runs | 54 // Task runner for the thread used for network IO. This thread runs |
62 // a libjingle message loop, and is the only thread on which | 55 // a libjingle message loop, and is the only thread on which |
63 // libjingle code may be run. | 56 // libjingle code may be run. |
64 virtual base::SingleThreadTaskRunner* network_task_runner(); | 57 scoped_refptr<AutoThreadTaskRunner> network_task_runner(); |
65 | 58 |
66 // Task runner for the thread that is used for the UI. In the NPAPI | 59 // Task runner for the thread that is used for the UI. In the NPAPI |
67 // plugin this corresponds to the main plugin thread. | 60 // plugin this corresponds to the main plugin thread. |
68 virtual base::SingleThreadTaskRunner* ui_task_runner(); | 61 scoped_refptr<AutoThreadTaskRunner> ui_task_runner(); |
69 | 62 |
70 const scoped_refptr<net::URLRequestContextGetter>& | 63 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter(); |
71 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 screen capture. |
80 base::Thread video_capture_thread_; | 72 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner_; |
alexeypa (please no reviews)
2012/12/03 20:34:23
nit: since you are touching this code, could you p
Wez
2012/12/03 22:38:46
Done.
| |
81 | 73 |
82 // A thread that hosts video encode operations. | 74 // Thread for video encoding. |
83 base::Thread video_encode_thread_; | 75 scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner_; |
84 | 76 |
85 // Thread for blocking IO operations. | 77 // Thread for I/O operations. |
86 base::Thread file_thread_; | 78 scoped_refptr<AutoThreadTaskRunner> file_task_runner_; |
87 | 79 |
88 // A thread that hosts input injection. | 80 // Thread for input injection. |
89 base::Thread input_thread_; | 81 scoped_refptr<AutoThreadTaskRunner> input_task_runner_; |
90 | 82 |
91 // A thread that hosts all network operations. | 83 // Thread for network operations. |
92 base::Thread network_thread_; | 84 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
93 | 85 |
94 // Task runners wrapping the above threads. These should be declared after | 86 // Caller-supplied UI thread. This is usually the application main thread. |
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_; | 87 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
104 | 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 |