blob: 0b3b317fc8bf2a92a72bcf2991af8da3470ac2b0 [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"
10#include "base/strings/string_number_conversions.h"
11#include "base/sys_info_internal.h"
avi@chromium.orgb45ec932013-06-29 00:14:18 +090012#include "base/time/time.h"
jeremy@chromium.orgde658ed2012-10-29 10:04:09 +090013
14namespace base {
15
c.shu@samsung.comda21aff2014-06-27 01:55:27 +090016#if !defined(OS_ANDROID)
17
18static const int kLowMemoryDeviceThresholdMB = 512;
19
20bool DetectLowEndDevice() {
21 CommandLine* command_line = CommandLine::ForCurrentProcess();
22 int int_value = 0;
23 if (command_line->HasSwitch(switches::kLowEndDeviceMode)) {
24 std::string string_value =
25 command_line->GetSwitchValueASCII(switches::kLowEndDeviceMode);
26 StringToInt(string_value, &int_value);
27 }
28 if (int_value == 1)
29 return true;
30 if (int_value != 2)
31 return false;
32
33 int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB();
34 return (ram_size_mb > 0 && ram_size_mb < kLowMemoryDeviceThresholdMB);
35}
36
37static LazyInstance<
38 internal::LazySysInfoValue<bool, DetectLowEndDevice> >::Leaky
39 g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER;
40
41// static
42bool SysInfo::IsLowEndDevice() {
43 return g_lazy_low_end_device.Get().value();
44}
45#endif
46
jeremy@chromium.orgde658ed2012-10-29 10:04:09 +090047// static
48int64 SysInfo::Uptime() {
49 // This code relies on an implementation detail of TimeTicks::Now() - that
50 // its return value happens to coincide with the system uptime value in
51 // microseconds, on Win/Mac/iOS/Linux/ChromeOS and Android.
52 int64 uptime_in_microseconds = TimeTicks::Now().ToInternalValue();
53 return uptime_in_microseconds / 1000;
54}
55
56} // namespace base