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

Side by Side Diff: base/message_loop.h

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: more test fixes 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | chrome/test/base/ui_test_utils.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MESSAGE_LOOP_H_ 5 #ifndef BASE_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 this, from_here, object); 217 this, from_here, object);
218 } 218 }
219 219
220 // Run the message loop. 220 // Run the message loop.
221 void Run(); 221 void Run();
222 222
223 // Process all pending tasks, windows messages, etc., but don't wait/sleep. 223 // Process all pending tasks, windows messages, etc., but don't wait/sleep.
224 // Return as soon as all items that can be run are taken care of. 224 // Return as soon as all items that can be run are taken care of.
225 void RunAllPending(); 225 void RunAllPending();
226 226
227 // Signals the Run method to return after it is done processing all pending 227 // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdle().
228 // messages. This method may only be called on the same thread that called 228 void Quit() { QuitWhenIdle(); }
229 // Run, and Run must still be on the call stack. 229
230 // Signals the Run method to return when it becomes idle. It will continue to
231 // process pending messages and future messages as long as they are enqueued.
232 // Warning: if the MessageLoop remains busy, it may never quit. Only use this
233 // Quit method when looping procedures (such as web pages) have been shut
234 // down.
230 // 235 //
231 // Use QuitClosure if you need to Quit another thread's MessageLoop, but note 236 // This method may only be called on the same thread that called Run, and Run
232 // that doing so is fairly dangerous if the target thread makes nested calls 237 // must still be on the call stack.
233 // to MessageLoop::Run. The problem being that you won't know which nested 238 //
234 // run loop you are quitting, so be careful! 239 // Use Quit*Closure variants if you need to Quit another thread's MessageLoop,
235 void Quit(); 240 // but note that doing so is fairly dangerous if the target thread makes
241 // nested calls to MessageLoop::Run. The problem being that you won't know
242 // which nested run loop you are quitting, so be careful!
243 void QuitWhenIdle();
236 244
237 // This method is a variant of Quit, that does not wait for pending messages 245 // This method is a variant of Quit, that does not wait for pending messages
238 // to be processed before returning from Run. 246 // to be processed before returning from Run.
239 void QuitNow(); 247 void QuitNow();
240 248
241 // Invokes Quit on the current MessageLoop when run. Useful to schedule an 249 // This method is a variant of Quit, that only waits for the currently pending
242 // arbitrary MessageLoop to Quit. 250 // messages to complete. Any new messages after this call will not be
243 static base::Closure QuitClosure(); 251 // processed and will remain enqueued on the MessageLoop.
252 void QuitAfterPending();
jar (doing other things) 2012/06/08 01:05:37 nit: I think this is now too terse. I read it as:
jbates 2012/06/13 22:11:20 Removed it since it wasn't adding more than QuitNo
253
254 // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdleClosure().
255 static base::Closure QuitClosure() { return QuitWhenIdleClosure(); }
256
257 // Invokes QuitWhenIdle on the current MessageLoop when run. Useful to
jar (doing other things) 2012/06/08 01:05:37 nit: I don't think "current MessageLoop" should be
jbates 2012/06/13 22:11:20 Done.
258 // schedule an arbitrary MessageLoop to QuitWhenIdle.
259 static base::Closure QuitWhenIdleClosure();
260
261 // Invokes QuitNow on the current MessageLoop when run. Useful to schedule an
262 // arbitrary MessageLoop to QuitNow.
263 static base::Closure QuitNowClosure();
264
265 // Invokes QuitAfterPending on the current MessageLoop when run. Useful to
266 // schedule an arbitrary MessageLoop to QuitAfterPending.
267 static base::Closure QuitAfterPendingClosure();
244 268
245 // Returns the type passed to the constructor. 269 // Returns the type passed to the constructor.
246 Type type() const { return type_; } 270 Type type() const { return type_; }
247 271
248 // Optional call to connect the thread name with this loop. 272 // Optional call to connect the thread name with this loop.
249 void set_thread_name(const std::string& thread_name) { 273 void set_thread_name(const std::string& thread_name) {
250 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; 274 DCHECK(thread_name_.empty()) << "Should not rename this thread!";
251 thread_name_ = thread_name; 275 thread_name_ = thread_name;
252 } 276 }
253 const std::string& thread_name() const { return thread_name_; } 277 const std::string& thread_name() const { return thread_name_; }
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 #endif // defined(OS_POSIX) 683 #endif // defined(OS_POSIX)
660 }; 684 };
661 685
662 // Do not add any member variables to MessageLoopForIO! This is important b/c 686 // Do not add any member variables to MessageLoopForIO! This is important b/c
663 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 687 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
664 // data that you need should be stored on the MessageLoop's pump_ instance. 688 // data that you need should be stored on the MessageLoop's pump_ instance.
665 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 689 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
666 MessageLoopForIO_should_not_have_extra_member_variables); 690 MessageLoopForIO_should_not_have_extra_member_variables);
667 691
668 #endif // BASE_MESSAGE_LOOP_H_ 692 #endif // BASE_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | chrome/test/base/ui_test_utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698