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/sys_string_conversions.h"
20 std::string SysInfo::OperatingSystemName() {
21 base::mac::ScopedNSAutoreleasePool pool;
22 // Examples of returned value: 'iPhone OS' on iPad 5.1.1
24 return SysNSStringToUTF8([[UIDevice currentDevice] systemName]);
28 std::string SysInfo::OperatingSystemVersion() {
29 base::mac::ScopedNSAutoreleasePool pool;
30 return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]);
34 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
36 int32* bugfix_version) {
37 base::mac::ScopedNSAutoreleasePool pool;
38 NSString* version = [[UIDevice currentDevice] systemVersion];
39 NSArray* version_info = [version componentsSeparatedByString:@"."];
40 NSUInteger length = [version_info count];
42 *major_version = [[version_info objectAtIndex:0] intValue];
45 *minor_version = [[version_info objectAtIndex:1] intValue];
50 *bugfix_version = [[version_info objectAtIndex:2] intValue];
56 int64 SysInfo::AmountOfPhysicalMemory() {
57 struct host_basic_info hostinfo;
58 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
59 base::mac::ScopedMachPort host(mach_host_self());
60 int result = host_info(host,
62 reinterpret_cast<host_info_t>(&hostinfo),
64 if (result != KERN_SUCCESS) {
68 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
69 return static_cast<int64>(hostinfo.max_mem);
73 std::string SysInfo::CPUModelName() {
75 size_t len = arraysize(name);
76 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)