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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | jingle/glue/thread_wrapper.cc » ('j') | jingle/glue/thread_wrapper.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 JINGLE_GLUE_THREAD_WRAPPER_H_ 5 #ifndef JINGLE_GLUE_THREAD_WRAPPER_H_
6 #define JINGLE_GLUE_THREAD_WRAPPER_H_ 6 #define JINGLE_GLUE_THREAD_WRAPPER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "third_party/libjingle/source/talk/base/thread.h" 15 #include "third_party/libjingle/source/talk/base/thread.h"
16 16
17 namespace jingle_glue { 17 namespace jingle_glue {
18 18
19 // JingleThreadWrapper wraps Chromium threads using talk_base::Thread 19 // JingleThreadWrapper wraps Chromium threads using talk_base::Thread
20 // interface. The object must be created by calling 20 // interface. The object must be created by calling
21 // EnsureForCurrentThread(). Each JingleThreadWrapper deletes itself 21 // EnsureForCurrentThread(). Each JingleThreadWrapper deletes itself
22 // when MessageLoop is destroyed. Currently only the bare minimum that 22 // when MessageLoop is destroyed. Currently only the bare minimum that
23 // is used by P2P part of libjingle is implemented. 23 // is used by P2P part of libjingle is implemented.
24 class JingleThreadWrapper 24 class JingleThreadWrapper
25 : public MessageLoop::DestructionObserver, 25 : public MessageLoop::DestructionObserver,
26 public talk_base::Thread { 26 public talk_base::Thread {
27 public: 27 public:
28 // Create JingleThreadWrapper for the current thread if it hasn't 28 // Create JingleThreadWrapper for the current thread if it hasn't been created
29 // been created yet. 29 // yet. The task runner is destroyed automatically when the current
30 // MessageLoop is destroyed.
Wez 2012/08/09 23:30:25 I think you mean that the ThreadWrapper will be de
Sergey Ulanov 2012/08/13 21:15:34 Done.
30 static void EnsureForCurrentThread(); 31 static void EnsureForCurrentThread();
Wez 2012/08/09 23:30:25 This should probably become EnsureForCurrentMessag
Sergey Ulanov 2012/08/13 21:15:34 Good point. Done.
31 32
32 // Returns thread wrapper for the current thread. NULL is returned 33 // Returns thread wrapper for the current thread. NULL is returned
33 // if EnsureForCurrentThread() has never been called for this 34 // if EnsureForCurrentThread() has never been called for this
34 // thread. 35 // thread.
35 static JingleThreadWrapper* current(); 36 static JingleThreadWrapper* current();
36 37
37 JingleThreadWrapper(MessageLoop* message_loop); 38 JingleThreadWrapper(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
Wez 2012/08/09 23:30:25 nit: explicit
Sergey Ulanov 2012/08/13 21:15:34 Done.
38 39
39 // Sets whether the thread can be used to send messages 40 // Sets whether the thread can be used to send messages
40 // synchronously to another thread using Send() method. Set to false 41 // synchronously to another thread using Send() method. Set to false
41 // by default to avoid potential jankiness when Send() used on 42 // by default to avoid potential jankiness when Send() used on
42 // renderer thread. It should be set explicitly for threads that 43 // renderer thread. It should be set explicitly for threads that
43 // need to call Send() for other threads. 44 // need to call Send() for other threads.
44 void set_send_allowed(bool allowed) { send_allowed_ = allowed; } 45 void set_send_allowed(bool allowed) { send_allowed_ = allowed; }
45 46
46 // MessageLoop::DestructionObserver implementation. 47 // MessageLoop::DestructionObserver implementation.
47 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 48 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 struct PendingSend; 92 struct PendingSend;
92 93
93 virtual ~JingleThreadWrapper(); 94 virtual ~JingleThreadWrapper();
94 95
95 void PostTaskInternal( 96 void PostTaskInternal(
96 int delay_ms, talk_base::MessageHandler* handler, 97 int delay_ms, talk_base::MessageHandler* handler,
97 uint32 message_id, talk_base::MessageData* data); 98 uint32 message_id, talk_base::MessageData* data);
98 void RunTask(int task_id); 99 void RunTask(int task_id);
99 void ProcessPendingSends(); 100 void ProcessPendingSends();
100 101
101 // Chromium thread used to execute messages posted on this thread. 102 // Task runner used to execute messages posted on this thread.
102 MessageLoop* message_loop_; 103 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
103 104
104 bool send_allowed_; 105 bool send_allowed_;
105 106
106 // |lock_| must be locked when accessing |messages_|. 107 // |lock_| must be locked when accessing |messages_|.
107 base::Lock lock_; 108 base::Lock lock_;
108 int last_task_id_; 109 int last_task_id_;
109 MessagesQueue messages_; 110 MessagesQueue messages_;
110 std::list<PendingSend*> pending_send_messages_; 111 std::list<PendingSend*> pending_send_messages_;
111 base::WaitableEvent pending_send_event_; 112 base::WaitableEvent pending_send_event_;
112 }; 113 };
113 114
114 } 115 }
115 116
116 #endif // JINGLE_GLUE_THREAD_WRAPPER_H_ 117 #endif // JINGLE_GLUE_THREAD_WRAPPER_H_
OLDNEW
« no previous file with comments | « no previous file | jingle/glue/thread_wrapper.cc » ('j') | jingle/glue/thread_wrapper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698