Commit 0dfe9ba2 authored by feng's avatar feng Committed by Commit bot

[Android] Initialize CommandLine before any usage in Render.

On low-end devices, if Chrome was upgraded from a previous version,
Chrome decides to use normal mode to keep user experience consistent.
This is done by force '--low-end-device-mode=0' on both browser and render
processes.

However, when crazy linker is used, Linker.isUsed() triggers
SysUtils.detectLowEndDevice() call which checks CommandLine first.
Existing code invokes Linker.isUsed() before initilizing CommandLine,
which causes the render process ignores '--low-end-device-mode=0'.

This results the browser in normal mode, but render is in low-end device mode.

BUG=424228

Review URL: https://codereview.chromium.org/665273003

Cr-Commit-Position: refs/heads/master@{#301581}
parent 08114182
...@@ -103,13 +103,12 @@ public class SysUtils { ...@@ -103,13 +103,12 @@ public class SysUtils {
} }
private static boolean detectLowEndDevice() { private static boolean detectLowEndDevice() {
if (CommandLine.isInitialized()) { assert CommandLine.isInitialized();
if (CommandLine.getInstance().hasSwitch(BaseSwitches.LOW_END_DEVICE_MODE)) { if (CommandLine.getInstance().hasSwitch(BaseSwitches.LOW_END_DEVICE_MODE)) {
int mode = Integer.parseInt(CommandLine.getInstance().getSwitchValue( int mode = Integer.parseInt(CommandLine.getInstance().getSwitchValue(
BaseSwitches.LOW_END_DEVICE_MODE)); BaseSwitches.LOW_END_DEVICE_MODE));
if (mode == 1) return true; if (mode == 1) return true;
if (mode == 0) return false; if (mode == 0) return false;
}
} }
if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) { if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) {
......
...@@ -130,6 +130,14 @@ public class ChildProcessService extends Service { ...@@ -130,6 +130,14 @@ public class ChildProcessService extends Service {
@Override @Override
public void run() { public void run() {
try { try {
// CommandLine must be initialized before others, e.g., Linker.isUsed()
// may check the command line options.
synchronized (mMainThread) {
while (mCommandLineParams == null) {
mMainThread.wait();
}
}
CommandLine.init(mCommandLineParams);
boolean useLinker = Linker.isUsed(); boolean useLinker = Linker.isUsed();
boolean requestedSharedRelro = false; boolean requestedSharedRelro = false;
if (useLinker) { if (useLinker) {
...@@ -138,23 +146,16 @@ public class ChildProcessService extends Service { ...@@ -138,23 +146,16 @@ public class ChildProcessService extends Service {
mMainThread.wait(); mMainThread.wait();
} }
} }
if (mLinkerParams != null) { assert mLinkerParams != null;
if (mLinkerParams.mWaitForSharedRelro) { if (mLinkerParams.mWaitForSharedRelro) {
requestedSharedRelro = true; requestedSharedRelro = true;
Linker.initServiceProcess(mLinkerParams.mBaseLoadAddress); Linker.initServiceProcess(mLinkerParams.mBaseLoadAddress);
} else { } else {
Linker.disableSharedRelros(); Linker.disableSharedRelros();
}
Linker.setTestRunnerClassName(mLinkerParams.mTestRunnerClassName);
} }
Linker.setTestRunnerClassName(mLinkerParams.mTestRunnerClassName);
} }
boolean isLoaded = false; boolean isLoaded = false;
synchronized (mMainThread) {
while (mCommandLineParams == null) {
mMainThread.wait();
}
}
CommandLine.init(mCommandLineParams);
if (CommandLine.getInstance().hasSwitch( if (CommandLine.getInstance().hasSwitch(
BaseSwitches.RENDERER_WAIT_FOR_JAVA_DEBUGGER)) { BaseSwitches.RENDERER_WAIT_FOR_JAVA_DEBUGGER)) {
android.os.Debug.waitForDebugger(); android.os.Debug.waitForDebugger();
...@@ -254,9 +255,9 @@ public class ChildProcessService extends Service { ...@@ -254,9 +255,9 @@ public class ChildProcessService extends Service {
synchronized (mMainThread) { synchronized (mMainThread) {
mCommandLineParams = intent.getStringArrayExtra( mCommandLineParams = intent.getStringArrayExtra(
ChildProcessConnection.EXTRA_COMMAND_LINE); ChildProcessConnection.EXTRA_COMMAND_LINE);
mLinkerParams = null; // mLinkerParams is never used if Linker.isUsed() returns false.
if (Linker.isUsed()) // See onCreate().
mLinkerParams = new ChromiumLinkerParams(intent); mLinkerParams = new ChromiumLinkerParams(intent);
mIsBound = true; mIsBound = true;
mMainThread.notifyAll(); mMainThread.notifyAll();
} }
......
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