| OLD | NEW |
| 1 // Copyright (c) 2012 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 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
| 9 #include <sys/sysctl.h> | 9 #include <sys/sysctl.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/mac/scoped_mach_port.h" |
| 13 #include "base/mac/scoped_nsautorelease_pool.h" | 14 #include "base/mac/scoped_nsautorelease_pool.h" |
| 14 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 | 18 |
| 18 // static | 19 // static |
| 19 std::string SysInfo::OperatingSystemName() { | 20 std::string SysInfo::OperatingSystemName() { |
| 20 base::mac::ScopedNSAutoreleasePool pool; | 21 base::mac::ScopedNSAutoreleasePool pool; |
| 21 // Examples of returned value: 'iPhone OS' on iPad 5.1.1 | 22 // Examples of returned value: 'iPhone OS' on iPad 5.1.1 |
| 22 // and iPhone 5.1.1. | 23 // and iPhone 5.1.1. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 48 if (length >= 3) | 49 if (length >= 3) |
| 49 *bugfix_version = [[version_info objectAtIndex:2] intValue]; | 50 *bugfix_version = [[version_info objectAtIndex:2] intValue]; |
| 50 else | 51 else |
| 51 *bugfix_version = 0; | 52 *bugfix_version = 0; |
| 52 } | 53 } |
| 53 | 54 |
| 54 // static | 55 // static |
| 55 int64 SysInfo::AmountOfPhysicalMemory() { | 56 int64 SysInfo::AmountOfPhysicalMemory() { |
| 56 struct host_basic_info hostinfo; | 57 struct host_basic_info hostinfo; |
| 57 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; | 58 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
| 58 int result = host_info(mach_host_self(), | 59 base::mac::ScopedMachPort<host_name_port_t> host(mach_host_self()); |
| 60 int result = host_info(host, |
| 59 HOST_BASIC_INFO, | 61 HOST_BASIC_INFO, |
| 60 reinterpret_cast<host_info_t>(&hostinfo), | 62 reinterpret_cast<host_info_t>(&hostinfo), |
| 61 &count); | 63 &count); |
| 62 if (result != KERN_SUCCESS) { | 64 if (result != KERN_SUCCESS) { |
| 63 NOTREACHED(); | 65 NOTREACHED(); |
| 64 return 0; | 66 return 0; |
| 65 } | 67 } |
| 66 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); | 68 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
| 67 return static_cast<int64>(hostinfo.max_mem); | 69 return static_cast<int64>(hostinfo.max_mem); |
| 68 } | 70 } |
| 69 | 71 |
| 70 // static | 72 // static |
| 71 std::string SysInfo::CPUModelName() { | 73 std::string SysInfo::CPUModelName() { |
| 72 char name[256]; | 74 char name[256]; |
| 73 size_t len = arraysize(name); | 75 size_t len = arraysize(name); |
| 74 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) | 76 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) |
| 75 return name; | 77 return name; |
| 76 return std::string(); | 78 return std::string(); |
| 77 } | 79 } |
| 78 | 80 |
| 79 } // namespace base | 81 } // namespace base |
| OLD | NEW |