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