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); |
+} |