1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/sys_info.h"
9 #include "base/base_switches.h"
10 #include "base/command_line.h"
11 #include "base/lazy_instance.h"
12 #include "base/sys_info_internal.h"
13 #include "base/time/time.h"
14 #include "build/build_config.h"
18 static const int kLowMemoryDeviceThresholdMB = 512;
22 int64_t SysInfo::AmountOfPhysicalMemory() {
23 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kEnableLowEndDeviceMode)) {
25 return kLowMemoryDeviceThresholdMB * 1024 * 1024;
28 return AmountOfPhysicalMemoryImpl();
32 int64_t SysInfo::AmountOfAvailablePhysicalMemory() {
33 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
34 switches::kEnableLowEndDeviceMode)) {
35 // Estimate the available memory by subtracting our memory used estimate
36 // from the fake |kLowMemoryDeviceThresholdMB| limit.
38 AmountOfPhysicalMemoryImpl() - AmountOfAvailablePhysicalMemoryImpl();
39 size_t memory_limit = kLowMemoryDeviceThresholdMB * 1024 * 1024;
40 // std::min ensures no underflow, as |memory_used| can be > |memory_limit|.
41 return memory_limit - std::min(memory_used, memory_limit);
44 return AmountOfAvailablePhysicalMemoryImpl();
47 bool SysInfo::IsLowEndDevice() {
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kEnableLowEndDeviceMode)) {
53 return IsLowEndDeviceImpl();
56 #if !defined(OS_ANDROID)
58 bool DetectLowEndDevice() {
59 CommandLine* command_line = CommandLine::ForCurrentProcess();
60 if (command_line->HasSwitch(switches::kEnableLowEndDeviceMode))
62 if (command_line->HasSwitch(switches::kDisableLowEndDeviceMode))
65 int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB();
66 return (ram_size_mb > 0 && ram_size_mb <= kLowMemoryDeviceThresholdMB);
70 internal::LazySysInfoValue<bool, DetectLowEndDevice> >::Leaky
71 g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER;
74 bool SysInfo::IsLowEndDeviceImpl() {
75 return g_lazy_low_end_device.Get().value();
79 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
80 std::string SysInfo::HardwareModelName() {
86 base::TimeDelta SysInfo::Uptime() {
87 // This code relies on an implementation detail of TimeTicks::Now() - that
88 // its return value happens to coincide with the system uptime value in
89 // microseconds, on Win/Mac/iOS/Linux/ChromeOS and Android.
90 int64_t uptime_in_microseconds = TimeTicks::Now().ToInternalValue();
91 return base::TimeDelta::FromMicroseconds(uptime_in_microseconds);