Create a new-installs-only uniformity trial.
[chromium-blink-merge.git] / base / sys_info_ios.mm
blob1ee0e545e3ee5054b10e7f7858d78f2577fe4b1b
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.
5 #include "base/sys_info.h"
7 #import <UIKit/UIKit.h>
8 #include <mach/mach.h>
9 #include <sys/sysctl.h>
10 #include <sys/types.h>
12 #include "base/logging.h"
13 #include "base/mac/scoped_mach_port.h"
14 #include "base/mac/scoped_nsautorelease_pool.h"
15 #include "base/sys_string_conversions.h"
17 namespace base {
19 // static
20 std::string SysInfo::OperatingSystemName() {
21   base::mac::ScopedNSAutoreleasePool pool;
22   // Examples of returned value: 'iPhone OS' on iPad 5.1.1
23   // and iPhone 5.1.1.
24   return SysNSStringToUTF8([[UIDevice currentDevice] systemName]);
27 // static
28 std::string SysInfo::OperatingSystemVersion() {
29   base::mac::ScopedNSAutoreleasePool pool;
30   return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]);
33 // static
34 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
35                                             int32* minor_version,
36                                             int32* bugfix_version) {
37   base::mac::ScopedNSAutoreleasePool pool;
38   NSString* version = [[UIDevice currentDevice] systemVersion];
39   NSArray* version_info = [version componentsSeparatedByString:@"."];
40   NSUInteger length = [version_info count];
42   *major_version = [[version_info objectAtIndex:0] intValue];
44   if (length >= 2)
45     *minor_version = [[version_info objectAtIndex:1] intValue];
46   else
47     *minor_version = 0;
49   if (length >= 3)
50     *bugfix_version = [[version_info objectAtIndex:2] intValue];
51   else
52     *bugfix_version = 0;
55 // static
56 int64 SysInfo::AmountOfPhysicalMemory() {
57   struct host_basic_info hostinfo;
58   mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
59   base::mac::ScopedMachPort host(mach_host_self());
60   int result = host_info(host,
61                          HOST_BASIC_INFO,
62                          reinterpret_cast<host_info_t>(&hostinfo),
63                          &count);
64   if (result != KERN_SUCCESS) {
65     NOTREACHED();
66     return 0;
67   }
68   DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
69   return static_cast<int64>(hostinfo.max_mem);
72 // static
73 std::string SysInfo::CPUModelName() {
74   char name[256];
75   size_t len = arraysize(name);
76   if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
77     return name;
78   return std::string();
81 }  // namespace base