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