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

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

Issue 2340293003: Add MemoryMonitorAndroid (Closed)
Patch Set: rebase 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
« no previous file with comments | « content/public/android/BUILD.gn ('k') | content/test/BUILD.gn » ('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
new file mode 100644
index 0000000000000000000000000000000000000000..0fa1e03b42803ca14cda4b2365b932d51a39de0c
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/MemoryMonitorAndroid.java
@@ -0,0 +1,42 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.app.ActivityManager;
+import android.content.Context;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+/**
+ * Android implementation of MemoryMonitor.
+ */
+@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 void getMemoryInfo(Context context, long outPtr) {
+ ActivityManager am = (ActivityManager) context.getSystemService(
+ Context.ACTIVITY_SERVICE);
+ 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);
+}
« no previous file with comments | « content/public/android/BUILD.gn ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698