Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Unified Diff: jingle/glue/thread_wrapper.h

Issue 10823224: Update JingleThreadWrapper to allow it to be created using task runner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jingle/glue/pseudotcp_adapter_unittest.cc ('k') | jingle/glue/thread_wrapper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jingle/glue/thread_wrapper.h
diff --git a/jingle/glue/thread_wrapper.h b/jingle/glue/thread_wrapper.h
index 284c7622736ad065cc1d18e53758fd71c0ce7178..3eb8488d53d4ce11e0fb1403e4759edc178d69a5 100644
--- a/jingle/glue/thread_wrapper.h
+++ b/jingle/glue/thread_wrapper.h
@@ -16,25 +16,34 @@
namespace jingle_glue {
-// JingleThreadWrapper wraps Chromium threads using talk_base::Thread
-// interface. The object must be created by calling
-// EnsureForCurrentThread(). Each JingleThreadWrapper deletes itself
-// when MessageLoop is destroyed. Currently only the bare minimum that
-// is used by P2P part of libjingle is implemented.
+// JingleThreadWrapper implements talk_base::Thread interface on top of
+// Chromium's SingleThreadTaskRunner interface. Currently only the bare minimum
+// that is used by P2P part of libjingle is implemented. There are two ways to
+// create this object:
+//
+// - Call EnsureForCurrentMessageLoop(). This approach works only on threads
+// that have MessageLoop In this case JingleThreadWrapper deletes itself
+// automatically when MessageLoop is destroyed.
+// - Using JingleThreadWrapper() constructor. In this case the creating code
+// must pass a valid task runner for the current thread and also delete the
+// wrapper later.
class JingleThreadWrapper
: public MessageLoop::DestructionObserver,
public talk_base::Thread {
public:
- // Create JingleThreadWrapper for the current thread if it hasn't
- // been created yet.
- static void EnsureForCurrentThread();
+ // Create JingleThreadWrapper for the current thread if it hasn't been created
+ // yet. The thread wrapper is destroyed automatically when the current
+ // MessageLoop is destroyed.
+ static void EnsureForCurrentMessageLoop();
// Returns thread wrapper for the current thread. NULL is returned
- // if EnsureForCurrentThread() has never been called for this
+ // if EnsureForCurrentMessageLoop() has never been called for this
// thread.
static JingleThreadWrapper* current();
- JingleThreadWrapper(MessageLoop* message_loop);
+ explicit JingleThreadWrapper(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ virtual ~JingleThreadWrapper();
// Sets whether the thread can be used to send messages
// synchronously to another thread using Send() method. Set to false
@@ -90,16 +99,14 @@ class JingleThreadWrapper
typedef std::map<int, talk_base::Message> MessagesQueue;
struct PendingSend;
- virtual ~JingleThreadWrapper();
-
void PostTaskInternal(
int delay_ms, talk_base::MessageHandler* handler,
uint32 message_id, talk_base::MessageData* data);
void RunTask(int task_id);
void ProcessPendingSends();
- // Chromium thread used to execute messages posted on this thread.
- MessageLoop* message_loop_;
+ // Task runner used to execute messages posted on this thread.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
bool send_allowed_;
@@ -109,8 +116,13 @@ class JingleThreadWrapper
MessagesQueue messages_;
std::list<PendingSend*> pending_send_messages_;
base::WaitableEvent pending_send_event_;
+
+ base::WeakPtrFactory<JingleThreadWrapper> weak_ptr_factory_;
+ base::WeakPtr<JingleThreadWrapper> weak_ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(JingleThreadWrapper);
};
-}
+} // namespace jingle_glue
#endif // JINGLE_GLUE_THREAD_WRAPPER_H_
« no previous file with comments | « jingle/glue/pseudotcp_adapter_unittest.cc ('k') | jingle/glue/thread_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698