Chromium Code Reviews| Index: jingle/glue/thread_wrapper.h |
| diff --git a/jingle/glue/thread_wrapper.h b/jingle/glue/thread_wrapper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1db91f5bc62b82ba2a44ac9630e78d0c054528d9 |
| --- /dev/null |
| +++ b/jingle/glue/thread_wrapper.h |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef JINGLE_GLUE_THREAD_WRAPPER_H_ |
| +#define JINGLE_GLUE_THREAD_WRAPPER_H_ |
| + |
| +#include "base/message_loop.h" |
| +#include "base/synchronization/lock.h" |
| +#include "third_party/libjingle/source/talk/base/thread.h" |
| + |
| +class MessageLoop; |
| + |
| +namespace jingle_glue { |
| + |
| +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.
|
| + : public MessageLoop::DestructionObserver, |
| + public talk_base::Thread { |
| + public: |
| + JingleThreadWrapper(MessageLoop* message_loop); |
| + |
| + // MessageLoop::DestructionObserver implementation. |
| + virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| + |
| + // talk_base::MessageQueue overrides. |
| + virtual void Post(talk_base::MessageHandler *phandler, uint32 id = 0, |
| + talk_base::MessageData *pdata = NULL, |
| + bool time_sensitive = false) OVERRIDE; |
| + virtual void PostDelayed( |
| + int delay_ms, talk_base::MessageHandler* handler, uint32 id = 0, |
| + talk_base::MessageData* data = NULL) OVERRIDE; |
| + virtual void Clear(talk_base::MessageHandler* handler, |
| + uint32 id = talk_base::MQID_ANY, |
| + talk_base::MessageList* removed = NULL) OVERRIDE; |
| + |
| + // Following methods are not supported, and should not be used. They |
| + // are overriden just to ensure that they are not called. |
| + virtual void Quit() OVERRIDE; |
| + virtual bool IsQuitting() OVERRIDE; |
| + virtual void Restart() OVERRIDE; |
| + virtual bool Get(talk_base::Message* msg, int delay_ms = talk_base::kForever, |
| + bool process_io = true) OVERRIDE; |
| + virtual bool Peek(talk_base::Message* msg, int delay_ms = 0) OVERRIDE; |
| + virtual void PostAt( |
| + uint32 timestamp, talk_base::MessageHandler* handler, |
| + uint32 id = 0, talk_base::MessageData* data = NULL) OVERRIDE; |
| + virtual void Dispatch(talk_base::Message* msg) OVERRIDE; |
| + virtual void ReceiveSends() OVERRIDE; |
| + virtual int GetDelay() OVERRIDE; |
| + |
| + // talk_base::Thread overrides. |
| + virtual void Stop() OVERRIDE; |
| + virtual void Run() OVERRIDE; |
| + |
| + private: |
| + 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.
|
| + |
| + typedef std::vector<talk_base::DelayedMessage> DelayedMessagesHeap; |
| + |
| + virtual ~JingleThreadWrapper() OVERRIDE; |
| + |
| + void RunPendingTasks(); |
| + void RunDelayedTask(uint32 task_time); |
| + |
| + // Chromium thread used to execute messages posted on this thread. |
| + MessageLoop* message_loop_; |
| + |
| + // |lock_| must be locked when accessing |messages_|. |
| + base::Lock lock_; |
| + bool task_posted_; |
| + std::list<talk_base::Message> messages_; |
| + |
| + // A heap that contains all delayed messages. std::push_heap() and |
| + // std::pop_heap() must be used to add/remove tasks. |
| + 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.
|
| +}; |
| + |
| +} |
| + |
| +// Safe to disable refcounting because JingleThreadWrapper deletes |
| +// itself with the thread. |
| +DISABLE_RUNNABLE_METHOD_REFCOUNT(jingle_glue::JingleThreadWrapper); |
| + |
| +#endif // JINGLE_GLUE_THREAD_WRAPPER_H_ |