Commit 049fabf2 authored by bulach@chromium.org's avatar bulach@chromium.org

Android: adds test intents for memory pressure.

Allows using:
adb shell am start -a org.chromium.content_shell.action.ACTION_LOW_MEMORY \
-n org.chromium.content_shell_apk/.ContentShellActivity

to simulate memory pressure signals.

BUG=

Review URL: https://chromiumcodereview.appspot.com/17108012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207960 0039d316-1c4b-4281-b951-d872f2087c98
parent 407b5a14
......@@ -16,7 +16,7 @@ import org.chromium.base.MemoryPressureLevelList;
* It registers a ComponentCallbacks2 with the system, and dispatches into
* native.
*/
class MemoryPressureListener {
public class MemoryPressureListener {
@CalledByNative
private static void registerSystemCallback(Context context) {
context.registerComponentCallbacks(
......@@ -37,6 +37,13 @@ class MemoryPressureListener {
});
}
/**
* Used by applications to simulate a memory pressure signal.
*/
public static void simulateMemoryPressureSignal(int level) {
nativeOnMemoryPressure(translate(level));
}
private static int translate(int level) {
if (level == ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
return MemoryPressureLevelList.MEMORY_PRESSURE_CRITICAL;
......
......@@ -12,6 +12,7 @@ import android.util.Log;
import android.view.KeyEvent;
import org.chromium.base.ChromiumActivity;
import org.chromium.base.MemoryPressureListener;
import org.chromium.chrome.browser.DevToolsServer;
import org.chromium.content.browser.ActivityContentVideoViewClient;
import org.chromium.content.browser.AndroidBrowserProcess;
......@@ -31,6 +32,19 @@ public class ChromiumTestShellActivity extends ChromiumActivity {
private static final String TAG = ChromiumTestShellActivity.class.getCanonicalName();
private static final String COMMAND_LINE_FILE =
"/data/local/tmp/chromium-testshell-command-line";
/**
* Sending an intent with this action will simulate a memory pressure signal
* at a critical level.
*/
private static final String ACTION_LOW_MEMORY =
"org.chromium.chrome_test_shell.action.ACTION_LOW_MEMORY";
/**
* Sending an intent with this action will simulate a memory pressure signal
* at a moderate level.
*/
private static final String ACTION_TRIM_MEMORY_MODERATE =
"org.chromium.chrome_test_shell.action.ACTION_TRIM_MEMORY_MODERATE";
private WindowAndroid mWindow;
private TabManager mTabManager;
......@@ -94,6 +108,14 @@ public class ChromiumTestShellActivity extends ChromiumActivity {
@Override
protected void onNewIntent(Intent intent) {
if (ACTION_LOW_MEMORY.equals(intent.getAction())) {
MemoryPressureListener.simulateMemoryPressureSignal(TRIM_MEMORY_COMPLETE);
return;
} else if (ACTION_TRIM_MEMORY_MODERATE.equals(intent.getAction())) {
MemoryPressureListener.simulateMemoryPressureSignal(TRIM_MEMORY_MODERATE);
return;
}
String url = getUrlFromIntent(intent);
if (!TextUtils.isEmpty(url)) {
TestShellTab tab = getActiveTab();
......
......@@ -14,6 +14,7 @@ import android.util.Log;
import android.view.KeyEvent;
import org.chromium.base.ChromiumActivity;
import org.chromium.base.MemoryPressureListener;
import org.chromium.content.app.LibraryLoader;
import org.chromium.content.browser.ActivityContentVideoViewClient;
import org.chromium.content.browser.AndroidBrowserProcess;
......@@ -44,6 +45,21 @@ public class ContentShellActivity extends ChromiumActivity {
"org.chromium.content_shell.action.PROFILE_STOP";
public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs";
/**
* Sending an intent with this action will simulate a memory pressure signal
* at a critical level.
*/
private static final String ACTION_LOW_MEMORY =
"org.chromium.content_shell.action.ACTION_LOW_MEMORY";
/**
* Sending an intent with this action will simulate a memory pressure signal
* at a moderate level.
*/
private static final String ACTION_TRIM_MEMORY_MODERATE =
"org.chromium.content_shell.action.ACTION_TRIM_MEMORY_MODERATE";
private ShellManager mShellManager;
private WindowAndroid mWindowAndroid;
private BroadcastReceiver mReceiver;
......@@ -134,6 +150,14 @@ public class ContentShellActivity extends ChromiumActivity {
Log.i(TAG, "Ignoring command line params: can only be set when creating the activity.");
}
if (ACTION_LOW_MEMORY.equals(intent.getAction())) {
MemoryPressureListener.simulateMemoryPressureSignal(TRIM_MEMORY_COMPLETE);
return;
} else if (ACTION_TRIM_MEMORY_MODERATE.equals(intent.getAction())) {
MemoryPressureListener.simulateMemoryPressureSignal(TRIM_MEMORY_MODERATE);
return;
}
String url = getUrlFromIntent(intent);
if (!TextUtils.isEmpty(url)) {
Shell activeView = getActiveShell();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment