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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "remoting/jingle_glue/jingle_thread.h" | |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
18 } // namespace base | 17 } // namespace base |
19 | 18 |
20 namespace net { | 19 namespace net { |
21 class URLRequestContextGetter; | 20 class URLRequestContextGetter; |
22 } // namespace net | 21 } // namespace net |
23 | 22 |
24 namespace remoting { | 23 namespace remoting { |
25 | 24 |
26 // A class that manages threads and running context for the chromoting host | 25 // A class that manages threads and running context for the chromoting host |
27 // process. This class is virtual only for testing purposes (see below). | 26 // process. This class is virtual only for testing purposes (see below). |
28 class ChromotingHostContext { | 27 class ChromotingHostContext { |
29 public: | 28 public: |
30 // Create a context. | 29 // Create a context. |
31 ChromotingHostContext( | 30 ChromotingHostContext( |
32 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 31 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
33 virtual ~ChromotingHostContext(); | 32 virtual ~ChromotingHostContext(); |
34 | 33 |
35 // TODO(ajwong): Move the Start method out of this class. Then | 34 // TODO(ajwong): Move the Start method out of this class. Then |
36 // create a static factory for construction, and destruction. We | 35 // create a static factory for construction, and destruction. We |
37 // should be able to remove the need for virtual functions below | 36 // should be able to remove the need for virtual functions below |
38 // with that design, while preserving the relative simplicity of | 37 // with that design, while preserving the relative simplicity of |
39 // this API. | 38 // this API. |
40 virtual bool Start(); | 39 virtual bool Start(); |
41 | 40 |
42 virtual JingleThread* jingle_thread(); | |
43 | |
44 // Task runner for the thread that is used for the UI. In the NPAPI | 41 // Task runner for the thread that is used for the UI. In the NPAPI |
45 // plugin this corresponds to the main plugin thread. | 42 // plugin this corresponds to the main plugin thread. |
46 virtual base::SingleThreadTaskRunner* ui_task_runner(); | 43 virtual base::SingleThreadTaskRunner* ui_task_runner(); |
47 | 44 |
48 // Task runner for the thread used by the ScreenRecorder to capture | 45 // Task runner for the thread used by the ScreenRecorder to capture |
49 // the screen. | 46 // the screen. |
50 virtual base::SingleThreadTaskRunner* capture_task_runner(); | 47 virtual base::SingleThreadTaskRunner* capture_task_runner(); |
51 | 48 |
52 // Task runner for the thread used to encode video streams. | 49 // Task runner for the thread used to encode video streams. |
53 virtual base::SingleThreadTaskRunner* encode_task_runner(); | 50 virtual base::SingleThreadTaskRunner* encode_task_runner(); |
54 | 51 |
55 // Task runner for the thread used for network IO. This thread runs | 52 // Task runner for the thread used for network IO. This thread runs |
56 // a libjingle message loop, and is the only thread on which | 53 // a libjingle message loop, and is the only thread on which |
57 // libjingle code may be run. | 54 // libjingle code may be run. |
58 virtual base::SingleThreadTaskRunner* network_task_runner(); | 55 virtual base::SingleThreadTaskRunner* network_task_runner(); |
59 | 56 |
60 // Task runner for the thread that is used by the EventExecutor. | 57 // Task runner for the thread that is used by the EventExecutor. |
61 // | 58 // |
62 // TODO(sergeyu): Do we need a separate thread for EventExecutor? | 59 // TODO(sergeyu): Do we need a separate thread for EventExecutor? |
63 // Can we use some other thread instead? | 60 // Can we use some other thread instead? |
64 virtual base::SingleThreadTaskRunner* desktop_task_runner(); | 61 virtual base::SingleThreadTaskRunner* desktop_task_runner(); |
65 | 62 |
66 // Task runner for the thread that is used for chromium's network | |
67 // IO, particularly all HTTP requests (for OAuth and Relay servers). | |
68 // Chromium's HTTP stack cannot be used on the network_task_runner() | |
69 // because that thread runs libjingle's message loop, while | |
70 // chromium's sockets must be used on a thread with a | |
71 // MessageLoopForIO. | |
72 // | |
73 // TODO(sergeyu): Implement socket server for libjingle that works | |
74 // on a regular chromium thread and use it for network_task_runner() | |
75 // to avoid the need for io_task_runner(). | |
76 virtual base::SingleThreadTaskRunner* io_task_runner(); | |
77 | |
78 // Task runner for the thread that is used for blocking file | 63 // Task runner for the thread that is used for blocking file |
79 // IO. This thread is used by the URLRequestContext to read proxy | 64 // IO. This thread is used by the URLRequestContext to read proxy |
80 // configuration and by NatConfig to read policy configs. | 65 // configuration and by NatConfig to read policy configs. |
81 virtual base::SingleThreadTaskRunner* file_task_runner(); | 66 virtual base::SingleThreadTaskRunner* file_task_runner(); |
82 | 67 |
83 const scoped_refptr<net::URLRequestContextGetter>& | 68 const scoped_refptr<net::URLRequestContextGetter>& |
84 url_request_context_getter(); | 69 url_request_context_getter(); |
85 | 70 |
86 private: | 71 private: |
87 FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop); | 72 FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop); |
88 | 73 |
89 // A thread that hosts all network operations. | 74 // A thread that hosts all network operations. |
90 JingleThread jingle_thread_; | 75 base::Thread network_thread_; |
91 | 76 |
92 // A thread that hosts screen capture. | 77 // A thread that hosts screen capture. |
93 base::Thread capture_thread_; | 78 base::Thread capture_thread_; |
94 | 79 |
95 // A thread that hosts all encode operations. | 80 // A thread that hosts all encode operations. |
96 base::Thread encode_thread_; | 81 base::Thread encode_thread_; |
97 | 82 |
98 // A thread that hosts input injection. | 83 // A thread that hosts input injection. |
99 base::Thread desktop_thread_; | 84 base::Thread desktop_thread_; |
100 | 85 |
101 // Thread for non-blocking IO operations. | |
102 base::Thread io_thread_; | |
103 | |
104 // Thread for blocking IO operations. | 86 // Thread for blocking IO operations. |
105 base::Thread file_thread_; | 87 base::Thread file_thread_; |
106 | 88 |
107 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 89 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
108 | 90 |
109 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 91 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
110 | 92 |
111 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext); | 93 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext); |
112 }; | 94 }; |
113 | 95 |
114 } // namespace remoting | 96 } // namespace remoting |
115 | 97 |
116 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ | 98 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ |
OLD | NEW |