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

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

Issue 2340293003: Add MemoryMonitorAndroid (Closed)
Patch Set: Use native callback instead of returning MemoryInfo Created 4 years, 3 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: 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 9053da8927fd739279c81716afc09ea1aa60a9f9..0fa1e03b42803ca14cda4b2365b932d51a39de0c 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
@@ -15,12 +15,28 @@ import org.chromium.base.annotations.JNINamespace;
*/
@JNINamespace("content")
class MemoryMonitorAndroid {
+ private static final ActivityManager.MemoryInfo sMemoryInfo =
+ new ActivityManager.MemoryInfo();
+
+ /**
+ * Get the current MemoryInfo from ActivityManager and invoke the native
+ * callback to populate the MemoryInfo.
+ *
+ * @param context The context of the application.
+ * @param outPtr A native output pointer to populate MemoryInfo. This is
+ * passed back to the native callback.
+ */
@CalledByNative
- private static ActivityManager.MemoryInfo getMemoryInfo(Context context) {
+ private static void getMemoryInfo(Context context, long outPtr) {
ActivityManager am = (ActivityManager) context.getSystemService(
Context.ACTIVITY_SERVICE);
- ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
- am.getMemoryInfo(info);
- return info;
+ am.getMemoryInfo(sMemoryInfo);
+ nativeGetMemoryInfoCallback(
+ sMemoryInfo.availMem, sMemoryInfo.lowMemory,
+ sMemoryInfo.threshold, sMemoryInfo.totalMem, outPtr);
}
+
+ private static native void nativeGetMemoryInfoCallback(
+ long availMem, boolean lowMemory,
+ long threshold, long totalMem, long outPtr);
}

Powered by Google App Engine
This is Rietveld 408576698