Index: base/sys_utils.cc |
diff --git a/base/sys_utils.cc b/base/sys_utils.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f2e8008eb102831da420cf189dae1976eb433460 |
--- /dev/null |
+++ b/base/sys_utils.cc |
@@ -0,0 +1,55 @@ |
+// 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 LOW_MEMORY_DEVICE_THRESHOLD_MB = 512; |
piman
2014/01/21 21:23:49
nit: kLowMemoryDeviceThresholdMB.
|
+ |
+bool detectLowEndDevice() { |
+ CommandLine* command_line = CommandLine::ForCurrentProcess(); |
+ if (command_line->HasSwitch(switches::kEnableLowEndDeviceMode )) { |
+ return true; |
+ } |
+ if (command_line->HasSwitch(switches::kDisableLowEndDeviceMode)) { |
+ return false; |
+ } |
+#if defined(ENABLE_LOW_END_DEVICE_DETECTION) |
piman
2014/01/21 21:23:49
Command-line flag instead of compile-time flag?
|
+ int ram_size_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
+ return (ram_size_mb > 0 && |
+ ram_size_mb < LOW_MEMORY_DEVICE_THRESHOLD_MB); |
+#else |
+ return false; |
+#endif // defined(ENABLE_LOW_END_DEVICE_DETECTION) |
+} |
+ |
+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(); |
+} |
+} // namespace base |
+#endif |
+ |
+namespace base { |
+// static |
+size_t SysUtils::AmountOfPhysicalMemoryKB() { |
+ return SysInfo::AmountOfPhysicalMemory() / 1024; |
+} |
+ |
+SysUtils::SysUtils() { } |
+} // namespace base |