| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.base; | 5 package org.chromium.base; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.ComponentCallbacks2; | 8 import android.content.ComponentCallbacks2; |
| 9 import android.content.Context; |
| 9 import android.content.res.Configuration; | 10 import android.content.res.Configuration; |
| 10 | 11 |
| 11 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
| 12 import org.chromium.base.annotations.MainDex; | 13 import org.chromium.base.annotations.MainDex; |
| 13 | 14 |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * This is an internal implementation of the C++ counterpart. | 17 * This is an internal implementation of the C++ counterpart. |
| 17 * It registers a ComponentCallbacks2 with the system, and dispatches into | 18 * It registers a ComponentCallbacks2 with the system, and dispatches into |
| 18 * native for levels that are considered actionable. | 19 * native for levels that are considered actionable. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 39 "org.chromium.base.ACTION_TRIM_MEMORY_RUNNING_CRITICAL"; | 40 "org.chromium.base.ACTION_TRIM_MEMORY_RUNNING_CRITICAL"; |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Sending an intent with this action to Chrome will cause it to issue a cal
l to onTrimMemory | 43 * Sending an intent with this action to Chrome will cause it to issue a cal
l to onTrimMemory |
| 43 * with notification level TRIM_MEMORY_MODERATE thus simulating a low memory
situation | 44 * with notification level TRIM_MEMORY_MODERATE thus simulating a low memory
situation |
| 44 */ | 45 */ |
| 45 private static final String ACTION_TRIM_MEMORY_MODERATE = | 46 private static final String ACTION_TRIM_MEMORY_MODERATE = |
| 46 "org.chromium.base.ACTION_TRIM_MEMORY_MODERATE"; | 47 "org.chromium.base.ACTION_TRIM_MEMORY_MODERATE"; |
| 47 | 48 |
| 48 @CalledByNative | 49 @CalledByNative |
| 49 private static void registerSystemCallback() { | 50 private static void registerSystemCallback(Context context) { |
| 50 ContextUtils.getApplicationContext().registerComponentCallbacks( | 51 context.registerComponentCallbacks( |
| 51 new ComponentCallbacks2() { | 52 new ComponentCallbacks2() { |
| 52 @Override | 53 @Override |
| 53 public void onTrimMemory(int level) { | 54 public void onTrimMemory(int level) { |
| 54 maybeNotifyMemoryPresure(level); | 55 maybeNotifyMemoryPresure(level); |
| 55 } | 56 } |
| 56 | 57 |
| 57 @Override | 58 @Override |
| 58 public void onLowMemory() { | 59 public void onLowMemory() { |
| 59 nativeOnMemoryPressure(MemoryPressureLevel.CRITICAL); | 60 nativeOnMemoryPressure(MemoryPressureLevel.CRITICAL); |
| 60 } | 61 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 private static void simulateTrimMemoryPressureSignal(Activity activity, int
level) { | 109 private static void simulateTrimMemoryPressureSignal(Activity activity, int
level) { |
| 109 // The Application and the Activity each have a list of callbacks they n
otify when this | 110 // The Application and the Activity each have a list of callbacks they n
otify when this |
| 110 // method is called. Notifying these will simulate the event at the App
/Activity level | 111 // method is called. Notifying these will simulate the event at the App
/Activity level |
| 111 // as well as trigger the listener bound from native in this process. | 112 // as well as trigger the listener bound from native in this process. |
| 112 activity.getApplication().onTrimMemory(level); | 113 activity.getApplication().onTrimMemory(level); |
| 113 activity.onTrimMemory(level); | 114 activity.onTrimMemory(level); |
| 114 } | 115 } |
| 115 | 116 |
| 116 private static native void nativeOnMemoryPressure(int memoryPressureType); | 117 private static native void nativeOnMemoryPressure(int memoryPressureType); |
| 117 } | 118 } |
| OLD | NEW |