From 358d2cd96403383cfb91bb68598a4cb2fe2e170e Mon Sep 17 00:00:00 2001 From: "Shimeng (Simon) Wang" Date: Mon, 23 May 2011 09:33:31 -0700 Subject: [PATCH] Simplify browser pause/resume logic to avoid stuck timer. The current browser pause/resume logic uses an integer count to track the pause/resume behavior, which is mostly working fine in phone. The interger count is usually 0 when browser is paused, and its value is usually 1 when the browser is resumed and will trigger any delayed timer. But in tablet, where tabs can be easily created/switched/deleted, this logic will not work well and sometimes cause resources timers get stuck. For example, in case multiple tabs are created, and you reload one of the tabs, when it's almost finished, switch to another tab, and hit home or power button, at this point of time, the browser will be suspended at Controller.java::onPause, hence the integer count will be 0; but since the other tab is also finished after the pause, the current logic at Controller.java::onPageFinished will call pause timer again, which will make the integer count to be -1. Before the time the browser is resumed, it's very possible some tabs will have some resources, such as images/flashs, scheduled to be loaded, these will be in delayed timer in ResourceLoadScheduler.cpp's m_requestTimer. Now when the browser is resumed, the integer count will be 0, which will not trigger delayed timer. Then all the new timers will be stuck as well since old timers are not executed yet. The fix is to simplify the pause/resume logic by just using a boolean variable instead of error-prone integer counting. issue: 4177932 Change-Id: Id10af9298c7be1f82222d0b94c34c5dc68403630 --- core/java/android/webkit/JWebCoreJavaBridge.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/java/android/webkit/JWebCoreJavaBridge.java b/core/java/android/webkit/JWebCoreJavaBridge.java index 976e7868c1196..12391dfe7885a 100644 --- a/core/java/android/webkit/JWebCoreJavaBridge.java +++ b/core/java/android/webkit/JWebCoreJavaBridge.java @@ -39,9 +39,6 @@ final class JWebCoreJavaBridge extends Handler { // immediately. private boolean mHasInstantTimer; - // Reference count the pause/resume of timers - private int mPauseTimerRefCount; - private boolean mTimerPaused; private boolean mHasDeferredTimers; @@ -136,7 +133,7 @@ final class JWebCoreJavaBridge extends Handler { * Pause all timers. */ public void pause() { - if (--mPauseTimerRefCount == 0) { + if (!mTimerPaused) { mTimerPaused = true; mHasDeferredTimers = false; } @@ -146,7 +143,7 @@ final class JWebCoreJavaBridge extends Handler { * Resume all timers. */ public void resume() { - if (++mPauseTimerRefCount == 1) { + if (mTimerPaused) { mTimerPaused = false; if (mHasDeferredTimers) { mHasDeferredTimers = false;