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