 Chromium Code Reviews
 Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef JINGLE_GLUE_THREAD_WRAPPER_H_ | |
| 6 #define JINGLE_GLUE_THREAD_WRAPPER_H_ | |
| 7 | |
| 8 #include "base/message_loop.h" | |
| 9 #include "base/synchronization/lock.h" | |
| 10 #include "third_party/libjingle/source/talk/base/thread.h" | |
| 11 | |
| 12 class MessageLoop; | |
| 13 | |
| 14 namespace jingle_glue { | |
| 15 | |
| 16 class JingleThreadWrapper | |
| 
Alpha Left Google
2011/03/26 01:06:01
Add a short comment here to explain what this is d
 
Sergey Ulanov
2011/03/26 01:44:24
Done.
 | |
| 17 : public MessageLoop::DestructionObserver, | |
| 18 public talk_base::Thread { | |
| 19 public: | |
| 20 JingleThreadWrapper(MessageLoop* message_loop); | |
| 21 | |
| 22 // MessageLoop::DestructionObserver implementation. | |
| 23 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | |
| 24 | |
| 25 // talk_base::MessageQueue overrides. | |
| 26 virtual void Post(talk_base::MessageHandler *phandler, uint32 id = 0, | |
| 27 talk_base::MessageData *pdata = NULL, | |
| 28 bool time_sensitive = false) OVERRIDE; | |
| 29 virtual void PostDelayed( | |
| 30 int delay_ms, talk_base::MessageHandler* handler, uint32 id = 0, | |
| 31 talk_base::MessageData* data = NULL) OVERRIDE; | |
| 32 virtual void Clear(talk_base::MessageHandler* handler, | |
| 33 uint32 id = talk_base::MQID_ANY, | |
| 34 talk_base::MessageList* removed = NULL) OVERRIDE; | |
| 35 | |
| 36 // Following methods are not supported, and should not be used. They | |
| 37 // are overriden just to ensure that they are not called. | |
| 38 virtual void Quit() OVERRIDE; | |
| 39 virtual bool IsQuitting() OVERRIDE; | |
| 40 virtual void Restart() OVERRIDE; | |
| 41 virtual bool Get(talk_base::Message* msg, int delay_ms = talk_base::kForever, | |
| 42 bool process_io = true) OVERRIDE; | |
| 43 virtual bool Peek(talk_base::Message* msg, int delay_ms = 0) OVERRIDE; | |
| 44 virtual void PostAt( | |
| 45 uint32 timestamp, talk_base::MessageHandler* handler, | |
| 46 uint32 id = 0, talk_base::MessageData* data = NULL) OVERRIDE; | |
| 47 virtual void Dispatch(talk_base::Message* msg) OVERRIDE; | |
| 48 virtual void ReceiveSends() OVERRIDE; | |
| 49 virtual int GetDelay() OVERRIDE; | |
| 50 | |
| 51 // talk_base::Thread overrides. | |
| 52 virtual void Stop() OVERRIDE; | |
| 53 virtual void Run() OVERRIDE; | |
| 54 | |
| 55 private: | |
| 56 friend class base::RefCountedThreadSafe<JingleThreadWrapper>; | |
| 
Alpha Left Google
2011/03/26 01:06:01
Because we need comments saying this has to be use
 
Sergey Ulanov
2011/03/26 01:44:24
Don't needs this. removed.
 | |
| 57 | |
| 58 typedef std::vector<talk_base::DelayedMessage> DelayedMessagesHeap; | |
| 59 | |
| 60 virtual ~JingleThreadWrapper() OVERRIDE; | |
| 61 | |
| 62 void RunPendingTasks(); | |
| 63 void RunDelayedTask(uint32 task_time); | |
| 64 | |
| 65 // Chromium thread used to execute messages posted on this thread. | |
| 66 MessageLoop* message_loop_; | |
| 67 | |
| 68 // |lock_| must be locked when accessing |messages_|. | |
| 69 base::Lock lock_; | |
| 70 bool task_posted_; | |
| 71 std::list<talk_base::Message> messages_; | |
| 72 | |
| 73 // A heap that contains all delayed messages. std::push_heap() and | |
| 74 // std::pop_heap() must be used to add/remove tasks. | |
| 75 DelayedMessagesHeap delayed_messages_; | |
| 
Alpha Left Google
2011/03/26 01:06:01
I would suggest you use STL set so you don't need
 
Sergey Ulanov
2011/03/26 01:44:24
Changed this to set.
 | |
| 76 }; | |
| 77 | |
| 78 } | |
| 79 | |
| 80 // Safe to disable refcounting because JingleThreadWrapper deletes | |
| 81 // itself with the thread. | |
| 82 DISABLE_RUNNABLE_METHOD_REFCOUNT(jingle_glue::JingleThreadWrapper); | |
| 83 | |
| 84 #endif // JINGLE_GLUE_THREAD_WRAPPER_H_ | |
| OLD | NEW |