diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-28 22:57:30 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-28 22:57:30 +0000 |
commit | 8e937c1e6a1cf0bdce081324965e105a6b17a3fc (patch) | |
tree | ffec2c670d3ceb188c0c1244b846b15adbe7838e /base/message_loop.cc | |
parent | ed50d3ee0ed2e26da0ff805dc52ee0c03f80df2e (diff) | |
download | chromium_src-8e937c1e6a1cf0bdce081324965e105a6b17a3fc.zip chromium_src-8e937c1e6a1cf0bdce081324965e105a6b17a3fc.tar.gz chromium_src-8e937c1e6a1cf0bdce081324965e105a6b17a3fc.tar.bz2 |
Add base::RunLoop and update ui_test_utils to use it to reduce flakiness
Timeout flakiness has been observed in multiple tests that use Quit. This changes various test utility APIs to use QuitNow via base::RunLoop instead. Some instances of Quit are left as-is where it appears they may have a use case.
The ui_test_utils QuitThisRunLoop function does a safer form of MessageLoop::QuitWhenIdle that allows a few generations of tasks to run before actually quitting the MessageLoop. This addresses the design assumptions of many existing tests while hopefully reducing flaky timeouts by moving away from QuitWhenIdle.
This fixes throughput_tests.cc which is currently timing out on Mac.
BUG=124906,130141,131220,128305,132932
Review URL: https://chromiumcodereview.appspot.com/10479018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop.cc')
-rw-r--r-- | base/message_loop.cc | 83 |
1 files changed, 23 insertions, 60 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc index b040ecc..8eb4e3b 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -16,6 +16,7 @@ #include "base/message_loop_proxy_impl.h" #include "base/message_pump_default.h" #include "base/metrics/histogram.h" +#include "base/run_loop.h" #include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/thread_task_runner_handle.h" #include "base/threading/thread_local.h" @@ -131,7 +132,7 @@ MessageLoop::MessageLoop(Type type) nestable_tasks_allowed_(true), exception_restoration_(false), message_histogram_(NULL), - state_(NULL), + run_loop_(NULL), #ifdef OS_WIN os_modal_loop_(false), #endif // OS_WIN @@ -180,7 +181,7 @@ MessageLoop::MessageLoop(Type type) MessageLoop::~MessageLoop() { DCHECK_EQ(this, current()); - DCHECK(!state_); + DCHECK(!run_loop_); // Clean up any unprocessed tasks, but take care: deleting a task could // result in the addition of more tasks (e.g., via DeleteSoon). We set a @@ -293,20 +294,19 @@ void MessageLoop::PostNonNestableDelayedTask( } void MessageLoop::Run() { - AutoRunState save_state(this); - RunHandler(); + base::RunLoop run_loop; + run_loop.Run(); } -void MessageLoop::RunAllPending() { - AutoRunState save_state(this); - state_->quit_received = true; // Means run until we would otherwise block. - RunHandler(); +void MessageLoop::RunUntilIdle() { + base::RunLoop run_loop; + run_loop.RunUntilIdle(); } -void MessageLoop::Quit() { +void MessageLoop::QuitWhenIdle() { DCHECK_EQ(this, current()); - if (state_) { - state_->quit_received = true; + if (run_loop_) { + run_loop_->quit_when_idle_received_ = true; } else { NOTREACHED() << "Must be inside Run to call Quit"; } @@ -314,20 +314,20 @@ void MessageLoop::Quit() { void MessageLoop::QuitNow() { DCHECK_EQ(this, current()); - if (state_) { + if (run_loop_) { pump_->Quit(); } else { NOTREACHED() << "Must be inside Run to call Quit"; } } -static void QuitCurrent() { - MessageLoop::current()->Quit(); +static void QuitCurrentWhenIdle() { + MessageLoop::current()->QuitWhenIdle(); } // static -base::Closure MessageLoop::QuitClosure() { - return base::Bind(&QuitCurrent); +base::Closure MessageLoop::QuitWhenIdleClosure() { + return base::Bind(&QuitCurrentWhenIdle); } void MessageLoop::SetNestableTasksAllowed(bool allowed) { @@ -345,7 +345,7 @@ bool MessageLoop::NestableTasksAllowed() const { } bool MessageLoop::IsNested() { - return state_->run_depth > 1; + return run_loop_->run_depth_ > 1; } void MessageLoop::AddTaskObserver(TaskObserver* task_observer) { @@ -366,7 +366,7 @@ void MessageLoop::AssertIdle() const { bool MessageLoop::is_running() const { DCHECK_EQ(this, current()); - return state_ != NULL; + return run_loop_ != NULL; } //------------------------------------------------------------------------------ @@ -404,9 +404,9 @@ void MessageLoop::RunInternal() { StartHistogrammer(); #if !defined(OS_MACOSX) && !defined(OS_ANDROID) - if (state_->dispatcher && type() == TYPE_UI) { + if (run_loop_->dispatcher_ && type() == TYPE_UI) { static_cast<base::MessagePumpForUI*>(pump_.get())-> - RunWithDispatcher(this, state_->dispatcher); + RunWithDispatcher(this, run_loop_->dispatcher_); return; } #endif @@ -415,7 +415,7 @@ void MessageLoop::RunInternal() { } bool MessageLoop::ProcessNextDelayedNonNestableTask() { - if (state_->run_depth != 1) + if (run_loop_->run_depth_ != 1) return false; if (deferred_non_nestable_work_queue_.empty()) @@ -463,7 +463,7 @@ void MessageLoop::RunTask(const PendingTask& pending_task) { } bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { - if (pending_task.nestable || state_->run_depth == 1) { + if (pending_task.nestable || run_loop_->run_depth_ == 1) { RunTask(pending_task); // Show that we ran a task (Note: a new one might arrive as a // consequence!). @@ -685,7 +685,7 @@ bool MessageLoop::DoIdleWork() { if (ProcessNextDelayedNonNestableTask()) return true; - if (state_->quit_received) + if (run_loop_->quit_when_idle_received_) pump_->Quit(); return false; @@ -705,30 +705,6 @@ void MessageLoop::ReleaseSoonInternal( } //------------------------------------------------------------------------------ -// MessageLoop::AutoRunState - -MessageLoop::AutoRunState::AutoRunState(MessageLoop* loop) : loop_(loop) { - // Make the loop reference us. - previous_state_ = loop_->state_; - if (previous_state_) { - run_depth = previous_state_->run_depth + 1; - } else { - run_depth = 1; - } - loop_->state_ = this; - - // Initialize the other fields: - quit_received = false; -#if !defined(OS_MACOSX) && !defined(OS_ANDROID) - dispatcher = NULL; -#endif -} - -MessageLoop::AutoRunState::~AutoRunState() { - loop_->state_ = previous_state_; -} - -//------------------------------------------------------------------------------ // MessageLoopForUI #if defined(OS_WIN) @@ -753,19 +729,6 @@ void MessageLoopForUI::RemoveObserver(Observer* observer) { pump_ui()->RemoveObserver(observer); } -void MessageLoopForUI::RunWithDispatcher(Dispatcher* dispatcher) { - AutoRunState save_state(this); - state_->dispatcher = dispatcher; - RunHandler(); -} - -void MessageLoopForUI::RunAllPendingWithDispatcher(Dispatcher* dispatcher) { - AutoRunState save_state(this); - state_->dispatcher = dispatcher; - state_->quit_received = true; // Means run until we would otherwise block. - RunHandler(); -} - #endif // !defined(OS_MACOSX) && !defined(OS_NACL) && !defined(OS_ANDROID) //------------------------------------------------------------------------------ |