Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: base/sys_info_ios.mm

Issue 10704123: Implement SysInfo for iOS (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove a blank line Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/base.gypi ('k') | base/sys_info_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
50 if (result != KERN_SUCCESS) { 60 if (result != KERN_SUCCESS) {
51 NOTREACHED(); 61 NOTREACHED();
52 return 0; 62 return 0;
53 } 63 }
54 64 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
55 return static_cast<int64>(hostinfo.max_mem); 65 return static_cast<int64>(hostinfo.max_mem);
56 } 66 }
57 67
58 } // namespace base 68 } // namespace base
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/sys_info_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698