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

Unified Diff: base/sys_info_ios.mm

Issue 2860663005: Implement SysInfo::HardwareModelName() on iOS. (Closed)
Patch Set: Address comments. 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.cc ('k') | base/sys_info_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_ios.mm
diff --git a/base/sys_info_ios.mm b/base/sys_info_ios.mm
index 9a329b9f0924bbdefce908cd51de4a6488c574f0..91ce72c3cc4080a05b9fb68f4529613937de989d 100644
--- a/base/sys_info_ios.mm
+++ b/base/sys_info_ios.mm
@@ -96,8 +96,23 @@ int64_t SysInfo::AmountOfAvailablePhysicalMemory() {
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;
+ if (sysctlbyname("machdep.cpu.brand_string", &name, &len, nullptr, 0) == 0) {
+ DCHECK_GE(len, 1u);
+ DCHECK_EQ('\0', name[len - 1]);
Mark Mentovai 2017/05/04 16:52:45 You don’t have to write things backwards like this
Alexei Svitkine (slow) 2017/05/04 17:10:18 Interesting. I guess I'm very used to having the
+ return std::string(name, len - 1);
+ }
+ return std::string();
+}
+
+// static
+std::string SysInfo::HardwareModelName() {
+ char model[256];
+ size_t len = sizeof(model);
+ if (sysctlbyname("hw.model", model, &len, nullptr, 0) == 0) {
Mark Mentovai 2017/05/04 16:52:45 Since these two functions are identical other than
Alexei Svitkine (slow) 2017/05/04 17:10:18 Done.
+ DCHECK_GE(len, 1u);
+ DCHECK_EQ('\0', model[len - 1]);
+ return std::string(model, len - 1);
+ }
return std::string();
}
« no previous file with comments | « base/sys_info.cc ('k') | base/sys_info_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698