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

Unified 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: phajdan feedback 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
« no previous file with comments | « base/base.gypi ('k') | base/message_loop.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop.h
diff --git a/base/message_loop.h b/base/message_loop.h
index a92ff7e2660f8afff037bd291c2c1a6de2d5ddf8..227bfe3d8a1cb3b06d55bb05f13fed12825659c1 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -42,7 +42,11 @@
namespace base {
class Histogram;
+class RunLoop;
class ThreadTaskRunnerHandle;
+#if defined(OS_ANDROID)
+class MessagePumpForUI;
+#endif
} // namespace base
// A MessageLoop is used to process events for a particular thread. There is
@@ -209,30 +213,51 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
this, from_here, object);
}
+ // Deprecated: use RunLoop instead.
// Run the message loop.
void Run();
+ // Deprecated: use RunLoop instead.
// Process all pending tasks, windows messages, etc., but don't wait/sleep.
// Return as soon as all items that can be run are taken care of.
- void RunAllPending();
+ void RunUntilIdle();
+
+ // TODO(jbates) remove this. crbug.com/131220. See RunUntilIdle().
+ void RunAllPending() { RunUntilIdle(); }
+
+ // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdle().
+ void Quit() { QuitWhenIdle(); }
- // Signals the Run method to return after it is done processing all pending
- // messages. This method may only be called on the same thread that called
- // Run, and Run must still be on the call stack.
+ // Deprecated: use RunLoop instead.
//
- // Use QuitClosure if you need to Quit another thread's MessageLoop, but note
- // that doing so is fairly dangerous if the target thread makes nested calls
- // to MessageLoop::Run. The problem being that you won't know which nested
- // run loop you are quitting, so be careful!
- void Quit();
+ // Signals the Run method to return when it becomes idle. It will continue to
+ // process pending messages and future messages as long as they are enqueued.
+ // Warning: if the MessageLoop remains busy, it may never quit. Only use this
+ // Quit method when looping procedures (such as web pages) have been shut
+ // down.
+ //
+ // This method may only be called on the same thread that called Run, and Run
+ // must still be on the call stack.
+ //
+ // Use QuitClosure variants if you need to Quit another thread's MessageLoop,
+ // but note that doing so is fairly dangerous if the target thread makes
+ // nested calls to MessageLoop::Run. The problem being that you won't know
+ // which nested run loop you are quitting, so be careful!
+ void QuitWhenIdle();
+ // Deprecated: use RunLoop instead.
+ //
// This method is a variant of Quit, that does not wait for pending messages
// to be processed before returning from Run.
void QuitNow();
- // Invokes Quit on the current MessageLoop when run. Useful to schedule an
- // arbitrary MessageLoop to Quit.
- static base::Closure QuitClosure();
+ // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdleClosure().
+ static base::Closure QuitClosure() { return QuitWhenIdleClosure(); }
+
+ // Deprecated: use RunLoop instead.
+ // Construct a Closure that will call QuitWhenIdle(). Useful to schedule an
+ // arbitrary MessageLoop to QuitWhenIdle.
+ static base::Closure QuitWhenIdleClosure();
// Returns the type passed to the constructor.
Type type() const { return type_; }
@@ -354,35 +379,7 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
//----------------------------------------------------------------------------
protected:
- struct RunState {
- // Used to count how many Run() invocations are on the stack.
- int run_depth;
-
- // Used to record that Quit() was called, or that we should quit the pump
- // once it becomes idle.
- bool quit_received;
-
-#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
- Dispatcher* dispatcher;
-#endif
- };
-
-#if defined(OS_ANDROID)
- // Android Java process manages the UI thread message loop. So its
- // MessagePumpForUI needs to keep the RunState.
- public:
-#endif
- class BASE_EXPORT AutoRunState : RunState {
- public:
- explicit AutoRunState(MessageLoop* loop);
- ~AutoRunState();
- private:
- MessageLoop* loop_;
- RunState* previous_state_;
- };
-#if defined(OS_ANDROID)
- protected:
-#endif
+ friend class base::RunLoop;
#if defined(OS_WIN)
base::MessagePumpWin* pump_win() {
@@ -496,7 +493,7 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
// Protect access to incoming_queue_.
mutable base::Lock incoming_queue_lock_;
- RunState* state_;
+ base::RunLoop* run_loop_;
#if defined(OS_WIN)
base::TimeTicks high_resolution_timer_expiration_;
@@ -525,7 +522,6 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
void(*releaser)(const void*),
const void* object);
-
DISALLOW_COPY_AND_ASSIGN(MessageLoop);
};
@@ -563,8 +559,6 @@ class BASE_EXPORT MessageLoopForUI : public MessageLoop {
// methods.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
- void RunWithDispatcher(Dispatcher* dispatcher);
- void RunAllPendingWithDispatcher(Dispatcher* dispatcher);
protected:
// TODO(rvargas): Make this platform independent.
« no previous file with comments | « base/base.gypi ('k') | base/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698