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

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 25082006: [Android WebView] OnMemoryPressure to drop tile memory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use level Created 7 years, 2 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
Index: android_webview/java/src/org/chromium/android_webview/AwContents.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index f0f286ffb8adcaf325ccd72bb5cb971b6c1d55ae..08f191d513f4c3a7499013fea7582c4cb99b182b 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -4,6 +4,8 @@
package org.chromium.android_webview;
+import android.content.ComponentCallbacks2;
+import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
@@ -193,6 +195,8 @@ public class AwContents {
private AwAutofillManagerDelegate mAwAutofillManagerDelegate;
+ private ComponentCallbacks2 mComponentCallbacks;
+
private static final class DestroyRunnable implements Runnable {
private int mNativeAwContents;
private DestroyRunnable(int nativeAwContents) {
@@ -431,6 +435,22 @@ public class AwContents {
}
}
+ private class AwComponentCallbacks implements ComponentCallbacks2 {
+ @Override
+ public void onTrimMemory(int level) {
+ if (mNativeAwContents == 0) return;
+ nativeTrimMemory(mNativeAwContents, level);
+ }
+
+ @Override
+ public void onLowMemory() {
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration configuration) {
+ }
+ };
+
/**
* @param browserContext the browsing context to associate this view contents with.
* @param containerView the view-hierarchy item this object will be bound to.
@@ -1480,6 +1500,10 @@ public class AwContents {
mContentViewCore.onAttachedToWindow();
nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth(),
mContainerView.getHeight());
+
+ if (mComponentCallbacks != null) return;
+ mComponentCallbacks = new AwComponentCallbacks();
+ mContainerView.getContext().registerComponentCallbacks(mComponentCallbacks);
}
/**
@@ -1494,6 +1518,11 @@ public class AwContents {
mContentViewCore.onDetachedFromWindow();
+ if (mComponentCallbacks != null) {
+ mContainerView.getContext().unregisterComponentCallbacks(mComponentCallbacks);
+ mComponentCallbacks = null;
+ }
+
if (mPendingDetachCleanupReferences != null) {
for (int i = 0; i < mPendingDetachCleanupReferences.size(); ++i) {
mPendingDetachCleanupReferences.get(i).cleanupNow();
@@ -1967,4 +1996,6 @@ public class AwContents {
int nativeAwContents, boolean value, String requestingFrame);
private native void nativeSetJsOnlineProperty(int nativeAwContents, boolean networkUp);
+
+ private native void nativeTrimMemory(int nativeAwContents, int level);
}

Powered by Google App Engine
This is Rietveld 408576698