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

Side by Side Diff: jingle/glue/thread_wrapper.h

Issue 876433003: Fix JingleThreadWrapper initialization in PNaCl plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@db
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | jingle/glue/thread_wrapper.cc » ('j') | no next file with comments »
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
(...skipping 17 matching lines...) Expand all
28 // must pass a valid task runner for the current thread and also delete the 28 // must pass a valid task runner for the current thread and also delete the
29 // wrapper later. 29 // wrapper later.
30 class JingleThreadWrapper : public base::MessageLoop::DestructionObserver, 30 class JingleThreadWrapper : public base::MessageLoop::DestructionObserver,
31 public rtc::Thread { 31 public rtc::Thread {
32 public: 32 public:
33 // Create JingleThreadWrapper for the current thread if it hasn't been created 33 // Create JingleThreadWrapper for the current thread if it hasn't been created
34 // yet. The thread wrapper is destroyed automatically when the current 34 // yet. The thread wrapper is destroyed automatically when the current
35 // MessageLoop is destroyed. 35 // MessageLoop is destroyed.
36 static void EnsureForCurrentMessageLoop(); 36 static void EnsureForCurrentMessageLoop();
37 37
38 // Returns thread wrapper for the current thread. NULL is returned 38 // Creates JingleThreadWrapper for |task_runner| that runs tasks on the
39 // if EnsureForCurrentMessageLoop() has never been called for this 39 // current thread.
40 // thread. 40 static scoped_ptr<JingleThreadWrapper> WrapTaskRunner(
41 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
42
43 // Returns thread wrapper for the current thread or nullptr if it doesn't
44 // exist.
41 static JingleThreadWrapper* current(); 45 static JingleThreadWrapper* current();
42 46
43 explicit JingleThreadWrapper(
44 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
45 ~JingleThreadWrapper() override; 47 ~JingleThreadWrapper() override;
46 48
47 // Sets whether the thread can be used to send messages 49 // Sets whether the thread can be used to send messages
48 // synchronously to another thread using Send() method. Set to false 50 // synchronously to another thread using Send() method. Set to false
49 // by default to avoid potential jankiness when Send() used on 51 // by default to avoid potential jankiness when Send() used on
50 // renderer thread. It should be set explicitly for threads that 52 // renderer thread. It should be set explicitly for threads that
51 // need to call Send() for other threads. 53 // need to call Send() for other threads.
52 void set_send_allowed(bool allowed) { send_allowed_ = allowed; } 54 void set_send_allowed(bool allowed) { send_allowed_ = allowed; }
53 55
54 // MessageLoop::DestructionObserver implementation. 56 // MessageLoop::DestructionObserver implementation.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 int GetDelay() override; 90 int GetDelay() override;
89 91
90 // rtc::Thread overrides. 92 // rtc::Thread overrides.
91 void Stop() override; 93 void Stop() override;
92 void Run() override; 94 void Run() override;
93 95
94 private: 96 private:
95 typedef std::map<int, rtc::Message> MessagesQueue; 97 typedef std::map<int, rtc::Message> MessagesQueue;
96 struct PendingSend; 98 struct PendingSend;
97 99
100 explicit JingleThreadWrapper(
101 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
102
98 void PostTaskInternal( 103 void PostTaskInternal(
99 int delay_ms, rtc::MessageHandler* handler, 104 int delay_ms, rtc::MessageHandler* handler,
100 uint32 message_id, rtc::MessageData* data); 105 uint32 message_id, rtc::MessageData* data);
101 void RunTask(int task_id); 106 void RunTask(int task_id);
102 void ProcessPendingSends(); 107 void ProcessPendingSends();
103 108
104 // Task runner used to execute messages posted on this thread. 109 // Task runner used to execute messages posted on this thread.
105 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 110 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
106 111
107 bool send_allowed_; 112 bool send_allowed_;
108 113
109 // |lock_| must be locked when accessing |messages_|. 114 // |lock_| must be locked when accessing |messages_|.
110 base::Lock lock_; 115 base::Lock lock_;
111 int last_task_id_; 116 int last_task_id_;
112 MessagesQueue messages_; 117 MessagesQueue messages_;
113 std::list<PendingSend*> pending_send_messages_; 118 std::list<PendingSend*> pending_send_messages_;
114 base::WaitableEvent pending_send_event_; 119 base::WaitableEvent pending_send_event_;
115 120
116 base::WeakPtr<JingleThreadWrapper> weak_ptr_; 121 base::WeakPtr<JingleThreadWrapper> weak_ptr_;
117 base::WeakPtrFactory<JingleThreadWrapper> weak_ptr_factory_; 122 base::WeakPtrFactory<JingleThreadWrapper> weak_ptr_factory_;
118 123
119 DISALLOW_COPY_AND_ASSIGN(JingleThreadWrapper); 124 DISALLOW_COPY_AND_ASSIGN(JingleThreadWrapper);
120 }; 125 };
121 126
122 } // namespace jingle_glue 127 } // namespace jingle_glue
123 128
124 #endif // JINGLE_GLUE_THREAD_WRAPPER_H_ 129 #endif // JINGLE_GLUE_THREAD_WRAPPER_H_
OLDNEW
« no previous file with comments | « no previous file | jingle/glue/thread_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698