summaryrefslogtreecommitdiffstats
path: root/base/sys_info_ios.mm
diff options
context:
space:
mode:
authorleng@chromium.org <leng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-10 18:50:35 +0000
committerleng@chromium.org <leng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-10 18:50:35 +0000
commitdba7cf20f5c5eba9b373107122caf5dd547b518d (patch)
tree1681c85d5568e5a5aa824c6fa4ea30f8bcf4ab8f /base/sys_info_ios.mm
parent9f33102ee6455b54eb2925bca4ed262687b69019 (diff)
downloadchromium_src-dba7cf20f5c5eba9b373107122caf5dd547b518d.zip
chromium_src-dba7cf20f5c5eba9b373107122caf5dd547b518d.tar.gz
chromium_src-dba7cf20f5c5eba9b373107122caf5dd547b518d.tar.bz2
Cache the system version, numbers, and name, as the OS does not.
During startup, the system name and/or version is requested a number of times, and each call is 1ms or more. Changed the numbers parsing to use std::string instead of NSString so that the static variable could be an std::string, avoiding having to make the conversion every function call. BUG=None Review URL: https://chromiumcodereview.appspot.com/11437046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172092 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_info_ios.mm')
-rw-r--r--base/sys_info_ios.mm47
1 files changed, 28 insertions, 19 deletions
diff --git a/base/sys_info_ios.mm b/base/sys_info_ios.mm
index 1ee0e54..7863f6b 100644
--- a/base/sys_info_ios.mm
+++ b/base/sys_info_ios.mm
@@ -18,16 +18,28 @@ namespace base {
// static
std::string SysInfo::OperatingSystemName() {
- base::mac::ScopedNSAutoreleasePool pool;
+ static dispatch_once_t get_system_name_once;
+ static std::string* system_name;
+ dispatch_once(&get_system_name_once, ^{
+ base::mac::ScopedNSAutoreleasePool pool;
+ system_name = new std::string(
+ SysNSStringToUTF8([[UIDevice currentDevice] systemName]));
+ });
// Examples of returned value: 'iPhone OS' on iPad 5.1.1
// and iPhone 5.1.1.
- return SysNSStringToUTF8([[UIDevice currentDevice] systemName]);
+ return *system_name;
}
// static
std::string SysInfo::OperatingSystemVersion() {
- base::mac::ScopedNSAutoreleasePool pool;
- return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]);
+ static dispatch_once_t get_system_version_once;
+ static std::string* system_version;
+ dispatch_once(&get_system_version_once, ^{
+ base::mac::ScopedNSAutoreleasePool pool;
+ system_version = new std::string(
+ SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]));
+ });
+ return *system_version;
}
// static
@@ -35,21 +47,18 @@ void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
int32* minor_version,
int32* bugfix_version) {
base::mac::ScopedNSAutoreleasePool pool;
- NSString* version = [[UIDevice currentDevice] systemVersion];
- NSArray* version_info = [version componentsSeparatedByString:@"."];
- NSUInteger length = [version_info count];
-
- *major_version = [[version_info objectAtIndex:0] intValue];
-
- if (length >= 2)
- *minor_version = [[version_info objectAtIndex:1] intValue];
- else
- *minor_version = 0;
-
- if (length >= 3)
- *bugfix_version = [[version_info objectAtIndex:2] intValue];
- else
- *bugfix_version = 0;
+ std::string system_version = OperatingSystemVersion();
+ if (!system_version.empty()) {
+ // Try to parse out the version numbers from the string.
+ int num_read = sscanf(system_version.c_str(), "%d.%d.%d", major_version,
+ minor_version, bugfix_version);
+ if (num_read < 1)
+ *major_version = 0;
+ if (num_read < 2)
+ *minor_version = 0;
+ if (num_read < 3)
+ *bugfix_version = 0;
+ }
}
// static