jeremy@chromium.org | de658ed | 2012-10-29 10:04:09 +0900 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "base/sys_info.h" |
| 6 | |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 7 | #include "base/base_switches.h" |
| 8 | #include "base/command_line.h" |
| 9 | #include "base/lazy_instance.h" |
cnwan | 8ea79f2 | 2015-05-06 15:11:45 +0900 | [diff] [blame] | 10 | #include "base/metrics/field_trial.h" |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 11 | #include "base/strings/string_number_conversions.h" |
cnwan | 8ea79f2 | 2015-05-06 15:11:45 +0900 | [diff] [blame] | 12 | #include "base/strings/string_util.h" |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 13 | #include "base/sys_info_internal.h" |
avi@chromium.org | b45ec93 | 2013-06-29 00:14:18 +0900 | [diff] [blame] | 14 | #include "base/time/time.h" |
avi | a6a6a68 | 2015-12-27 07:15:14 +0900 | [diff] [blame] | 15 | #include "build/build_config.h" |
jeremy@chromium.org | de658ed | 2012-10-29 10:04:09 +0900 | [diff] [blame] | 16 | |
| 17 | namespace base { |
| 18 | |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 19 | #if !defined(OS_ANDROID) |
| 20 | |
| 21 | static const int kLowMemoryDeviceThresholdMB = 512; |
| 22 | |
| 23 | bool DetectLowEndDevice() { |
| 24 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
ssid | 108428f | 2014-12-17 01:04:02 +0900 | [diff] [blame] | 25 | if (command_line->HasSwitch(switches::kEnableLowEndDeviceMode)) |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 26 | return true; |
ssid | 108428f | 2014-12-17 01:04:02 +0900 | [diff] [blame] | 27 | if (command_line->HasSwitch(switches::kDisableLowEndDeviceMode)) |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 28 | return false; |
| 29 | |
| 30 | int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB(); |
mariakhomenko | afb287c | 2016-04-29 04:25:33 +0900 | [diff] [blame] | 31 | return (ram_size_mb > 0 && ram_size_mb <= kLowMemoryDeviceThresholdMB); |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static LazyInstance< |
| 35 | internal::LazySysInfoValue<bool, DetectLowEndDevice> >::Leaky |
| 36 | g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER; |
| 37 | |
| 38 | // static |
| 39 | bool SysInfo::IsLowEndDevice() { |
cnwan | 8ea79f2 | 2015-05-06 15:11:45 +0900 | [diff] [blame] | 40 | const std::string group_name = |
| 41 | base::FieldTrialList::FindFullName("MemoryReduction"); |
| 42 | |
| 43 | // Low End Device Mode will be enabled if this client is assigned to |
| 44 | // one of those EnabledXXX groups. |
brettw | e1daa97 | 2015-06-16 14:52:47 +0900 | [diff] [blame] | 45 | if (StartsWith(group_name, "Enabled", CompareCase::SENSITIVE)) |
cnwan | 8ea79f2 | 2015-05-06 15:11:45 +0900 | [diff] [blame] | 46 | return true; |
| 47 | |
c.shu@samsung.com | da21aff | 2014-06-27 01:55:27 +0900 | [diff] [blame] | 48 | return g_lazy_low_end_device.Get().value(); |
| 49 | } |
| 50 | #endif |
| 51 | |
tdresser | f393369 | 2015-07-17 00:41:04 +0900 | [diff] [blame] | 52 | #if (!defined(OS_MACOSX) || defined(OS_IOS)) && !defined(OS_ANDROID) |
jeremy | b43af09 | 2014-11-07 03:47:10 +0900 | [diff] [blame] | 53 | std::string SysInfo::HardwareModelName() { |
| 54 | return std::string(); |
| 55 | } |
| 56 | #endif |
| 57 | |
jeremy@chromium.org | de658ed | 2012-10-29 10:04:09 +0900 | [diff] [blame] | 58 | // static |
sque | babf673 | 2015-11-05 09:01:03 +0900 | [diff] [blame] | 59 | base::TimeDelta SysInfo::Uptime() { |
jeremy@chromium.org | de658ed | 2012-10-29 10:04:09 +0900 | [diff] [blame] | 60 | // This code relies on an implementation detail of TimeTicks::Now() - that |
| 61 | // its return value happens to coincide with the system uptime value in |
| 62 | // microseconds, on Win/Mac/iOS/Linux/ChromeOS and Android. |
avi | 95a2f37 | 2015-12-09 09:44:49 +0900 | [diff] [blame] | 63 | int64_t uptime_in_microseconds = TimeTicks::Now().ToInternalValue(); |
sque | babf673 | 2015-11-05 09:01:03 +0900 | [diff] [blame] | 64 | return base::TimeDelta::FromMicroseconds(uptime_in_microseconds); |
jeremy@chromium.org | de658ed | 2012-10-29 10:04:09 +0900 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | } // namespace base |