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

Unified Diff: base/message_loop/message_pump_android.cc

Issue 18181011: Make a fairer combined message loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improving comment Created 7 years, 5 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/message_loop/message_loop.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_pump_android.cc
diff --git a/base/message_loop/message_pump_android.cc b/base/message_loop/message_pump_android.cc
index 70eb6ef089e7230455cf24a25b0d8ac8ed9cdfb1..f3f1c9bcb4d83bc0f5b94312f1ef64371a4617c7 100644
--- a/base/message_loop/message_pump_android.cc
+++ b/base/message_loop/message_pump_android.cc
@@ -21,7 +21,7 @@ using base::android::ScopedJavaLocalRef;
// ----------------------------------------------------------------------------
// This method can not move to anonymous namespace as it has been declared as
// 'static' in system_message_handler_jni.h.
-static jboolean DoRunLoopOnce(JNIEnv* env, jobject obj, jint native_delegate) {
+static void DoRunLoopOnce(JNIEnv* env, jobject obj, jint native_delegate) {
base::MessagePump::Delegate* delegate =
reinterpret_cast<base::MessagePump::Delegate*>(native_delegate);
DCHECK(delegate);
@@ -31,26 +31,27 @@ static jboolean DoRunLoopOnce(JNIEnv* env, jobject obj, jint native_delegate) {
// we call DoWork() / DoDelayedWork().
// On Android, the java message queue may contain messages for other handlers
// that will be processed before calling here again.
- bool more_work_is_plausible = delegate->DoWork();
+ bool did_work = delegate->DoWork();
// This is the time when we need to do delayed work.
base::TimeTicks delayed_work_time;
- more_work_is_plausible |= delegate->DoDelayedWork(&delayed_work_time);
+ did_work |= delegate->DoDelayedWork(&delayed_work_time);
+
+ // Always call this if there is a delayed message waiting in the queue
+ // since is at most one delayed message in the Java message handler, and this
+ // function call may be the result of that message being handled.
+ if (!delayed_work_time.is_null()) {
+ Java_SystemMessageHandler_setDelayedTimer(env, obj,
+ (delayed_work_time - base::TimeTicks::Now()).InMillisecondsRoundedUp());
+ }
// This is a major difference between android and other platforms: since we
// can't inspect it and process just one single message, instead we'll yeld
- // the callstack, and post a message to call us back soon.
- if (more_work_is_plausible)
- return true;
-
- more_work_is_plausible = delegate->DoIdleWork();
- if (!more_work_is_plausible && !delayed_work_time.is_null()) {
- // We only set the timer here as returning true would post a message.
- jlong millis =
- (delayed_work_time - base::TimeTicks::Now()).InMillisecondsRoundedUp();
- Java_SystemMessageHandler_setDelayedTimer(env, obj, millis);
- }
- return more_work_is_plausible;
+ // the callstack.
+ if (did_work)
+ return;
+
+ delegate->DoIdleWork();
}
namespace base {
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698