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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java

Issue 2486573003: memory coordinator: Add metrics for Android's onTrimMemory() (Closed)
Patch Set: comments addressed Created 4 years, 1 month 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 | « content/browser/memory/memory_monitor_android.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « content/browser/memory/memory_monitor_android.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698