OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" |
11 #include "base/sys_info_internal.h" | 13 #include "base/sys_info_internal.h" |
12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
13 | 15 |
14 namespace base { | 16 namespace base { |
15 | 17 |
16 #if !defined(OS_ANDROID) | 18 #if !defined(OS_ANDROID) |
17 | 19 |
18 static const int kLowMemoryDeviceThresholdMB = 512; | 20 static const int kLowMemoryDeviceThresholdMB = 512; |
19 | 21 |
20 bool DetectLowEndDevice() { | 22 bool DetectLowEndDevice() { |
21 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 23 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
22 if (command_line->HasSwitch(switches::kEnableLowEndDeviceMode)) | 24 if (command_line->HasSwitch(switches::kEnableLowEndDeviceMode)) |
23 return true; | 25 return true; |
24 if (command_line->HasSwitch(switches::kDisableLowEndDeviceMode)) | 26 if (command_line->HasSwitch(switches::kDisableLowEndDeviceMode)) |
25 return false; | 27 return false; |
26 | 28 |
27 int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB(); | 29 int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB(); |
28 return (ram_size_mb > 0 && ram_size_mb < kLowMemoryDeviceThresholdMB); | 30 return (ram_size_mb > 0 && ram_size_mb < kLowMemoryDeviceThresholdMB); |
29 } | 31 } |
30 | 32 |
31 static LazyInstance< | 33 static LazyInstance< |
32 internal::LazySysInfoValue<bool, DetectLowEndDevice> >::Leaky | 34 internal::LazySysInfoValue<bool, DetectLowEndDevice> >::Leaky |
33 g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER; | 35 g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER; |
34 | 36 |
35 // static | 37 // static |
36 bool SysInfo::IsLowEndDevice() { | 38 bool SysInfo::IsLowEndDevice() { |
| 39 const std::string group_name = |
| 40 base::FieldTrialList::FindFullName("MemoryReduction"); |
| 41 |
| 42 // Low End Device Mode will be enabled if this client is assigned to |
| 43 // one of those EnabledXXX groups. |
| 44 if (StartsWithASCII(group_name, "Enabled", true)) |
| 45 return true; |
| 46 |
37 return g_lazy_low_end_device.Get().value(); | 47 return g_lazy_low_end_device.Get().value(); |
38 } | 48 } |
39 #endif | 49 #endif |
40 | 50 |
41 #if !defined(OS_MACOSX) || defined(OS_IOS) | 51 #if !defined(OS_MACOSX) || defined(OS_IOS) |
42 std::string SysInfo::HardwareModelName() { | 52 std::string SysInfo::HardwareModelName() { |
43 return std::string(); | 53 return std::string(); |
44 } | 54 } |
45 #endif | 55 #endif |
46 | 56 |
47 // static | 57 // static |
48 int64 SysInfo::Uptime() { | 58 int64 SysInfo::Uptime() { |
49 // This code relies on an implementation detail of TimeTicks::Now() - that | 59 // This code relies on an implementation detail of TimeTicks::Now() - that |
50 // its return value happens to coincide with the system uptime value in | 60 // its return value happens to coincide with the system uptime value in |
51 // microseconds, on Win/Mac/iOS/Linux/ChromeOS and Android. | 61 // microseconds, on Win/Mac/iOS/Linux/ChromeOS and Android. |
52 int64 uptime_in_microseconds = TimeTicks::Now().ToInternalValue(); | 62 int64 uptime_in_microseconds = TimeTicks::Now().ToInternalValue(); |
53 return uptime_in_microseconds / 1000; | 63 return uptime_in_microseconds / 1000; |
54 } | 64 } |
55 | 65 |
56 } // namespace base | 66 } // namespace base |
OLD | NEW |