diff options
author | sergeyu <sergeyu@chromium.org> | 2015-01-26 18:53:53 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-27 02:55:09 +0000 |
commit | 8eb15cc4766a09c82d0e4f60739b7675f23d4e60 (patch) | |
tree | 1d622047555da4ba9eb96009ecb10dd5df79d387 /jingle | |
parent | c247da12fcca15fdcc948024287b94d6e63e9784 (diff) | |
download | chromium_src-8eb15cc4766a09c82d0e4f60739b7675f23d4e60.zip chromium_src-8eb15cc4766a09c82d0e4f60739b7675f23d4e60.tar.gz chromium_src-8eb15cc4766a09c82d0e4f60739b7675f23d4e60.tar.bz2 |
Fix JingleThreadWrapper initialization in PNaCl plugin.
Previously JingleThreadWrapper was initialized in the remoting PNaCl
plugin such that JingleThreadWrapper::current() was always returning
NULL. JingleThreadWrapper::current() is used only to implement
rtc::Thread::Send() and until recently Send() wasn't used in the parts
of webrtc used in remoting. Now rtc::StunRequest uses Send(), which
crashes the plugin.
Added JingleThreadWrapper::WrapTaskRunner() that properly initializes
current() and is used in the remoting plugin now.
Also JingleThreadWrapper is no longer passes SocketServer to the
parent as it is no longer necessary.
BUG=451643
Review URL: https://codereview.chromium.org/876433003
Cr-Commit-Position: refs/heads/master@{#313213}
Diffstat (limited to 'jingle')
-rw-r--r-- | jingle/glue/thread_wrapper.cc | 44 | ||||
-rw-r--r-- | jingle/glue/thread_wrapper.h | 15 |
2 files changed, 37 insertions, 22 deletions
diff --git a/jingle/glue/thread_wrapper.cc b/jingle/glue/thread_wrapper.cc index d07b746..f74fbb3 100644 --- a/jingle/glue/thread_wrapper.cc +++ b/jingle/glue/thread_wrapper.cc @@ -30,16 +30,26 @@ base::LazyInstance<base::ThreadLocalPointer<JingleThreadWrapper> > // static void JingleThreadWrapper::EnsureForCurrentMessageLoop() { - if (JingleThreadWrapper::current() == NULL) { + if (JingleThreadWrapper::current() == nullptr) { base::MessageLoop* message_loop = base::MessageLoop::current(); - g_jingle_thread_wrapper.Get() - .Set(new JingleThreadWrapper(message_loop->message_loop_proxy())); - message_loop->AddDestructionObserver(current()); + scoped_ptr<JingleThreadWrapper> wrapper = + JingleThreadWrapper::WrapTaskRunner(message_loop->task_runner()); + message_loop->AddDestructionObserver(wrapper.release()); } DCHECK_EQ(rtc::Thread::Current(), current()); } +scoped_ptr<JingleThreadWrapper> JingleThreadWrapper::WrapTaskRunner( + scoped_refptr<base::SingleThreadTaskRunner> task_runner) { + DCHECK(!JingleThreadWrapper::current()); + DCHECK(task_runner->BelongsToCurrentThread()); + + scoped_ptr<JingleThreadWrapper> result(new JingleThreadWrapper(task_runner)); + g_jingle_thread_wrapper.Get().Set(result.get()); + return result.Pass(); +} + // static JingleThreadWrapper* JingleThreadWrapper::current() { return g_jingle_thread_wrapper.Get().Get(); @@ -47,8 +57,7 @@ JingleThreadWrapper* JingleThreadWrapper::current() { JingleThreadWrapper::JingleThreadWrapper( scoped_refptr<base::SingleThreadTaskRunner> task_runner) - : rtc::Thread(new rtc::NullSocketServer()), - task_runner_(task_runner), + : task_runner_(task_runner), send_allowed_(false), last_task_id_(0), pending_send_event_(true, false), @@ -61,18 +70,19 @@ JingleThreadWrapper::JingleThreadWrapper( } JingleThreadWrapper::~JingleThreadWrapper() { - Clear(NULL, rtc::MQID_ANY, NULL); -} + DCHECK_EQ(this, JingleThreadWrapper::current()); + DCHECK_EQ(this, rtc::Thread::Current()); -void JingleThreadWrapper::WillDestroyCurrentMessageLoop() { - DCHECK_EQ(rtc::Thread::Current(), current()); UnwrapCurrent(); - g_jingle_thread_wrapper.Get().Set(NULL); - rtc::ThreadManager::Instance()->SetCurrentThread(NULL); + rtc::ThreadManager::Instance()->SetCurrentThread(nullptr); rtc::MessageQueueManager::Remove(this); - rtc::SocketServer* ss = socketserver(); + g_jingle_thread_wrapper.Get().Set(nullptr); + + Clear(nullptr, rtc::MQID_ANY, nullptr); +} + +void JingleThreadWrapper::WillDestroyCurrentMessageLoop() { delete this; - delete ss; } void JingleThreadWrapper::Post( @@ -133,7 +143,7 @@ void JingleThreadWrapper::Send(rtc::MessageHandler *handler, uint32 id, return; JingleThreadWrapper* current_thread = JingleThreadWrapper::current(); - DCHECK(current_thread != NULL) << "Send() can be called only from a " + DCHECK(current_thread != nullptr) << "Send() can be called only from a " "thread that has JingleThreadWrapper."; rtc::Message message; @@ -180,7 +190,7 @@ void JingleThreadWrapper::Send(rtc::MessageHandler *handler, uint32 id, void JingleThreadWrapper::ProcessPendingSends() { while (true) { - PendingSend* pending_send = NULL; + PendingSend* pending_send = nullptr; { base::AutoLock auto_lock(lock_); if (!pending_send_messages_.empty()) { @@ -240,7 +250,7 @@ void JingleThreadWrapper::RunTask(int task_id) { if (have_message) { if (message.message_id == rtc::MQID_DISPOSE) { - DCHECK(message.phandler == NULL); + DCHECK(message.phandler == nullptr); delete message.pdata; } else { message.phandler->OnMessage(&message); diff --git a/jingle/glue/thread_wrapper.h b/jingle/glue/thread_wrapper.h index 6a045bf..7969d2b 100644 --- a/jingle/glue/thread_wrapper.h +++ b/jingle/glue/thread_wrapper.h @@ -35,13 +35,15 @@ class JingleThreadWrapper : public base::MessageLoop::DestructionObserver, // MessageLoop is destroyed. static void EnsureForCurrentMessageLoop(); - // Returns thread wrapper for the current thread. NULL is returned - // if EnsureForCurrentMessageLoop() has never been called for this - // thread. + // Creates JingleThreadWrapper for |task_runner| that runs tasks on the + // current thread. + static scoped_ptr<JingleThreadWrapper> WrapTaskRunner( + scoped_refptr<base::SingleThreadTaskRunner> task_runner); + + // Returns thread wrapper for the current thread or nullptr if it doesn't + // exist. static JingleThreadWrapper* current(); - explicit JingleThreadWrapper( - scoped_refptr<base::SingleThreadTaskRunner> task_runner); ~JingleThreadWrapper() override; // Sets whether the thread can be used to send messages @@ -95,6 +97,9 @@ class JingleThreadWrapper : public base::MessageLoop::DestructionObserver, typedef std::map<int, rtc::Message> MessagesQueue; struct PendingSend; + explicit JingleThreadWrapper( + scoped_refptr<base::SingleThreadTaskRunner> task_runner); + void PostTaskInternal( int delay_ms, rtc::MessageHandler* handler, uint32 message_id, rtc::MessageData* data); |