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

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: 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
« base/base.gypi ('K') | « base/base.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/sys_info.h"
6
7 #import <UIKit/UIKit.h>
8 #include <mach/mach_host.h>
Mark Mentovai 2012/07/09 18:22:47 Instead of #including these two mach headers, just
Chen Yu 2012/07/10 15:51:10 Done.
9 #include <mach/mach_init.h>
10
11 #include "base/logging.h"
12 #include "base/mac/scoped_nsautorelease_pool.h"
13 #include "base/string_split.h"
Mark Mentovai 2012/07/09 18:22:47 You don’t seem to use this.
Chen Yu 2012/07/10 15:51:10 Done.
14 #include "base/sys_string_conversions.h"
15
16 namespace base {
17
18 // static
19 std::string SysInfo::OperatingSystemName() {
20 base::mac::ScopedNSAutoreleasePool pool;
21 return SysNSStringToUTF8([[UIDevice currentDevice] systemName]);
Mark Mentovai 2012/07/09 18:22:47 I’m curious: what does this return on iPhone? iPad
Chen Yu 2012/07/10 15:51:10 I saw "iPhone OS" when running it on an iPhone dev
22 }
23
24 // static
25 std::string SysInfo::OperatingSystemVersion() {
26 base::mac::ScopedNSAutoreleasePool pool;
27 return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]);
28 }
29
30 // static
31 void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
Mark Mentovai 2012/07/09 18:22:47 Chrome style puts the * on the type name. I don’t
Chen Yu 2012/07/10 15:51:10 Done.
stuartmorgan 2012/07/11 09:46:04 FWIW, the answer is that we didn't; it was wrong e
32 int32 *minor_version,
33 int32 *bugfix_version) {
Mark Mentovai 2012/07/09 18:22:47 Don’t you want a ScopedNSAutoreleasePool here too?
Chen Yu 2012/07/10 15:51:10 Done.
34 static int32 sSystemVersionMajor = 0;
Mark Mentovai 2012/07/09 18:22:47 1. There is no need to initialize this to 0. That’
Chen Yu 2012/07/10 15:51:10 Here it is changed to not to cache the information
35 static int32 sSystemVersionMinor;
36 static int32 sSystemVersionBugFix;
37
38 // iOS doesn't have Gestalt, so parse the version string.
Mark Mentovai 2012/07/09 18:22:47 This comment only makes sense in comparison to the
Chen Yu 2012/07/10 15:51:10 Removed. On 2012/07/09 18:22:47, Mark Mentovai wro
39 if (!sSystemVersionMajor) {
40 NSString* version = [[UIDevice currentDevice] systemVersion];
41 NSArray* versionInfo = [version componentsSeparatedByString:@"."];
42 NSUInteger length = [versionInfo count];
43 sSystemVersionMajor = [[versionInfo objectAtIndex:0] intValue];
44 sSystemVersionMinor = [[versionInfo objectAtIndex:1] intValue];
Mark Mentovai 2012/07/09 18:22:47 This is only safe if length >= 2. The docs don’t m
Chen Yu 2012/07/10 15:51:10 Done.
45 if (length == 3) {
Mark Mentovai 2012/07/09 18:22:47 This can be >= instead of ==.
Chen Yu 2012/07/10 15:51:10 Done.
46 sSystemVersionBugFix = [[versionInfo objectAtIndex:2] intValue];
47 }
48 }
49
50 *major_version = sSystemVersionMajor;
51 *minor_version = sSystemVersionMinor;
52 *bugfix_version = sSystemVersionBugFix;
53 }
54
55 // static
56 int64 SysInfo::AmountOfPhysicalMemory() {
57 struct host_basic_info hostinfo;
58 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
59 int result = host_info(mach_host_self(),
60 HOST_BASIC_INFO,
61 reinterpret_cast<host_info_t>(&hostinfo),
62 &count);
63 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
Mark Mentovai 2012/07/09 18:22:47 This should actually follow the “result != KERN_SU
Chen Yu 2012/07/10 15:51:10 Done.
64 if (result != KERN_SUCCESS) {
65 NOTREACHED();
66 return 0;
67 }
68
69 return static_cast<int64>(hostinfo.max_mem);
70 }
71
72 } // namespace base
OLDNEW
« base/base.gypi ('K') | « base/base.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698