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 <mach/mach.h> | 7 #include <mach/mach.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <sys/sysctl.h> | 10 #include <sys/sysctl.h> |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 #import <UIKit/UIKit.h> | 12 #import <UIKit/UIKit.h> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/mac/scoped_mach_port.h" | 15 #include "base/mac/scoped_mach_port.h" |
16 #include "base/mac/scoped_nsautorelease_pool.h" | 16 #include "base/mac/scoped_nsautorelease_pool.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/process/process_metrics.h" | 18 #include "base/process/process_metrics.h" |
19 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 | 22 |
23 namespace { | |
24 | |
25 // Queries sysctlbyname() for the given key and returns the value from the | |
26 // system or the empty string on failure. | |
27 std::string GetSysctlValue(const char* key_name) { | |
28 char value[256]; | |
29 size_t len = arraysize(value); | |
30 if (sysctlbyname(key_name, &value, &len, nullptr, 0) == 0) { | |
31 DCHECK_GE(len, 1u); | |
32 DCHECK_EQ('\0', value[len - 1]); | |
33 return std::string(value, len - 1); | |
34 } | |
35 return std::string(); | |
36 } | |
37 | |
38 } // namespace | |
39 | |
23 // static | 40 // static |
24 std::string SysInfo::OperatingSystemName() { | 41 std::string SysInfo::OperatingSystemName() { |
25 static dispatch_once_t get_system_name_once; | 42 static dispatch_once_t get_system_name_once; |
26 static std::string* system_name; | 43 static std::string* system_name; |
27 dispatch_once(&get_system_name_once, ^{ | 44 dispatch_once(&get_system_name_once, ^{ |
28 base::mac::ScopedNSAutoreleasePool pool; | 45 base::mac::ScopedNSAutoreleasePool pool; |
29 system_name = new std::string( | 46 system_name = new std::string( |
30 SysNSStringToUTF8([[UIDevice currentDevice] systemName])); | 47 SysNSStringToUTF8([[UIDevice currentDevice] systemName])); |
31 }); | 48 }); |
32 // Examples of returned value: 'iPhone OS' on iPad 5.1.1 | 49 // Examples of returned value: 'iPhone OS' on iPad 5.1.1 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 SystemMemoryInfoKB info; | 104 SystemMemoryInfoKB info; |
88 if (!GetSystemMemoryInfo(&info)) | 105 if (!GetSystemMemoryInfo(&info)) |
89 return 0; | 106 return 0; |
90 // We should add inactive file-backed memory also but there is no such | 107 // We should add inactive file-backed memory also but there is no such |
91 // information from iOS unfortunately. | 108 // information from iOS unfortunately. |
92 return static_cast<int64_t>(info.free + info.speculative) * 1024; | 109 return static_cast<int64_t>(info.free + info.speculative) * 1024; |
93 } | 110 } |
94 | 111 |
95 // static | 112 // static |
96 std::string SysInfo::CPUModelName() { | 113 std::string SysInfo::CPUModelName() { |
97 char name[256]; | 114 return GetSysctlValue("machdep.cpu.brand_string"); |
98 size_t len = arraysize(name); | 115 } |
99 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) | 116 |
100 return name; | 117 // static |
101 return std::string(); | 118 std::string SysInfo::HardwareModelName() { |
119 return GetSysctlValue("hw.model"); | |
pkl (ping after 24h if needed)
2017/05/04 19:50:22
I patched this CL and tested it on a real device (
Alexei Svitkine (slow)
2017/05/04 20:01:41
Wow - that's pretty strange. Thanks for checking!
| |
102 } | 120 } |
103 | 121 |
104 } // namespace base | 122 } // namespace base |
OLD | NEW |