Allow MessageLoop to attempt to queue tasks on message_pump_android after calling Quit().

Like other platform implementations, tasks queued up after quitting will
simply not be run.

Bug: 758738
Change-Id: I3c7badbb5c1fe4e91856dfdaa49b16e016f9f8b1
Reviewed-on: https://chromium-review.googlesource.com/634158
Commit-Queue: Michael Thiessen <[email protected]>
Reviewed-by: Yaron Friedman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#497874}
diff --git a/base/message_loop/message_pump_android.cc b/base/message_loop/message_pump_android.cc
index 4be8899..5326658 100644
--- a/base/message_loop/message_pump_android.cc
+++ b/base/message_loop/message_pump_android.cc
@@ -117,11 +117,8 @@
 
 namespace base {
 
-MessagePumpForUI::MessagePumpForUI()
-    : run_loop_(nullptr), should_abort_(false) {}
-
-MessagePumpForUI::~MessagePumpForUI() {
-}
+MessagePumpForUI::MessagePumpForUI() = default;
+MessagePumpForUI::~MessagePumpForUI() = default;
 
 void MessagePumpForUI::Run(Delegate* delegate) {
   NOTREACHED() << "UnitTests should rely on MessagePumpForUIStub in"
@@ -129,6 +126,7 @@
 }
 
 JNIEnv* MessagePumpForUI::StartInternal() {
+  DCHECK(!quit_);
   run_loop_ = new RunLoop();
   // Since the RunLoop was just created above, BeforeRun should be guaranteed to
   // return true (it only returns false if the RunLoop has been Quit already).
@@ -159,6 +157,7 @@
 }
 
 void MessagePumpForUI::Quit() {
+  quit_ = true;
   if (!system_message_handler_obj_.is_null()) {
     JNIEnv* env = base::android::AttachCurrentThread();
     DCHECK(env);
@@ -176,6 +175,8 @@
 }
 
 void MessagePumpForUI::ScheduleWork() {
+  if (quit_)
+    return;
   DCHECK(!system_message_handler_obj_.is_null());
 
   JNIEnv* env = base::android::AttachCurrentThread();
@@ -185,6 +186,8 @@
 }
 
 void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) {
+  if (quit_)
+    return;
   DCHECK(!system_message_handler_obj_.is_null());
 
   JNIEnv* env = base::android::AttachCurrentThread();