From 81dec47c83622b28e63024c8ee3a76622eb00c62 Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Mon, 8 Oct 2012 22:46:18 -0600 Subject: [PATCH] Bug 797239 - Fix message loop to allow idle tasks to work in child content processes. r=cjones --- ipc/chromium/src/base/message_loop.cc | 11 +++++++++-- ipc/chromium/src/base/message_loop.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ipc/chromium/src/base/message_loop.cc b/ipc/chromium/src/base/message_loop.cc index 7900c6153d7..bcdd71fc9cf 100644 --- a/ipc/chromium/src/base/message_loop.cc +++ b/ipc/chromium/src/base/message_loop.cc @@ -90,6 +90,7 @@ MessageLoop::MessageLoop(Type type) nestable_tasks_allowed_(true), exception_restoration_(false), state_(NULL), + run_depth_base_(1), #ifdef OS_WIN os_modal_loop_(false), #endif // OS_WIN @@ -102,6 +103,12 @@ MessageLoop::MessageLoop(Type type) } if (type_ == TYPE_MOZILLA_CHILD) { pump_ = new mozilla::ipc::MessagePumpForChildProcess(); + // There is a MessageLoop Run call from XRE_InitChildProcess + // and another one from MessagePumpForChildProcess. The one + // from MessagePumpForChildProcess becomes the base, so we need + // to set run_depth_base_ to 2 or we'll never be able to process + // Idle tasks. + run_depth_base_ = 2; return; } @@ -212,7 +219,7 @@ void MessageLoop::RunInternal() { // Wrapper functions for use in above message loop framework. bool MessageLoop::ProcessNextDelayedNonNestableTask() { - if (state_->run_depth != 1) + if (state_->run_depth > run_depth_base_) return false; if (deferred_non_nestable_work_queue_.empty()) @@ -330,7 +337,7 @@ void MessageLoop::RunTask(Task* task) { } bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { - if (pending_task.nestable || state_->run_depth == 1) { + if (pending_task.nestable || state_->run_depth >= run_depth_base_) { RunTask(pending_task.task); // Show that we ran a task (Note: a new one might arrive as a // consequence!). diff --git a/ipc/chromium/src/base/message_loop.h b/ipc/chromium/src/base/message_loop.h index e3de53f7bd2..0dc02dafc52 100644 --- a/ipc/chromium/src/base/message_loop.h +++ b/ipc/chromium/src/base/message_loop.h @@ -408,6 +408,7 @@ public: Lock incoming_queue_lock_; RunState* state_; + int run_depth_base_; #if defined(OS_WIN) // Should be set to true before calling Windows APIs like TrackPopupMenu, etc