blob: 48c7bd944841b1f215e44c0cff71a02c1dff54c4 [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>
9
10#include "base/logging.h"
11#include "base/mac/scoped_nsautorelease_pool.h"
12#include "base/sys_string_conversions.h"
13
14namespace base {
15
16// static
17std::string SysInfo::OperatingSystemName() {
18 base::mac::ScopedNSAutoreleasePool pool;
19 // Examples of returned value: 'iPhone OS' on iPad 5.1.1
20 // and iPhone 5.1.1.
21 return SysNSStringToUTF8([[UIDevice currentDevice] systemName]);
22}
23
24// static
25std::string SysInfo::OperatingSystemVersion() {
26 base::mac::ScopedNSAutoreleasePool pool;
27 return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]);
28}
29
30// static
31void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
32 int32* minor_version,
33 int32* bugfix_version) {
34 base::mac::ScopedNSAutoreleasePool pool;
35 NSString* version = [[UIDevice currentDevice] systemVersion];
36 NSArray* version_info = [version componentsSeparatedByString:@"."];
37 NSUInteger length = [version_info count];
38
39 *major_version = [[version_info objectAtIndex:0] intValue];
40
41 if (length >= 2)
42 *minor_version = [[version_info objectAtIndex:1] intValue];
43 else
44 *minor_version = 0;
45
46 if (length >= 3)
47 *bugfix_version = [[version_info objectAtIndex:2] intValue];
48 else
49 *bugfix_version = 0;
50}
51
52// static
53int64 SysInfo::AmountOfPhysicalMemory() {
54 struct host_basic_info hostinfo;
55 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
56 int result = host_info(mach_host_self(),
57 HOST_BASIC_INFO,
58 reinterpret_cast<host_info_t>(&hostinfo),
59 &count);
60 if (result != KERN_SUCCESS) {
61 NOTREACHED();
62 return 0;
63 }
64 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
65 return static_cast<int64>(hostinfo.max_mem);
66}
67
68} // namespace base