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

Unified Diff: base/message_loop.cc

Issue 10479018: Add base::RunLoop and update ui_test_utils to use it to reduce flakiness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added printfs to debug timeout which doesn't happen locally Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: base/message_loop.cc
diff --git a/base/message_loop.cc b/base/message_loop.cc
index a207659a4a922203a2e3850bbcdde4b1425dd21d..40dabb25e1ca2331cf3e25b39aa28088f6b0f8ca 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -135,7 +135,8 @@ MessageLoop::MessageLoop(Type type)
#ifdef OS_WIN
os_modal_loop_(false),
#endif // OS_WIN
- next_sequence_num_(0) {
+ next_sequence_num_(0),
+ current_run_state_id_(0) {
DCHECK(!current()) << "should only have one message loop per thread";
lazy_tls_ptr.Pointer()->Set(this);
@@ -313,7 +314,7 @@ void MessageLoop::RunAllPending() {
RunHandler();
}
-void MessageLoop::Quit() {
+void MessageLoop::QuitWhenIdle() {
DCHECK_EQ(this, current());
if (state_) {
state_->quit_received = true;
@@ -331,13 +332,49 @@ void MessageLoop::QuitNow() {
}
}
-static void QuitCurrent() {
- MessageLoop::current()->Quit();
+void MessageLoop::QuitNowByID(int run_id) {
+ DCHECK_EQ(this, current());
+ if (!state_)
+ return;
+ if (state_->run_state_id == run_id)
+ QuitNow();
+
+ // Search back through RunStates for run_id.
+ RunState* run_state = state_;
+ while (run_state) {
+ if (run_state->run_state_id == run_id) {
+ run_state->quit_now_received = true;
+ break;
+ }
+ run_state = run_state->previous_state;
+ }
+}
+
+static void QuitWhenIdleCurrent() {
+ MessageLoop::current()->QuitWhenIdle();
+}
+
+static void QuitNowCurrent() {
+ MessageLoop::current()->QuitNow();
+}
+
+static void QuitNowByIDCurrent(int run_id) {
jar (doing other things) 2012/06/14 04:50:29 nit: I think the word "current" is in the wrong pl
jbates 2012/06/15 02:20:38 Done.
+ MessageLoop::current()->QuitNowByID(run_id);
+}
+
+// static
+base::Closure MessageLoop::QuitWhenIdleClosure() {
+ return base::Bind(&QuitWhenIdleCurrent);
}
// static
-base::Closure MessageLoop::QuitClosure() {
- return base::Bind(&QuitCurrent);
+base::Closure MessageLoop::QuitNowClosure() {
+ return base::Bind(&QuitNowCurrent);
+}
+
+// static
+base::Closure MessageLoop::QuitNowByIDClosure(int run_id) {
+ return base::Bind(&QuitNowByIDCurrent, run_id);
}
void MessageLoop::SetNestableTasksAllowed(bool allowed) {
@@ -720,23 +757,28 @@ void MessageLoop::ReleaseSoonInternal(
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;
+ previous_state = loop_->state_;
+ if (previous_state) {
+ run_depth = previous_state->run_depth + 1;
} else {
run_depth = 1;
}
loop_->state_ = this;
+ run_state_id = ++loop_->current_run_state_id_;
+
// Initialize the other fields:
quit_received = false;
+ quit_now_received = false;
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
dispatcher = NULL;
#endif
}
MessageLoop::AutoRunState::~AutoRunState() {
- loop_->state_ = previous_state_;
+ loop_->state_ = previous_state;
+ if (previous_state && previous_state->quit_now_received)
+ MessageLoop::current()->QuitNow();
}
//------------------------------------------------------------------------------

Powered by Google App Engine
This is Rietveld 408576698