Make a fairer combined message loop

This will make us insert a new Message into the java message loop each time a new task is added. When those
tasks are handled we will handle one native task.

This is not the full truth as the Android DoRunLoopOnce does not actually just run the loop once, but that is for a later CL to clear up.

BUG=250924

Review URL: https://chromiumcodereview.appspot.com/18181011

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


CrOS-Libchrome-Original-Commit: d1d787eff9df609988cf852374cb36cf65070a47
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
index 96192a7..bd3542a 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -97,6 +97,16 @@
          static_cast<uint64>(reinterpret_cast<intptr_t>(loop));
 }
 
+// Returns true if MessagePump::ScheduleWork() must be called one
+// time for every task that is added to the MessageLoop incoming queue.
+bool AlwaysNotifyPump(MessageLoop::Type type) {
+#if defined(OS_ANDROID)
+  return type == MessageLoop::TYPE_UI;
+#else
+  return false;
+#endif
+}
+
 }  // namespace
 
 //------------------------------------------------------------------------------
@@ -627,7 +637,9 @@
     bool was_empty = incoming_queue_.empty();
     incoming_queue_.push(*pending_task);
     pending_task->task.Reset();
-    if (!was_empty)
+    // The Android UI message loop needs to get notified each time
+    // a task is added to the incoming queue.
+    if (!was_empty && !AlwaysNotifyPump(type_))
       return true;  // Someone else should have started the sub-pump.
 
     pump = pump_;