base::Bind: Cleanup in automation.

BUG=none
TEST=none

R=csilv@chromium.org

Review URL: http://codereview.chromium.org/8212006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105761 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 8c6517e5e15b7e9a3d3c95f697f674d221968acc
diff --git a/base/message_loop.cc b/base/message_loop.cc
index ce5e900..f2e07b9 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -306,7 +306,7 @@
 
 void MessageLoop::PostTask(
     const tracked_objects::Location& from_here, const base::Closure& task) {
-  CHECK(!task.is_null());
+  CHECK(!task.is_null()) << from_here.ToString();
   PendingTask pending_task(task, from_here, CalculateDelayedRuntime(0), true);
   AddToIncomingQueue(&pending_task);
 }
@@ -314,7 +314,7 @@
 void MessageLoop::PostDelayedTask(
     const tracked_objects::Location& from_here, const base::Closure& task,
     int64 delay_ms) {
-  CHECK(!task.is_null());
+  CHECK(!task.is_null()) << from_here.ToString();
   PendingTask pending_task(task, from_here,
                            CalculateDelayedRuntime(delay_ms), true);
   AddToIncomingQueue(&pending_task);
@@ -322,7 +322,7 @@
 
 void MessageLoop::PostNonNestableTask(
     const tracked_objects::Location& from_here, const base::Closure& task) {
-  CHECK(!task.is_null());
+  CHECK(!task.is_null()) << from_here.ToString();
   PendingTask pending_task(task, from_here, CalculateDelayedRuntime(0), false);
   AddToIncomingQueue(&pending_task);
 }
@@ -330,7 +330,7 @@
 void MessageLoop::PostNonNestableDelayedTask(
     const tracked_objects::Location& from_here, const base::Closure& task,
     int64 delay_ms) {
-  CHECK(!task.is_null());
+  CHECK(!task.is_null()) << from_here.ToString();
   PendingTask pending_task(task, from_here,
                            CalculateDelayedRuntime(delay_ms), false);
   AddToIncomingQueue(&pending_task);
@@ -365,6 +365,12 @@
   }
 }
 
+// static
+base::Closure MessageLoop::QuitClosure() {
+  return base::Bind(&MessageLoop::Quit,
+                    base::Unretained(MessageLoop::current()));
+}
+
 void MessageLoop::SetNestableTasksAllowed(bool allowed) {
   if (nestable_tasks_allowed_ != allowed) {
     nestable_tasks_allowed_ = allowed;
diff --git a/base/message_loop.h b/base/message_loop.h
index 29c736c..adb58e3 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -242,11 +242,10 @@
   // messages.  This method may only be called on the same thread that called
   // Run, and Run must still be on the call stack.
   //
-  // Use QuitTask 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 quiting, so be careful!
-  //
+  // Use QuitTask or 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();
 
   // This method is a variant of Quit, that does not wait for pending messages
@@ -255,6 +254,7 @@
 
   // Invokes Quit on the current MessageLoop when run.  Useful to schedule an
   // arbitrary MessageLoop to Quit.
+  // TODO(jhawkins): Remove once task.h is removed.
   class QuitTask : public Task {
    public:
     virtual void Run() {
@@ -262,6 +262,10 @@
     }
   };
 
+  // Invokes Quit on the current MessageLoop when run. Useful to schedule an
+  // arbitrary MessageLoop to Quit.
+  static base::Closure QuitClosure();
+
   // Returns the type passed to the constructor.
   Type type() const { return type_; }