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

Unified Diff: base/android/java/src/org/chromium/base/MemoryPressureHandler.java

Issue 15995014: Adds MemoryPressureListener. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Joth's comments Created 7 years, 6 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: base/android/java/src/org/chromium/base/MemoryPressureHandler.java
diff --git a/base/android/java/src/org/chromium/base/MemoryPressureHandler.java b/base/android/java/src/org/chromium/base/MemoryPressureHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..744d1f187229b24166d4900a945cc5d790e77283
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/MemoryPressureHandler.java
@@ -0,0 +1,49 @@
+// Copyright (c) 2013 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.base;
+
+import android.content.ComponentCallbacks2;
+import android.content.Context;
+import android.content.res.Configuration;
+
+import org.chromium.base.MemoryPressureList;
+
+
+/**
+ * This is an internal implementation of the C++ counterpart.
+ * It registers a ComponentCallbacks2 with the system, and dispatches into
+ * native.
+ */
+class MemoryPressureHandler {
+ @CalledByNative
+ private static void registerSystemCallback(Context context) {
+ context.registerComponentCallbacks(
+ new ComponentCallbacks2() {
+ @Override
+ public void onTrimMemory(int level) {
+ nativeOnMemoryPressure(translate(level));
+ }
+
+ @Override
+ public void onLowMemory() {
+ nativeOnMemoryPressure(MemoryPressureList.MEMORY_PRESSURE_CRITICAL);
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration configuration) {
+ }
+ });
+ }
+
+ private static int translate(int level) {
+ if (level == ComponentCallbacks2.TRIM_MEMORY_BACKGROUND ||
+ level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
joth 2013/06/05 19:49:48 oh, hmmm, yeah we may find it very useful to have
bulach 2013/06/06 09:28:30 should this perhaps expose the native call? that i
joth 2013/06/06 22:36:46 Just to avoid having two different ComponentCallba
+ return MemoryPressureList.MEMORY_PRESSURE_MODERATE;
+ }
+ return MemoryPressureList.MEMORY_PRESSURE_CRITICAL;
+ }
+
+ private static native void nativeOnMemoryPressure(int memoryPressureType);
+}

Powered by Google App Engine
This is Rietveld 408576698