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
3 // found in the LICENSE file.
5 #include "base/sys_info.h"
7 #import <UIKit/UIKit.h>
9 #include <sys/sysctl.h>
10 #include <sys/types.h>
12 #include "base/logging.h"
13 #include "base/mac/scoped_mach_port.h"
14 #include "base/mac/scoped_nsautorelease_pool.h"
15 #include "base/strings/sys_string_conversions.h"
20 std::string SysInfo::OperatingSystemName() {
21 static dispatch_once_t get_system_name_once;
22 static std::string* system_name;
23 dispatch_once(&get_system_name_once, ^{
24 base::mac::ScopedNSAutoreleasePool pool;
25 system_name = new std::string(
26 SysNSStringToUTF8([[UIDevice currentDevice] systemName]));
28 // Examples of returned value: 'iPhone OS' on iPad 5.1.1
34 std::string SysInfo::OperatingSystemVersion() {
35 static dispatch_once_t get_system_version_once;
36 static std::string* system_version;
37 dispatch_once(&get_system_version_once, ^{
38 base::mac::ScopedNSAutoreleasePool pool;
39 system_version = new std::string(
40 SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]));
42 return *system_version;
46 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
48 int32* bugfix_version) {
49 base::mac::ScopedNSAutoreleasePool pool;
50 std::string system_version = OperatingSystemVersion();
51 if (!system_version.empty()) {
52 // Try to parse out the version numbers from the string.
53 int num_read = sscanf(system_version.c_str(), "%d.%d.%d", major_version,
54 minor_version, bugfix_version);
65 int64 SysInfo::AmountOfPhysicalMemory() {
66 struct host_basic_info hostinfo;
67 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
68 base::mac::ScopedMachPort host(mach_host_self());
69 int result = host_info(host,
71 reinterpret_cast<host_info_t>(&hostinfo),
73 if (result != KERN_SUCCESS) {
77 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
78 return static_cast<int64>(hostinfo.max_mem);
82 std::string SysInfo::CPUModelName() {
84 size_t len = arraysize(name);
85 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)