Index: base/sys_info_ios.mm |
diff --git a/base/sys_info_ios.mm b/base/sys_info_ios.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a67c7fd50122a415dd2fd3088e0f7192845b1e42 |
--- /dev/null |
+++ b/base/sys_info_ios.mm |
@@ -0,0 +1,72 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/sys_info.h" |
+ |
+#import <UIKit/UIKit.h> |
+#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.
|
+#include <mach/mach_init.h> |
+ |
+#include "base/logging.h" |
+#include "base/mac/scoped_nsautorelease_pool.h" |
+#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.
|
+#include "base/sys_string_conversions.h" |
+ |
+namespace base { |
+ |
+// static |
+std::string SysInfo::OperatingSystemName() { |
+ base::mac::ScopedNSAutoreleasePool pool; |
+ 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
|
+} |
+ |
+// static |
+std::string SysInfo::OperatingSystemVersion() { |
+ base::mac::ScopedNSAutoreleasePool pool; |
+ return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]); |
+} |
+ |
+// static |
+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
|
+ int32 *minor_version, |
+ 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.
|
+ 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
|
+ static int32 sSystemVersionMinor; |
+ static int32 sSystemVersionBugFix; |
+ |
+ // 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
|
+ if (!sSystemVersionMajor) { |
+ NSString* version = [[UIDevice currentDevice] systemVersion]; |
+ NSArray* versionInfo = [version componentsSeparatedByString:@"."]; |
+ NSUInteger length = [versionInfo count]; |
+ sSystemVersionMajor = [[versionInfo objectAtIndex:0] intValue]; |
+ 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.
|
+ 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.
|
+ sSystemVersionBugFix = [[versionInfo objectAtIndex:2] intValue]; |
+ } |
+ } |
+ |
+ *major_version = sSystemVersionMajor; |
+ *minor_version = sSystemVersionMinor; |
+ *bugfix_version = sSystemVersionBugFix; |
+} |
+ |
+// static |
+int64 SysInfo::AmountOfPhysicalMemory() { |
+ struct host_basic_info hostinfo; |
+ mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
+ int result = host_info(mach_host_self(), |
+ HOST_BASIC_INFO, |
+ reinterpret_cast<host_info_t>(&hostinfo), |
+ &count); |
+ 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.
|
+ if (result != KERN_SUCCESS) { |
+ NOTREACHED(); |
+ return 0; |
+ } |
+ |
+ return static_cast<int64>(hostinfo.max_mem); |
+} |
+ |
+} // namespace base |