summaryrefslogtreecommitdiffstats
path: root/android_webview/java
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-18 12:42:13 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-18 12:42:13 +0000
commit4b32e53918a98e05c5caac8300ec7cfa5f91f47e (patch)
treea76357d76527f1f29fbdb5dfc4ede6e0f6f33823 /android_webview/java
parent1a662f20c0652c9f2bf7e576bde6d7ae109143c8 (diff)
downloadchromium_src-4b32e53918a98e05c5caac8300ec7cfa5f91f47e.zip
chromium_src-4b32e53918a98e05c5caac8300ec7cfa5f91f47e.tar.gz
chromium_src-4b32e53918a98e05c5caac8300ec7cfa5f91f47e.tar.bz2
rate limit onNewPicture to 2 per second max
This stops rapid content changes from stealing UI thread time away from screen updates NOTRY=true BUG=275045 Review URL: https://chromiumcodereview.appspot.com/22884012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218195 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/java')
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java
index 14962ec..c792a18 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java
@@ -8,6 +8,7 @@ import android.graphics.Picture;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
+import android.os.SystemClock;
import org.chromium.content.browser.ContentViewCore;
@@ -75,6 +76,13 @@ class AwContentsClientCallbackHelper {
private final static int MSG_ON_RECEIVED_ERROR = 5;
private final static int MSG_ON_NEW_PICTURE = 6;
+ // Minimum period allowed between consecutive onNewPicture calls, to rate-limit the callbacks.
+ private static final long ON_NEW_PICTURE_MIN_PERIOD_MILLIS = 500;
+ // Timestamp of the most recent onNewPicture callback.
+ private long mLastPictureTime = 0;
+ // True when a onNewPicture callback is currenly in flight.
+ private boolean mHasPendingOnNewPicture = false;
+
private final AwContentsClient mContentsClient;
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
@@ -116,6 +124,8 @@ class AwContentsClientCallbackHelper {
throw new RuntimeException("Error getting picture", e);
}
mContentsClient.onNewPicture(picture);
+ mLastPictureTime = SystemClock.uptimeMillis();
+ mHasPendingOnNewPicture = false;
break;
}
default:
@@ -155,6 +165,11 @@ class AwContentsClientCallbackHelper {
}
public void postOnNewPicture(Callable<Picture> pictureProvider) {
- mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_NEW_PICTURE, pictureProvider));
+ if (mHasPendingOnNewPicture) return;
+ mHasPendingOnNewPicture = true;
+ long pictureTime = java.lang.Math.max(mLastPictureTime + ON_NEW_PICTURE_MIN_PERIOD_MILLIS,
+ SystemClock.uptimeMillis());
+ mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ON_NEW_PICTURE, pictureProvider),
+ pictureTime);
}
}