blob: 5aac9b71cd49e80c45fd11ca4337eb805acb3faf [file] [log] [blame]
jeremy@chromium.orgde658ed2012-10-29 10:04:09 +09001// 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.comda21aff2014-06-27 01:55:27 +09007#include "base/base_switches.h"
8#include "base/command_line.h"
9#include "base/lazy_instance.h"
cnwan8ea79f22015-05-06 15:11:45 +090010#include "base/metrics/field_trial.h"
c.shu@samsung.comda21aff2014-06-27 01:55:27 +090011#include "base/strings/string_number_conversions.h"
cnwan8ea79f22015-05-06 15:11:45 +090012#include "base/strings/string_util.h"
c.shu@samsung.comda21aff2014-06-27 01:55:27 +090013#include "base/sys_info_internal.h"
avi@chromium.orgb45ec932013-06-29 00:14:18 +090014#include "base/time/time.h"
avia6a6a682015-12-27 07:15:14 +090015#include "build/build_config.h"
jeremy@chromium.orgde658ed2012-10-29 10:04:09 +090016
17namespace base {
18
c.shu@samsung.comda21aff2014-06-27 01:55:27 +090019#if !defined(OS_ANDROID)
20
21static const int kLowMemoryDeviceThresholdMB = 512;
22
23bool DetectLowEndDevice() {
24 CommandLine* command_line = CommandLine::ForCurrentProcess();
ssid108428f2014-12-17 01:04:02 +090025 if (command_line->HasSwitch(switches::kEnableLowEndDeviceMode))
c.shu@samsung.comda21aff2014-06-27 01:55:27 +090026 return true;
ssid108428f2014-12-17 01:04:02 +090027 if (command_line->HasSwitch(switches::kDisableLowEndDeviceMode))
c.shu@samsung.comda21aff2014-06-27 01:55:27 +090028 return false;
29
30 int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB();
mariakhomenkoafb287c2016-04-29 04:25:33 +090031 return (ram_size_mb > 0 && ram_size_mb <= kLowMemoryDeviceThresholdMB);
c.shu@samsung.comda21aff2014-06-27 01:55:27 +090032}
33
34static LazyInstance<
35 internal::LazySysInfoValue<bool, DetectLowEndDevice> >::Leaky
36 g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER;
37
38// static
39bool SysInfo::IsLowEndDevice() {
cnwan8ea79f22015-05-06 15:11:45 +090040 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.
brettwe1daa972015-06-16 14:52:47 +090045 if (StartsWith(group_name, "Enabled", CompareCase::SENSITIVE))
cnwan8ea79f22015-05-06 15:11:45 +090046 return true;
47
c.shu@samsung.comda21aff2014-06-27 01:55:27 +090048 return g_lazy_low_end_device.Get().value();
49}
50#endif
51
tdresserf3933692015-07-17 00:41:04 +090052#if (!defined(OS_MACOSX) || defined(OS_IOS)) && !defined(OS_ANDROID)
jeremyb43af092014-11-07 03:47:10 +090053std::string SysInfo::HardwareModelName() {
54 return std::string();
55}
56#endif
57
jeremy@chromium.orgde658ed2012-10-29 10:04:09 +090058// static
squebabf6732015-11-05 09:01:03 +090059base::TimeDelta SysInfo::Uptime() {
jeremy@chromium.orgde658ed2012-10-29 10:04:09 +090060 // 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.
avi95a2f372015-12-09 09:44:49 +090063 int64_t uptime_in_microseconds = TimeTicks::Now().ToInternalValue();
squebabf6732015-11-05 09:01:03 +090064 return base::TimeDelta::FromMicroseconds(uptime_in_microseconds);
jeremy@chromium.orgde658ed2012-10-29 10:04:09 +090065}
66
67} // namespace base