| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_JINGLE_GLUE_JINGLE_THREAD_H_ | 5 #ifndef REMOTING_JINGLE_GLUE_JINGLE_THREAD_H_ |
| 6 #define REMOTING_JINGLE_GLUE_JINGLE_THREAD_H_ | 6 #define REMOTING_JINGLE_GLUE_JINGLE_THREAD_H_ |
| 7 | 7 |
| 8 #include "base/message_loop.h" |
| 8 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
| 9 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
| 10 #include "third_party/libjingle/source/talk/base/messagequeue.h" | 11 #include "third_party/libjingle/source/talk/base/messagequeue.h" |
| 11 #include "third_party/libjingle/source/talk/base/taskrunner.h" | 12 #include "third_party/libjingle/source/talk/base/taskrunner.h" |
| 12 #include "third_party/libjingle/source/talk/base/thread.h" | 13 #include "third_party/libjingle/source/talk/base/thread.h" |
| 13 | 14 |
| 14 class MessageLoop; | |
| 15 | |
| 16 namespace buzz { | 15 namespace buzz { |
| 17 class XmppClient; | 16 class XmppClient; |
| 18 } | 17 } |
| 19 | 18 |
| 20 namespace remoting { | 19 namespace remoting { |
| 21 | 20 |
| 22 class TaskPump : public talk_base::MessageHandler, | 21 class TaskPump : public talk_base::MessageHandler, |
| 23 public talk_base::TaskRunner { | 22 public talk_base::TaskRunner { |
| 24 public: | 23 public: |
| 25 TaskPump(); | 24 TaskPump(); |
| 26 | 25 |
| 27 // TaskRunner methods. | 26 // TaskRunner methods. |
| 28 virtual void WakeTasks(); | 27 virtual void WakeTasks(); |
| 29 virtual int64 CurrentTime(); | 28 virtual int64 CurrentTime(); |
| 30 | 29 |
| 31 // MessageHandler methods. | 30 // MessageHandler methods. |
| 32 virtual void OnMessage(talk_base::Message* pmsg); | 31 virtual void OnMessage(talk_base::Message* pmsg); |
| 33 }; | 32 }; |
| 34 | 33 |
| 35 // TODO(sergeyu): This class should be changed to inherit from Chromiums | 34 // TODO(sergeyu): This class should be changed to inherit from Chromiums |
| 36 // base::Thread instead of libjingle's thread. | 35 // base::Thread instead of libjingle's thread. |
| 37 class JingleThread : public talk_base::Thread, | 36 class JingleThread : public talk_base::Thread, |
| 38 private talk_base::MessageHandler { | 37 public talk_base::MessageHandler { |
| 39 public: | 38 public: |
| 40 JingleThread(); | 39 JingleThread(); |
| 41 virtual ~JingleThread(); | 40 virtual ~JingleThread(); |
| 42 | 41 |
| 43 void Start(); | 42 void Start(); |
| 44 | 43 |
| 45 // Main function for the thread. Should not be called directly. | 44 // Main function for the thread. Should not be called directly. |
| 46 void Run(); | 45 void Run(); |
| 47 | 46 |
| 47 // Stop the thread. |
| 48 void Stop(); |
| 49 |
| 48 // Returns Chromiums message loop for this thread. | 50 // Returns Chromiums message loop for this thread. |
| 49 // TODO(sergeyu): remove this method when we use base::Thread instead of | 51 // TODO(sergeyu): remove this method when we use base::Thread instead of |
| 50 // talk_base::Thread | 52 // talk_base::Thread |
| 51 MessageLoop* message_loop() { return message_loop_; } | 53 MessageLoop* message_loop(); |
| 52 | 54 |
| 53 // Returns task pump if the thread is running, otherwise NULL is returned. | 55 // Returns task pump if the thread is running, otherwise NULL is returned. |
| 54 TaskPump* task_pump() { return task_pump_; } | 56 TaskPump* task_pump(); |
| 55 | 57 |
| 56 private: | 58 private: |
| 59 class JingleMessageLoop; |
| 60 class JingleMessagePump; |
| 61 |
| 57 friend class HeartbeatSenderTest; | 62 friend class HeartbeatSenderTest; |
| 58 | 63 |
| 59 virtual void OnMessage(talk_base::Message* msg); | 64 virtual void OnMessage(talk_base::Message* msg); |
| 60 | 65 |
| 61 void PumpAuxiliaryLoops(); | |
| 62 | |
| 63 TaskPump* task_pump_; | 66 TaskPump* task_pump_; |
| 64 base::WaitableEvent started_event_; | 67 base::WaitableEvent started_event_; |
| 68 base::WaitableEvent stopped_event_; |
| 65 MessageLoop* message_loop_; | 69 MessageLoop* message_loop_; |
| 66 | 70 |
| 67 DISALLOW_COPY_AND_ASSIGN(JingleThread); | 71 DISALLOW_COPY_AND_ASSIGN(JingleThread); |
| 68 }; | 72 }; |
| 69 | 73 |
| 70 } // namespace remoting | 74 } // namespace remoting |
| 71 | 75 |
| 72 #endif // REMOTING_JINGLE_GLUE_JINGLE_THREAD_H_ | 76 #endif // REMOTING_JINGLE_GLUE_JINGLE_THREAD_H_ |
| OLD | NEW |