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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sys_info_ios.mm ('k') | base/sys_info_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_mac.mm
diff --git a/base/sys_info_mac.mm b/base/sys_info_mac.mm
index 1141bd557768bab8eb387dd62668831edd40bd92..6dc2f22a390970571cab6cbe04890472989bbe8e 100644
--- a/base/sys_info_mac.mm
+++ b/base/sys_info_mac.mm
@@ -24,6 +24,23 @@
namespace base {
+namespace {
+
+// Queries sysctlbyname() for the given key and returns the value from the
+// system or the empty string on failure.
+std::string GetSysctlValue(const char* key_name) {
+ char value[256];
+ size_t len = arraysize(value);
+ if (sysctlbyname(key_name, &value, &len, nullptr, 0) == 0) {
+ DCHECK_GE(len, 1u);
+ DCHECK_EQ('\0', value[len - 1]);
+ return std::string(value, len - 1);
+ }
+ return std::string();
+}
+
+} // namespace
+
// static
std::string SysInfo::OperatingSystemName() {
return "Mac OS X";
@@ -94,19 +111,12 @@ int64_t SysInfo::AmountOfAvailablePhysicalMemory() {
// static
std::string SysInfo::CPUModelName() {
- char name[256];
- size_t len = arraysize(name);
- if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
- return name;
- return std::string();
+ return GetSysctlValue("machdep.cpu.brand_string");
}
+// static
std::string SysInfo::HardwareModelName() {
- char model[256];
- size_t len = sizeof(model);
- if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0)
- return std::string(model, 0, len);
- return std::string();
+ return GetSysctlValue("hw.model");
}
} // namespace base
« 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