blob: 8b1ffd4521192f0f9db7e9c2b3b6621a4e6d1838 [file] [log] [blame]
[email protected]c6d5f8c2012-07-11 12:15:081// 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.
4
5#include "base/sys_info.h"
6
7#import <UIKit/UIKit.h>
8#include <mach/mach.h>
[email protected]d5df0c8c2012-09-08 09:53:019#include <sys/sysctl.h>
10#include <sys/types.h>
[email protected]c6d5f8c2012-07-11 12:15:0811
12#include "base/logging.h"
13#include "base/mac/scoped_nsautorelease_pool.h"
14#include "base/sys_string_conversions.h"
15
16namespace base {
17
18// static
19std::string SysInfo::OperatingSystemName() {
20 base::mac::ScopedNSAutoreleasePool pool;
21 // Examples of returned value: 'iPhone OS' on iPad 5.1.1
22 // and iPhone 5.1.1.
23 return SysNSStringToUTF8([[UIDevice currentDevice] systemName]);
24}
25
26// static
27std::string SysInfo::OperatingSystemVersion() {
28 base::mac::ScopedNSAutoreleasePool pool;
29 return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]);
30}
31
32// static
33void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
34 int32* minor_version,
35 int32* bugfix_version) {
36 base::mac::ScopedNSAutoreleasePool pool;
37 NSString* version = [[UIDevice currentDevice] systemVersion];
38 NSArray* version_info = [version componentsSeparatedByString:@"."];
39 NSUInteger length = [version_info count];
40
41 *major_version = [[version_info objectAtIndex:0] intValue];
42
43 if (length >= 2)
44 *minor_version = [[version_info objectAtIndex:1] intValue];
45 else
46 *minor_version = 0;
47
48 if (length >= 3)
49 *bugfix_version = [[version_info objectAtIndex:2] intValue];
50 else
51 *bugfix_version = 0;
52}
53
54// static
55int64 SysInfo::AmountOfPhysicalMemory() {
56 struct host_basic_info hostinfo;
57 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
58 int result = host_info(mach_host_self(),
59 HOST_BASIC_INFO,
60 reinterpret_cast<host_info_t>(&hostinfo),
61 &count);
62 if (result != KERN_SUCCESS) {
63 NOTREACHED();
64 return 0;
65 }
66 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
67 return static_cast<int64>(hostinfo.max_mem);
68}
69
[email protected]d5df0c8c2012-09-08 09:53:0170// static
71std::string SysInfo::CPUModelName() {
72 char name[256];
73 size_t len = arraysize(name);
74 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
75 return name;
76 return std::string();
77}
78
[email protected]c6d5f8c2012-07-11 12:15:0879} // namespace base