Chromium Code Reviews| Index: base/sys_utils.cc |
| diff --git a/base/sys_utils.cc b/base/sys_utils.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9f099e724fdc2dc4debf2081e5b068673140e77b |
| --- /dev/null |
| +++ b/base/sys_utils.cc |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/sys_utils.h" |
| + |
| +#include "base/base_switches.h" |
| +#include "base/command_line.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/sys_info.h" |
| +#include "base/sys_info_internal.h" |
| + |
| +#if !defined(OS_ANDROID) |
| +namespace { |
| +static const int kLowMemoryDeviceThresholdMB = 512; |
| + |
| +bool detectLowEndDevice() { |
|
piman
2014/04/24 19:50:08
nit: style
c.shu
2014/06/10 17:36:26
Done.
|
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kEnableLowEndDeviceMode )) { |
| + return true; |
| + } |
| + if (command_line->HasSwitch(switches::kDisableLowEndDeviceMode)) { |
| + return false; |
| + } |
| + |
| + if (command_line->HasSwitch(switches::kDetectLowEndDevice)) { |
| + int ram_size_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
| + return (ram_size_mb > 0 && ram_size_mb < kLowMemoryDeviceThresholdMB); |
| + } |
| + return false; |
| +} |
| + |
| +static base::LazyInstance< |
| + base::internal::LazySysInfoValue<bool, detectLowEndDevice> >::Leaky |
| + g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| + |
| +namespace base { |
| +// static |
| +bool SysUtils::IsLowEndDevice() { |
| + return g_lazy_low_end_device.Get().value(); |
|
piman
2014/04/24 19:50:08
This won't work in subprocesses unless:
1- command
|
| +} |
| +} // namespace base |
| +#endif |
| + |
| +namespace base { |
| +// static |
| +size_t SysUtils::AmountOfPhysicalMemoryKB() { |
| + return SysInfo::AmountOfPhysicalMemory() / 1024; |
| +} |
| + |
| +SysUtils::SysUtils() { } |
| +} // namespace base |