Skip to content

Commit

Permalink
[Android] Add a low-end device mode override flag
Browse files Browse the repository at this point in the history
The current low-end device optimizations are restricted to devices that meet
certain memory and OS version criteria.  Add a flag that overrides this
detection, simplifying testing and allowing power users to take advantage
of the optimizations.

BUG=320747

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237584 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jdduke@chromium.org committed Nov 27, 2013
1 parent 48b902d commit 705872b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
6 changes: 6 additions & 0 deletions base/android/java/src/org/chromium/base/BaseSwitches.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public abstract class BaseSwitches {
// Block onCreate() of Chrome until a Java debugger is attached.
public static final String WAIT_FOR_JAVA_DEBUGGER = "wait-for-java-debugger";

// Overrides low-end device detection, disabling low-end device optimizations.
public static final String DISABLE_LOW_END_DEVICE_MODE = "disable-low-end-device-mode";

// Overrides low-end device detection, enabling low-end device optimizations.
public static final String ENABLE_LOW_END_DEVICE_MODE = "enable-low-end-device-mode";

// Prevent instantiation.
private BaseSwitches() {}
};
28 changes: 22 additions & 6 deletions base/android/java/src/org/chromium/base/SysUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import android.os.Build;
import android.util.Log;

import org.chromium.base.BaseSwitches;
import org.chromium.base.CommandLine;

/**
* Exposes system related information about the current device.
*/
Expand Down Expand Up @@ -98,15 +101,28 @@ public static int amountOfPhysicalMemoryKB() {
*/
@CalledByNative
public static boolean isLowEndDevice() {
if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) {
return false;
}
if (sLowEndDevice == null) {
int ramSizeKB = amountOfPhysicalMemoryKB();
sLowEndDevice = (ramSizeKB > 0 &&
ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB);
sLowEndDevice = detectLowEndDevice();
}

return sLowEndDevice.booleanValue();
}

private static boolean detectLowEndDevice() {
if (CommandLine.isInitialized()) {
if (CommandLine.getInstance().hasSwitch(BaseSwitches.ENABLE_LOW_END_DEVICE_MODE)) {
return true;
}
if (CommandLine.getInstance().hasSwitch(BaseSwitches.DISABLE_LOW_END_DEVICE_MODE)) {
return false;
}
}

if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) {
return false;
}

int ramSizeKB = amountOfPhysicalMemoryKB();
return (ramSizeKB > 0 && ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB);
}
}
8 changes: 8 additions & 0 deletions base/base_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ const char kEnableCrashReporterForTesting[] =
"enable-crash-reporter-for-testing";
#endif

#if defined(OS_ANDROID)
// Overrides low-end device detection, disabling low-end device optimizations.
const char kDisableLowEndDeviceMode[] = "disable-low-end-device-mode";

// Overrides low-end device detection, enabling low-end device optimizations.
const char kEnableLowEndDeviceMode[] = "enable-low-end-device-mode";
#endif

} // namespace switches
5 changes: 5 additions & 0 deletions base/base_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ extern const char kTraceToConsole[];
extern const char kEnableCrashReporterForTesting[];
#endif

#if defined(OS_ANDROID)
extern const char kDisableLowEndDeviceMode[];
extern const char kEnableLowEndDeviceMode[];
#endif

} // namespace switches

#endif // BASE_BASE_SWITCHES_H_
6 changes: 6 additions & 0 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -6673,6 +6673,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_DISABLE_CLICK_DELAY_DESCRIPTION" desc="Description of the flag to disable the click delay.">
Always send click events immediate upon a tap, even when it's part of a double-tap gesture. This speeds up navigation and other tap actions by 300ms on most pages, but means links and buttons must be avoided when double tapping to zoom.
</message>
<message name="IDS_FLAGS_LOW_END_DEVICE_MODE_DESCRIPTION" desc="Description of the flag to tweak low end device optimizations.">
Overrides low end device optimizations.
</message>
<message name="IDS_FLAGS_LOW_END_DEVICE_MODE_NAME" desc="Name of the flag to tweak low end device optimizations.">
Low end device mode.
</message>
</if>
<message name="IDS_FLAGS_ENABLE_TRANSLATE_NEW_UX_NAME" desc="Name of the flag to enable the new Translate UX.">
Enable the new Translate UX.
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,14 @@ const Experiment kExperiments[] = {
// Java-only switch: CommandLine.DISABLE_CLICK_DELAY
SINGLE_VALUE_TYPE("disable-click-delay")
},
{
"low-end-device-mode",
IDS_FLAGS_LOW_END_DEVICE_MODE_NAME,
IDS_FLAGS_LOW_END_DEVICE_MODE_DESCRIPTION,
kOsAndroid,
ENABLE_DISABLE_VALUE_TYPE(switches::kEnableLowEndDeviceMode,
switches::kDisableLowEndDeviceMode)
},
#endif
#if defined(OS_CHROMEOS)
{
Expand Down
2 changes: 2 additions & 0 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
#endif
#if defined(OS_ANDROID)
switches::kDisableGestureRequirementForMediaPlayback,
switches::kDisableLowEndDeviceMode,
switches::kDisableWebRTC,
switches::kEnableLowEndDeviceMode,
switches::kEnableSpeechRecognition,
switches::kHideScrollbars,
switches::kMediaDrmEnableNonCompositing,
Expand Down

0 comments on commit 705872b

Please sign in to comment.