[base] Migrate Android's MessagePumpForUI to DoSomeWork().
The tricky part is the need to yield to java before declaring
idle. Previously this was done by only yielding to java if we
did any work. With DoSomeWork() however we do not know if we
did any work, we only know whether there's more work to come.
As such we use a special bit to yield to java once and declare
idle if no other work is scheduled in-between now and java
invoking us again.
Bug: 885371
Change-Id: Id9c8271cc216d06a2db7b9a95636fe87b285eb93
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1485130
Reviewed-by: Alex Clarke <[email protected]>
Reviewed-by: Michael Thiessen <[email protected]>
Commit-Queue: Gabriel Charette <[email protected]>
Auto-Submit: Gabriel Charette <[email protected]>
Cr-Commit-Position: refs/heads/master@{#654883}
diff --git a/base/message_loop/message_pump_android.h b/base/message_loop/message_pump_android.h
index d7e0f50..a6014b4 100644
--- a/base/message_loop/message_pump_android.h
+++ b/base/message_loop/message_pump_android.h
@@ -14,6 +14,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/message_loop/message_pump.h"
+#include "base/optional.h"
#include "base/time/time.h"
struct ALooper;
@@ -79,8 +80,10 @@
Delegate* delegate_ = nullptr;
// The time at which we are currently scheduled to wake up and perform a
- // delayed task.
- base::TimeTicks delayed_scheduled_time_;
+ // delayed task. This avoids redundantly scheduling |delayed_fd_| with the
+ // same timeout when subsequent work phases all go idle on the same pending
+ // delayed task; nullopt if no wakeup is currently scheduled.
+ Optional<TimeTicks> delayed_scheduled_time_;
// If set, a callback to fire when the message pump is quit.
base::OnceClosure on_quit_callback_;