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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/sys_info.cc ('k') | base/sys_info_mac.mm » ('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 (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>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return 0; 89 return 0;
90 // We should add inactive file-backed memory also but there is no such 90 // We should add inactive file-backed memory also but there is no such
91 // information from iOS unfortunately. 91 // information from iOS unfortunately.
92 return static_cast<int64_t>(info.free + info.speculative) * 1024; 92 return static_cast<int64_t>(info.free + info.speculative) * 1024;
93 } 93 }
94 94
95 // static 95 // static
96 std::string SysInfo::CPUModelName() { 96 std::string SysInfo::CPUModelName() {
97 char name[256]; 97 char name[256];
98 size_t len = arraysize(name); 98 size_t len = arraysize(name);
99 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) 99 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, nullptr, 0) == 0) {
100 return name; 100 DCHECK_GE(len, 1u);
101 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
102 return std::string(name, len - 1);
103 }
101 return std::string(); 104 return std::string();
102 } 105 }
103 106
107 // static
108 std::string SysInfo::HardwareModelName() {
109 char model[256];
110 size_t len = sizeof(model);
111 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.
112 DCHECK_GE(len, 1u);
113 DCHECK_EQ('\0', model[len - 1]);
114 return std::string(model, len - 1);
115 }
116 return std::string();
117 }
118
104 } // namespace base 119 } // namespace base
OLDNEW
« 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