Chromium Code Reviews| Index: base/android/java/src/org/chromium/base/MemoryPressure.java |
| diff --git a/base/android/java/src/org/chromium/base/MemoryPressure.java b/base/android/java/src/org/chromium/base/MemoryPressure.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..95c8f37505eab3139eadbea28c09dc38597c95d3 |
| --- /dev/null |
| +++ b/base/android/java/src/org/chromium/base/MemoryPressure.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.MemoryPressureLevelList; |
| + |
| + |
| +/** |
| + * 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(MemoryPressureLevelList.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/06 22:36:46
I dunno. This will map UI_HIDDEN => MODERATE, but
bulach
2013/06/07 11:06:58
agreed. I called out the critical level here (Comp
|
| + return MemoryPressureLevelList.MEMORY_PRESSURE_MODERATE; |
| + } |
| + return MemoryPressureLevelList.MEMORY_PRESSURE_CRITICAL; |
| + } |
| + |
| + private static native void nativeOnMemoryPressure(int memoryPressureType); |
| +} |