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

Unified Diff: components/memory_coordinator/android/java/src/org/chromium/components/memory_coordinator/MemoryStateListener.java

Issue 2259743002: Add MemoryStateListenerAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: native 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: components/memory_coordinator/android/java/src/org/chromium/components/memory_coordinator/MemoryStateListener.java
diff --git a/components/memory_coordinator/android/java/src/org/chromium/components/memory_coordinator/MemoryStateListener.java b/components/memory_coordinator/android/java/src/org/chromium/components/memory_coordinator/MemoryStateListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..47516b0caa93e5da1395be419adf6a91c8d4d7a3
--- /dev/null
+++ b/components/memory_coordinator/android/java/src/org/chromium/components/memory_coordinator/MemoryStateListener.java
@@ -0,0 +1,56 @@
+// 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.components.memory_coordinator;
+
+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;
+import org.chromium.base.annotations.MainDex;
+
+/**
+ * This class registers a ComponentCallbacks2 which delegates actual memory
+ * management to internal memory coordinator implementation.
+ */
+@JNINamespace("memory_coordinator")
+@MainDex
+public class MemoryStateListener {
+ private static ComponentCallbacks2 sCallbacks = null;
+
+ @CalledByNative
+ private static void registerCallback(Context context) {
+ sCallbacks = new ComponentCallbacks2() {
+ @Override
+ public void onTrimMemory(int level) {
+ // Though the API document says that we shouldn't compare
+ // to exact values we filter UI_HIDDEN because it's not
+ // exactly a memory pressure signal.
+ if (level != ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
+ nativeOnTrimMemory(level);
+ }
+ }
+
+ @Override
+ public void onLowMemory() {
+ // Don't support old onLowMemory() API.
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration config) {
+ }
+ };
+ context.registerComponentCallbacks(sCallbacks);
+ }
+
+ @CalledByNative
+ private static void unregisterCallback(Context context) {
+ context.unregisterComponentCallbacks(sCallbacks);
+ sCallbacks = null;
+ }
+
+ private static native void nativeOnTrimMemory(int level);
+}

Powered by Google App Engine
This is Rietveld 408576698