Skip to content

Commit

Permalink
Expose a low-end device mode override flags for non-android OSs as well
Browse files Browse the repository at this point in the history
BUG=324824

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280024 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
c.shu@samsung.com committed Jun 26, 2014
1 parent 8851dbe commit 35b4f0c
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 108 deletions.
9 changes: 4 additions & 5 deletions base/android/java/src/org/chromium/base/BaseSwitches.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ 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";
// Force low-end device when set to 1;
// Force non-low-end device when set to 0;
// Auto-detect low-end device when set to other values or empty;
public static final String LOW_END_DEVICE_MODE = "low-end-device-mode";

// Adds additional thread idle time information into the trace event output.
public static final String ENABLE_IDLE_TRACING = "enable-idle-tracing";
Expand Down
18 changes: 8 additions & 10 deletions base/android/java/src/org/chromium/base/SysUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ private SysUtils() { }

/**
* Return the amount of physical memory on this device in kilobytes.
* Note: the only reason this is public is for testability reason.
* @return Amount of physical memory in kilobytes, or 0 if there was
* an error trying to access the information.
*
* Note that this is CalledByNative for testing purpose only.
*/
@CalledByNative
public static int amountOfPhysicalMemoryKB() {
private static int amountOfPhysicalMemoryKB() {
// Extract total memory RAM size by parsing /proc/meminfo, note that
// this is exactly what the implementation of sysconf(_SC_PHYS_PAGES)
// does. However, it can't be called because this method must be
Expand Down Expand Up @@ -108,11 +104,13 @@ public static boolean isLowEndDevice() {

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 (CommandLine.getInstance().hasSwitch(BaseSwitches.LOW_END_DEVICE_MODE)) {
int mode = Integer.parseInt(CommandLine.getInstance().getSwitchValue(
BaseSwitches.LOW_END_DEVICE_MODE));
if (mode == 1)
return true;
if (mode == 0)
return false;
}
}

Expand Down
20 changes: 2 additions & 18 deletions base/android/sys_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ bool SysUtils::IsLowEndDeviceFromJni() {
return Java_SysUtils_isLowEndDevice(env);
}

bool SysUtils::IsLowEndDevice() {
static bool is_low_end = IsLowEndDeviceFromJni();
return is_low_end;
}

size_t SysUtils::AmountOfPhysicalMemoryKBFromJni() {
JNIEnv* env = AttachCurrentThread();
return static_cast<size_t>(Java_SysUtils_amountOfPhysicalMemoryKB(env));
}

size_t SysUtils::AmountOfPhysicalMemoryKB() {
static size_t amount_of_ram = AmountOfPhysicalMemoryKBFromJni();
return amount_of_ram;
}

SysUtils::SysUtils() { }

} // namespace android
} // namespace base

} // namespace base
9 changes: 0 additions & 9 deletions base/android/sys_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ class BASE_EXPORT SysUtils {
static bool Register(JNIEnv* env);

// Returns true iff this is a low-end device.
static bool IsLowEndDevice();

// Return the device's RAM size in kilo-bytes.
static size_t AmountOfPhysicalMemoryKB();

private:
SysUtils();

static bool IsLowEndDeviceFromJni();
static size_t AmountOfPhysicalMemoryKBFromJni();
};

} // namespace android
Expand Down
7 changes: 3 additions & 4 deletions base/android/sys_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/android/sys_utils.h"

#include <unistd.h>

#include "base/sys_info.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace android {

TEST(SysUtils, AmountOfPhysicalMemory) {
// Check that the RAM size reported by sysconf() matches the one
// computed by base::android::SysUtils::AmountOfPhysicalMemory().
// computed by base::SysInfo::AmountOfPhysicalMemory().
size_t sys_ram_size =
static_cast<size_t>(sysconf(_SC_PHYS_PAGES) * PAGE_SIZE);
EXPECT_EQ(sys_ram_size, SysUtils::AmountOfPhysicalMemoryKB() * 1024UL);
EXPECT_EQ(sys_ram_size, SysInfo::AmountOfPhysicalMemory());
}

} // namespace android
Expand Down
13 changes: 5 additions & 8 deletions base/base_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const char kEnableCrashReporter[] = "enable-crash-reporter";
// Generates full memory crash dump.
const char kFullMemoryCrashReport[] = "full-memory-crash-report";

