| Index: content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java b/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
|
| index 0fa1e03b42803ca14cda4b2365b932d51a39de0c..501b69c257970490fd8bb9b3689d7df8ef9d2364 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
|
| @@ -5,7 +5,9 @@
|
| package org.chromium.content.browser;
|
|
|
| import android.app.ActivityManager;
|
| +import android.content.ComponentCallbacks2;
|
| import android.content.Context;
|
| +import android.content.res.Configuration;
|
|
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| @@ -17,6 +19,10 @@ import org.chromium.base.annotations.JNINamespace;
|
| class MemoryMonitorAndroid {
|
| private static final ActivityManager.MemoryInfo sMemoryInfo =
|
| new ActivityManager.MemoryInfo();
|
| + private static ComponentCallbacks2 sCallbacks = null;
|
| +
|
| + private MemoryMonitorAndroid() {
|
| + }
|
|
|
| /**
|
| * Get the current MemoryInfo from ActivityManager and invoke the native
|
| @@ -36,7 +42,34 @@ class MemoryMonitorAndroid {
|
| sMemoryInfo.threshold, sMemoryInfo.totalMem, outPtr);
|
| }
|
|
|
| + /**
|
| + * Register ComponentCallbacks2 to receive memory pressure signals.
|
| + *
|
| + * @param context The context of the application.
|
| + */
|
| + @CalledByNative
|
| + private static void registerComponentCallbacks(Context context) {
|
| + sCallbacks = new ComponentCallbacks2() {
|
| + @Override
|
| + public void onTrimMemory(int level) {
|
| + if (level != ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
|
| + nativeOnTrimMemory(level);
|
| + }
|
| + }
|
| + @Override
|
| + public void onLowMemory() {
|
| + // Don't support old onLowMemory().
|
| + }
|
| + @Override
|
| + public void onConfigurationChanged(Configuration config) {
|
| + }
|
| + };
|
| + context.registerComponentCallbacks(sCallbacks);
|
| + }
|
| +
|
| private static native void nativeGetMemoryInfoCallback(
|
| long availMem, boolean lowMemory,
|
| long threshold, long totalMem, long outPtr);
|
| +
|
| + private static native void nativeOnTrimMemory(int level);
|
| }
|
|
|