OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 <ApplicationServices/ApplicationServices.h> | 7 #import <UIKit/UIKit.h> |
8 #include <CoreServices/CoreServices.h> | 8 #include <mach/mach.h> |
9 #include <mach/mach_host.h> | |
10 #include <mach/mach_init.h> | |
11 | 9 |
12 #include "base/logging.h" | 10 #include "base/logging.h" |
13 #include "base/stringprintf.h" | 11 #include "base/mac/scoped_nsautorelease_pool.h" |
12 #include "base/sys_string_conversions.h" | |
14 | 13 |
15 namespace base { | 14 namespace base { |
16 | 15 |
17 // static | 16 // static |
18 std::string SysInfo::OperatingSystemName() { | 17 std::string SysInfo::OperatingSystemName() { |
19 return "Mac OS X"; | 18 base::mac::ScopedNSAutoreleasePool pool; |
19 // Examples of returned value: 'iPhone OS' on iPad 5.1.1 | |
Mark Mentovai
2012/07/10 17:11:27
Thank you!
| |
20 // and iPhone 5.1.1. | |
21 return SysNSStringToUTF8([[UIDevice currentDevice] systemName]); | |
20 } | 22 } |
21 | 23 |
22 // static | 24 // static |
23 std::string SysInfo::OperatingSystemVersion() { | 25 std::string SysInfo::OperatingSystemVersion() { |
24 int32 major, minor, bugfix; | 26 base::mac::ScopedNSAutoreleasePool pool; |
25 OperatingSystemVersionNumbers(&major, &minor, &bugfix); | 27 return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]); |
26 return base::StringPrintf("%d.%d.%d", major, minor, bugfix); | |
27 } | 28 } |
28 | 29 |
29 // static | 30 // static |
30 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, | 31 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
31 int32* minor_version, | 32 int32* minor_version, |
32 int32* bugfix_version) { | 33 int32* bugfix_version) { |
33 Gestalt(gestaltSystemVersionMajor, | 34 base::mac::ScopedNSAutoreleasePool pool; |
34 reinterpret_cast<SInt32*>(major_version)); | 35 NSString* version = [[UIDevice currentDevice] systemVersion]; |
35 Gestalt(gestaltSystemVersionMinor, | 36 NSArray* version_info = [version componentsSeparatedByString:@"."]; |
36 reinterpret_cast<SInt32*>(minor_version)); | 37 NSUInteger length = [version_info count]; |
37 Gestalt(gestaltSystemVersionBugFix, | 38 |
38 reinterpret_cast<SInt32*>(bugfix_version)); | 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; | |
39 } | 50 } |
40 | 51 |
41 // static | 52 // static |
42 int64 SysInfo::AmountOfPhysicalMemory() { | 53 int64 SysInfo::AmountOfPhysicalMemory() { |
43 struct host_basic_info hostinfo; | 54 struct host_basic_info hostinfo; |
44 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; | 55 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
45 int result = host_info(mach_host_self(), | 56 int result = host_info(mach_host_self(), |
46 HOST_BASIC_INFO, | 57 HOST_BASIC_INFO, |
47 reinterpret_cast<host_info_t>(&hostinfo), | 58 reinterpret_cast<host_info_t>(&hostinfo), |
48 &count); | 59 &count); |
49 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); | 60 |
Mark Mentovai
2012/07/10 17:11:27
Remove this blank line (so that this function matc
Chen Yu
2012/07/10 17:13:24
Done.
| |
50 if (result != KERN_SUCCESS) { | 61 if (result != KERN_SUCCESS) { |
51 NOTREACHED(); | 62 NOTREACHED(); |
52 return 0; | 63 return 0; |
53 } | 64 } |
54 | 65 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
55 return static_cast<int64>(hostinfo.max_mem); | 66 return static_cast<int64>(hostinfo.max_mem); |
56 } | 67 } |
57 | 68 |
58 } // namespace base | 69 } // namespace base |
OLD | NEW |