// Force low-end device when set to 1;
// Auto-detect low-end device when set to 2;
// Force non-low-end device when set to other values or empty;
const char kLowEndDeviceMode[] = "low-end-device-mode";

// Suppresses all error dialogs when present.
const char kNoErrorDialogs[] = "noerrdialogs";

Expand Down Expand Up @@ -60,12 +65,4 @@ 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
6 changes: 1 addition & 5 deletions base/base_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace switches {
extern const char kDisableBreakpad[];
extern const char kEnableCrashReporter[];
extern const char kFullMemoryCrashReport[];
extern const char kLowEndDeviceMode[];
extern const char kNoErrorDialogs[];
extern const char kProfilerTiming[];
extern const char kProfilerTimingDisabledValue[];
Expand All @@ -27,11 +28,6 @@ extern const char kWaitForDebugger[];
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_
4 changes: 2 additions & 2 deletions base/memory/discardable_memory_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "base/memory/discardable_memory.h"

#include "base/android/sys_utils.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
Expand All @@ -13,6 +12,7 @@
#include "base/memory/discardable_memory_ashmem_allocator.h"
#include "base/memory/discardable_memory_emulated.h"
#include "base/memory/discardable_memory_malloc.h"
#include "base/sys_info.h"

namespace base {
namespace {
Expand All @@ -26,7 +26,7 @@ const size_t kAshmemMemoryLimit = 512 * 1024 * 1024;
size_t GetOptimalAshmemRegionSizeForAllocator() {
// Note that this may do some I/O (without hitting the disk though) so it
// should not be called on the critical path.
return base::android::SysUtils::AmountOfPhysicalMemoryKB() * 1024 / 8;
return base::SysInfo::AmountOfPhysicalMemory() / 8;
}

// Holds the shared state used for allocations.
Expand Down
36 changes: 36 additions & 0 deletions base/sys_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,46 @@

#include "base/sys_info.h"

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/strings/string_number_conversions.h"
#include "base/sys_info_internal.h"
#include "base/time/time.h"

namespace base {

#if !defined(OS_ANDROID)

static const int kLowMemoryDeviceThresholdMB = 512;

bool DetectLowEndDevice() {
CommandLine* command_line = CommandLine::ForCurrentProcess();
int int_value = 0;
if (command_line->HasSwitch(switches::kLowEndDeviceMode)) {
std::string string_value =
command_line->GetSwitchValueASCII(switches::kLowEndDeviceMode);
StringToInt(string_value, &int_value);
}
if (int_value == 1)
return true;
if (int_value != 2)
return false;

int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB();
return (ram_size_mb > 0 && ram_size_mb < kLowMemoryDeviceThresholdMB);
}

static LazyInstance<
internal::LazySysInfoValue<bool, DetectLowEndDevice> >::Leaky
g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER;

// static
bool SysInfo::IsLowEndDevice() {
return g_lazy_low_end_device.Get().value();
}
#endif

// static
int64 SysInfo::Uptime() {
// This code relies on an implementation detail of TimeTicks::Now() - that
Expand Down
5 changes: 5 additions & 0 deletions base/sys_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class BASE_EXPORT SysInfo {
static int DalvikHeapSizeMB();
static int DalvikHeapGrowthLimitMB();
#endif // defined(OS_ANDROID)

// Returns true if this is a low-end device.
// Low-end device refers to devices having less than 512M memory in the
// current implementation.
static bool IsLowEndDevice();
};

} // namespace base
Expand Down
12 changes: 12 additions & 0 deletions base/sys_info_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#include <sys/system_properties.h>

#include "base/android/sys_utils.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info_internal.h"

namespace {

Expand Down Expand Up @@ -162,5 +165,14 @@ int SysInfo::DalvikHeapGrowthLimitMB() {
return heap_growth_limit;
}

static base::LazyInstance<
base::internal::LazySysInfoValue<bool,
android::SysUtils::IsLowEndDeviceFromJni> >::Leaky
g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER;

bool SysInfo::IsLowEndDevice() {
return g_lazy_low_end_device.Get().value();
}


} // namespace base
4 changes: 2 additions & 2 deletions chrome/browser/android/chrome_startup_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/android/sys_utils.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/sys_info.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "content/public/common/content_switches.h"
Expand Down Expand Up @@ -44,7 +44,7 @@ void SetChromeSpecificCommandLineFlags() {
switches::kPrerenderFromOmniboxSwitchValueEnabled);

// Disable syncing favicons on low end devices.
if (base::android::SysUtils::IsLowEndDevice())
if (base::SysInfo::IsLowEndDevice())
SetCommandLineSwitchASCII(switches::kDisableSyncTypes, "Favicon Images");

// Enable DOM Distiller on local builds, canary and dev-channel.
Expand Down
9 changes: 2 additions & 7 deletions chrome/browser/prerender/prerender_manager_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

#include "chrome/browser/prerender/prerender_manager_factory.h"

#if defined(OS_ANDROID)
#include "base/android/sys_utils.h"
#endif

#include "base/debug/trace_event.h"
#include "base/sys_info.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/predictors/predictor_database_factory.h"
Expand Down Expand Up @@ -65,10 +62,8 @@ KeyedService* PrerenderManagerFactory::BuildServiceInstanceFor(
content::BrowserContext* browser_context) const {
Profile* profile = Profile::FromBrowserContext(browser_context);
CHECK(g_browser_process->prerender_tracker());
#if defined(OS_ANDROID)
if (base::android::SysUtils::IsLowEndDevice())
if (base::SysInfo::IsLowEndDevice())
return NULL;
#endif

PrerenderManager* prerender_manager = new PrerenderManager(
profile, g_browser_process->prerender_tracker());
Expand Down
10 changes: 2 additions & 8 deletions chrome/browser/renderer_host/web_cache_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"

#if defined(OS_ANDROID)
#include "base/android/sys_utils.h"
#endif

using base::Time;
using base::TimeDelta;
using blink::WebCache;
Expand Down Expand Up @@ -326,12 +322,10 @@ void WebCacheManager::EnactStrategy(const AllocationStrategy& strategy) {

// We allow the dead objects to consume up to half of the cache capacity.
size_t max_dead_capacity = capacity / 2;
#if defined(OS_ANDROID)
if (base::android::SysUtils::IsLowEndDevice())
if (base::SysInfo::IsLowEndDevice()) {
max_dead_capacity = std::min(static_cast<size_t>(512 * 1024),
max_dead_capacity);
#endif

}
host->Send(new ChromeViewMsg_SetCacheCapacities(min_dead_capacity,
max_dead_capacity,
capacity));
Expand Down
1 change: 1 addition & 0 deletions content/browser/gpu/gpu_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) {
switches::kGpuSandboxStartAfterInitialization,
switches::kIgnoreResolutionLimitsForAcceleratedVideoDecode,
switches::kLoggingLevel,
switches::kLowEndDeviceMode,
switches::kNoSandbox,
switches::kTestGLLib,
switches::kTraceStartup,
Expand Down
3 changes: 1 addition & 2 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1238,11 +1238,10 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
switches::kDisableWebRtcHWEncoding,
switches::kEnableWebRtcHWVp8Encoding,
#endif
switches::kLowEndDeviceMode,
#if defined(OS_ANDROID)
switches::kDisableGestureRequirementForMediaPlayback,
switches::kDisableLowEndDeviceMode,
switches::kDisableWebRTC,
switches::kEnableLowEndDeviceMode,
switches::kEnableSpeechRecognition,
switches::kMediaDrmEnableNonCompositing,
switches::kNetworkCountryIso,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <android/bitmap.h>

#include "base/android/sys_utils.h"
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
Expand All @@ -15,6 +14,7 @@
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
#include "base/threading/worker_pool.h"
#include "cc/base/latency_info_swap_promise.h"
#include "cc/layers/delegated_frame_provider.h"
Expand Down Expand Up @@ -1436,7 +1436,7 @@ SkBitmap::Config RenderWidgetHostViewAndroid::PreferredReadbackFormat() {
// Define the criteria here. If say the 16 texture readback is
// supported we should go with that (this degrades quality)
// or stick back to the default format.
if (base::android::SysUtils::IsLowEndDevice()) {
if (base::SysInfo::IsLowEndDevice()) {
if (IsReadbackConfigSupported(SkBitmap::kRGB_565_Config))
return SkBitmap::kRGB_565_Config;
}
Expand Down
Loading

0 comments on commit 35b4f0c

Please sign in to comment.