| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.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 #include "remoting/jingle_glue/jingle_thread.h" |
| 15 | 15 |
| 16 class Task; | 16 class Task; |
| 17 | 17 |
| 18 namespace tracked_objects { | 18 namespace tracked_objects { |
| 19 class Location; | 19 class Location; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace remoting { | 22 namespace remoting { |
| 23 | 23 |
| 24 // 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 |
| 25 // process. This class is virtual only for testing purposes (see below). | 25 // process. This class is virtual only for testing purposes (see below). |
| 26 class ChromotingHostContext { | 26 class ChromotingHostContext { |
| 27 public: | 27 public: |
| 28 typedef base::Callback<void( | |
| 29 const tracked_objects::Location& from_here, | |
| 30 const base::Closure& task)> UIThreadPostTaskFunction; | |
| 31 | |
| 32 // Create a context. | 28 // Create a context. |
| 33 ChromotingHostContext(); | 29 ChromotingHostContext(base::MessageLoopProxy* ui_message_loop); |
| 34 virtual ~ChromotingHostContext(); | 30 virtual ~ChromotingHostContext(); |
| 35 | 31 |
| 36 // TODO(ajwong): Move the Start/Stop methods out of this class. Then | 32 // TODO(ajwong): Move the Start/Stop methods out of this class. Then |
| 37 // create a static factory for construction, and destruction. We | 33 // create a static factory for construction, and destruction. We |
| 38 // should be able to remove the need for virtual functions below with that | 34 // should be able to remove the need for virtual functions below with that |
| 39 // design, while preserving the relative simplicity of this API. | 35 // design, while preserving the relative simplicity of this API. |
| 40 virtual void Start(); | 36 virtual void Start(); |
| 41 virtual void Stop(); | 37 virtual void Stop(); |
| 42 | 38 |
| 43 virtual JingleThread* jingle_thread(); | 39 virtual JingleThread* jingle_thread(); |
| 44 | 40 |
| 41 virtual base::MessageLoopProxy* ui_message_loop(); |
| 45 virtual MessageLoop* main_message_loop(); | 42 virtual MessageLoop* main_message_loop(); |
| 46 virtual MessageLoop* encode_message_loop(); | 43 virtual MessageLoop* encode_message_loop(); |
| 47 virtual base::MessageLoopProxy* network_message_loop(); | 44 virtual base::MessageLoopProxy* network_message_loop(); |
| 48 virtual MessageLoop* desktop_message_loop(); | 45 virtual MessageLoop* desktop_message_loop(); |
| 49 | 46 |
| 50 // Must be called from the main GUI thread. | |
| 51 void SetUITaskPostFunction(const UIThreadPostTaskFunction& poster); | |
| 52 | |
| 53 void PostTaskToUIThread(const tracked_objects::Location& from_here, | |
| 54 const base::Closure& task); | |
| 55 void PostDelayedTaskToUIThread(const tracked_objects::Location& from_here, | |
| 56 const base::Closure& task, | |
| 57 int delay_ms); | |
| 58 bool IsUIThread() const; | |
| 59 | |
| 60 private: | 47 private: |
| 61 FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop); | 48 FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop); |
| 62 | 49 |
| 63 // A thread that hosts all network operations. | 50 // A thread that hosts all network operations. |
| 64 JingleThread jingle_thread_; | 51 JingleThread jingle_thread_; |
| 65 scoped_refptr<base::MessageLoopProxy> network_message_loop_; | 52 scoped_refptr<base::MessageLoopProxy> network_message_loop_; |
| 66 | 53 |
| 67 // A thread that hosts ChromotingHost and performs rate control. | 54 // A thread that hosts ChromotingHost and performs rate control. |
| 68 base::Thread main_thread_; | 55 base::Thread main_thread_; |
| 69 | 56 |
| 70 // A thread that hosts all encode operations. | 57 // A thread that hosts all encode operations. |
| 71 base::Thread encode_thread_; | 58 base::Thread encode_thread_; |
| 72 | 59 |
| 73 // A thread that hosts desktop integration (capture, input injection, etc) | 60 // A thread that hosts desktop integration (capture, input injection, etc) |
| 74 // This is NOT a Chrome-style UI thread. | 61 // This is NOT a Chrome-style UI thread. |
| 75 base::Thread desktop_thread_; | 62 base::Thread desktop_thread_; |
| 76 | 63 |
| 77 UIThreadPostTaskFunction ui_poster_; | 64 scoped_refptr<base::MessageLoopProxy> ui_message_loop_; |
| 78 // This IS the main Chrome GUI thread that |ui_poster_| will post to. | |
| 79 base::PlatformThreadId ui_main_thread_id_; | |
| 80 | |
| 81 | 65 |
| 82 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext); | 66 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext); |
| 83 }; | 67 }; |
| 84 | 68 |
| 85 } // namespace remoting | 69 } // namespace remoting |
| 86 | 70 |
| 87 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ | 71 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ |
| OLD | NEW |