Commit 8eb15cc4 authored by sergeyu's avatar sergeyu Committed by Commit bot

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}
parent c247da12
...@@ -30,16 +30,26 @@ base::LazyInstance<base::ThreadLocalPointer<JingleThreadWrapper> > ...@@ -30,16 +30,26 @@ base::LazyInstance<base::ThreadLocalPointer<JingleThreadWrapper> >
// static // static
void JingleThreadWrapper::EnsureForCurrentMessageLoop() { void JingleThreadWrapper::EnsureForCurrentMessageLoop() {
if (JingleThreadWrapper::current() == NULL) { if (JingleThreadWrapper::current() == nullptr) {
base::MessageLoop* message_loop = base::MessageLoop::current(); base::MessageLoop* message_loop = base::MessageLoop::current();
g_jingle_thread_wrapper.Get() scoped_ptr<JingleThreadWrapper> wrapper =
.Set(new JingleThreadWrapper(message_loop->message_loop_proxy())); JingleThreadWrapper::WrapTaskRunner(message_loop->task_runner());
message_loop->AddDestructionObserver(current()); message_loop->AddDestructionObserver(wrapper.release());
} }
DCHECK_EQ(rtc::Thread::Current(), current()); 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 // static
JingleThreadWrapper* JingleThreadWrapper::current() { JingleThreadWrapper* JingleThreadWrapper::current() {
return g_jingle_thread_wrapper.Get().Get(); return g_jingle_thread_wrapper.Get().Get();
...@@ -47,8 +57,7 @@ JingleThreadWrapper* JingleThreadWrapper::current() { ...@@ -47,8 +57,7 @@ JingleThreadWrapper* JingleThreadWrapper::current() {
JingleThreadWrapper::JingleThreadWrapper( JingleThreadWrapper::JingleThreadWrapper(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: rtc::Thread(new rtc::NullSocketServer()), : task_runner_(task_runner),
task_runner_(task_runner),
send_allowed_(false), send_allowed_(false),
last_task_id_(0), last_task_id_(0),
pending_send_event_(true, false), pending_send_event_(true, false),
...@@ -61,18 +70,19 @@ JingleThreadWrapper::JingleThreadWrapper( ...@@ -61,18 +70,19 @@ JingleThreadWrapper::JingleThreadWrapper(
} }
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(); UnwrapCurrent();
g_jingle_thread_wrapper.Get().Set(NULL); rtc::ThreadManager::Instance()->SetCurrentThread(nullptr);
rtc::ThreadManager::Instance()->SetCurrentThread(NULL);
rtc::MessageQueueManager::Remove(this); 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 this;
delete ss;
} }
void JingleThreadWrapper::Post( void JingleThreadWrapper::Post(
...@@ -133,7 +143,7 @@ void JingleThreadWrapper::Send(rtc::MessageHandler *handler, uint32 id, ...@@ -133,7 +143,7 @@ void JingleThreadWrapper::Send(rtc::MessageHandler *handler, uint32 id,
return; return;
JingleThreadWrapper* current_thread = JingleThreadWrapper::current(); 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."; "thread that has JingleThreadWrapper.";
rtc::Message message; rtc::Message message;
...@@ -180,7 +190,7 @@ void JingleThreadWrapper::Send(rtc::MessageHandler *handler, uint32 id, ...@@ -180,7 +190,7 @@ void JingleThreadWrapper::Send(rtc::MessageHandler *handler, uint32 id,
void JingleThreadWrapper::ProcessPendingSends() { void JingleThreadWrapper::ProcessPendingSends() {
while (true) { while (true) {
PendingSend* pending_send = NULL; PendingSend* pending_send = nullptr;
{ {
base::AutoLock auto_lock(lock_); base::AutoLock auto_lock(lock_);
if (!pending_send_messages_.empty()) { if (!pending_send_messages_.empty()) {
...@@ -240,7 +250,7 @@ void JingleThreadWrapper::RunTask(int task_id) { ...@@ -240,7 +250,7 @@ void JingleThreadWrapper::RunTask(int task_id) {
if (have_message) { if (have_message) {
if (message.message_id == rtc::MQID_DISPOSE) { if (message.message_id == rtc::MQID_DISPOSE) {
DCHECK(message.phandler == NULL); DCHECK(message.phandler == nullptr);
delete message.pdata; delete message.pdata;
} else { } else {
message.phandler->OnMessage(&message); message.phandler->OnMessage(&message);
......
...@@ -35,13 +35,15 @@ class JingleThreadWrapper : public base::MessageLoop::DestructionObserver, ...@@ -35,13 +35,15 @@ class JingleThreadWrapper : public base::MessageLoop::DestructionObserver,
// MessageLoop is destroyed. // MessageLoop is destroyed.
static void EnsureForCurrentMessageLoop(); static void EnsureForCurrentMessageLoop();
// Returns thread wrapper for the current thread. NULL is returned // Creates JingleThreadWrapper for |task_runner| that runs tasks on the
// if EnsureForCurrentMessageLoop() has never been called for this // current thread.
// 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(); static JingleThreadWrapper* current();
explicit JingleThreadWrapper(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~JingleThreadWrapper() override; ~JingleThreadWrapper() override;
// Sets whether the thread can be used to send messages // Sets whether the thread can be used to send messages
...@@ -95,6 +97,9 @@ class JingleThreadWrapper : public base::MessageLoop::DestructionObserver, ...@@ -95,6 +97,9 @@ class JingleThreadWrapper : public base::MessageLoop::DestructionObserver,
typedef std::map<int, rtc::Message> MessagesQueue; typedef std::map<int, rtc::Message> MessagesQueue;
struct PendingSend; struct PendingSend;
explicit JingleThreadWrapper(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
void PostTaskInternal( void PostTaskInternal(
int delay_ms, rtc::MessageHandler* handler, int delay_ms, rtc::MessageHandler* handler,
uint32 message_id, rtc::MessageData* data); uint32 message_id, rtc::MessageData* data);
......
...@@ -198,8 +198,8 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) ...@@ -198,8 +198,8 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
// are not shared with Chrome. // are not shared with Chrome.
thread_task_runner_handle_.reset( thread_task_runner_handle_.reset(
new base::ThreadTaskRunnerHandle(plugin_task_runner_)); new base::ThreadTaskRunnerHandle(plugin_task_runner_));
thread_wrapper_.reset( thread_wrapper_ =
new jingle_glue::JingleThreadWrapper(plugin_task_runner_)); jingle_glue::JingleThreadWrapper::WrapTaskRunner(plugin_task_runner_);
media::InitializeCPUSpecificYUVConversions(); media::InitializeCPUSpecificYUVConversions();
// Register a global log handler. // Register a global log handler.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment