blob: 5aac9b71cd49e80c45fd11ca4337eb805acb3faf [file] [log] [blame]
[email protected]0f24e53e2012-10-29 01:04:091// 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
[email protected]35b4f0c2014-06-26 16:55:277#include "base/base_switches.h"
8#include "base/command_line.h"
9#include "base/lazy_instance.h"
cnwand4270e82015-05-06 06:11:4510#include "base/metrics/field_trial.h"
[email protected]35b4f0c2014-06-26 16:55:2711#include "base/strings/string_number_conversions.h"
cnwand4270e82015-05-06 06:11:4512#include "base/strings/string_util.h"
[email protected]35b4f0c2014-06-26 16:55:2713#include "base/sys_info_internal.h"
[email protected]8f9a3a52013-06-28 15:14:1814#include "base/time/time.h"
avi9b6f42932015-12-26 22:15:1415#include "build/build_config.h"
[email protected]0f24e53e2012-10-29 01:04:0916
17namespace base {
18
[email protected]35b4f0c2014-06-26 16:55:2719#if !defined(OS_ANDROID)
20
21static const int kLowMemoryDeviceThresholdMB = 512;
22
23bool DetectLowEndDevice() {
24 CommandLine* command_line = CommandLine::ForCurrentProcess();
ssidfeb3f47d2014-12-16 16:04:0225 if (command_line->HasSwitch(switches::kEnableLowEndDeviceMode))
[email protected]35b4f0c2014-06-26 16:55:2726 return true;
ssidfeb3f47d2014-12-16 16:04:0227 if (command_line->HasSwitch(switches::kDisableLowEndDeviceMode))
[email protected]35b4f0c2014-06-26 16:55:2728 return false;
29
30 int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB();
mariakhomenko0064e5e2016-04-28 19:25:3331 return (ram_size_mb > 0 && ram_size_mb <= kLowMemoryDeviceThresholdMB);
[email protected]35b4f0c2014-06-26 16:55:2732}
33
34static LazyInstance<
35 internal::LazySysInfoValue<bool, DetectLowEndDevice> >::Leaky
36 g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER;
37
38// static
39bool SysInfo::IsLowEndDevice() {
cnwand4270e82015-05-06 06:11:4540 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.
brettw89365dc2015-06-16 05:52:4745 if (StartsWith(group_name, "Enabled", CompareCase::SENSITIVE))
cnwand4270e82015-05-06 06:11:4546 return true;
47
[email protected]35b4f0c2014-06-26 16:55:2748 return g_lazy_low_end_device.Get().value();
49}
50#endif
51
tdresserae4166952015-07-16 15:41:0452#if (!defined(OS_MACOSX) || defined(OS_IOS)) && !defined(OS_ANDROID)
jeremyba4eca92014-11-06 18:47:1053std::string SysInfo::HardwareModelName() {
54 return std::string();
55}
56#endif
57
[email protected]0f24e53e2012-10-29 01:04:0958// static
sque0f78ba542015-11-05 00:01:0359base::TimeDelta SysInfo::Uptime() {
[email protected]0f24e53e2012-10-29 01:04:0960 // 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.
avidd4e614352015-12-09 00:44:4963 int64_t uptime_in_microseconds = TimeTicks::Now().ToInternalValue();
sque0f78ba542015-11-05 00:01:0364 return base::TimeDelta::FromMicroseconds(uptime_in_microseconds);
[email protected]0f24e53e2012-10-29 01:04:0965}
66
67} // namespace base