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