Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: base/sys_info_mac.mm

Issue 2860663005: Implement SysInfo::HardwareModelName() on iOS. (Closed)
Patch Set: Use different simulator macro. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/sys_info_ios.mm ('k') | base/sys_info_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 #include <mach/mach_host.h> 10 #include <mach/mach_host.h>
11 #include <mach/mach_init.h> 11 #include <mach/mach_init.h>
12 #include <stddef.h> 12 #include <stddef.h>
13 #include <stdint.h> 13 #include <stdint.h>
14 #include <sys/sysctl.h> 14 #include <sys/sysctl.h>
15 #include <sys/types.h> 15 #include <sys/types.h>
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/mac/mac_util.h" 18 #include "base/mac/mac_util.h"
19 #include "base/mac/scoped_mach_port.h" 19 #include "base/mac/scoped_mach_port.h"
20 #import "base/mac/sdk_forward_declarations.h" 20 #import "base/mac/sdk_forward_declarations.h"
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/process/process_metrics.h" 22 #include "base/process/process_metrics.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 24
25 namespace base { 25 namespace base {
26 26
27 namespace {
28
29 // Queries sysctlbyname() for the given key and returns the value from the
30 // system or the empty string on failure.
31 std::string GetSysctlValue(const char* key_name) {
32 char value[256];
33 size_t len = arraysize(value);
34 if (sysctlbyname(key_name, &value, &len, nullptr, 0) == 0) {
35 DCHECK_GE(len, 1u);
36 DCHECK_EQ('\0', value[len - 1]);
37 return std::string(value, len - 1);
38 }
39 return std::string();
40 }
41
42 } // namespace
43
27 // static 44 // static
28 std::string SysInfo::OperatingSystemName() { 45 std::string SysInfo::OperatingSystemName() {
29 return "Mac OS X"; 46 return "Mac OS X";
30 } 47 }
31 48
32 // static 49 // static
33 std::string SysInfo::OperatingSystemVersion() { 50 std::string SysInfo::OperatingSystemVersion() {
34 int32_t major, minor, bugfix; 51 int32_t major, minor, bugfix;
35 OperatingSystemVersionNumbers(&major, &minor, &bugfix); 52 OperatingSystemVersionNumbers(&major, &minor, &bugfix);
36 return base::StringPrintf("%d.%d.%d", major, minor, bugfix); 53 return base::StringPrintf("%d.%d.%d", major, minor, bugfix);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Mac OS unfortunately. 108 // information from Mac OS 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);
99 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
100 return name;
101 return std::string();
102 } 115 }
103 116
117 // static
104 std::string SysInfo::HardwareModelName() { 118 std::string SysInfo::HardwareModelName() {
105 char model[256]; 119 return GetSysctlValue("hw.model");
106 size_t len = sizeof(model);
107 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0)
108 return std::string(model, 0, len);
109 return std::string();
110 } 120 }
111 121
112 } // namespace base 122 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_ios.mm ('k') | base/sys_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698