| 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 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
| 9 #include <mach/mach_host.h> | 9 #include <mach/mach_host.h> |
| 10 #include <mach/mach_init.h> | 10 #include <mach/mach_init.h> |
| 11 #include <sys/sysctl.h> | 11 #include <sys/sysctl.h> |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/mac/scoped_mach_port.h" | 15 #include "base/mac/scoped_mach_port.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 std::string SysInfo::OperatingSystemName() { | 21 std::string SysInfo::OperatingSystemName() { |
| 22 return "Mac OS X"; | 22 return "Mac OS X"; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 std::string SysInfo::OperatingSystemVersion() { | 26 std::string SysInfo::OperatingSystemVersion() { |
| 27 int32 major, minor, bugfix; | 27 int32_t major, minor, bugfix; |
| 28 OperatingSystemVersionNumbers(&major, &minor, &bugfix); | 28 OperatingSystemVersionNumbers(&major, &minor, &bugfix); |
| 29 return base::StringPrintf("%d.%d.%d", major, minor, bugfix); | 29 return base::StringPrintf("%d.%d.%d", major, minor, bugfix); |
| 30 } | 30 } |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, | 33 void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version, |
| 34 int32* minor_version, | 34 int32_t* minor_version, |
| 35 int32* bugfix_version) { | 35 int32_t* bugfix_version) { |
| 36 Gestalt(gestaltSystemVersionMajor, | 36 Gestalt(gestaltSystemVersionMajor, |
| 37 reinterpret_cast<SInt32*>(major_version)); | 37 reinterpret_cast<SInt32*>(major_version)); |
| 38 Gestalt(gestaltSystemVersionMinor, | 38 Gestalt(gestaltSystemVersionMinor, |
| 39 reinterpret_cast<SInt32*>(minor_version)); | 39 reinterpret_cast<SInt32*>(minor_version)); |
| 40 Gestalt(gestaltSystemVersionBugFix, | 40 Gestalt(gestaltSystemVersionBugFix, |
| 41 reinterpret_cast<SInt32*>(bugfix_version)); | 41 reinterpret_cast<SInt32*>(bugfix_version)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 int64 SysInfo::AmountOfPhysicalMemory() { | 45 int64_t SysInfo::AmountOfPhysicalMemory() { |
| 46 struct host_basic_info hostinfo; | 46 struct host_basic_info hostinfo; |
| 47 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; | 47 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
| 48 base::mac::ScopedMachSendRight host(mach_host_self()); | 48 base::mac::ScopedMachSendRight host(mach_host_self()); |
| 49 int result = host_info(host.get(), | 49 int result = host_info(host.get(), |
| 50 HOST_BASIC_INFO, | 50 HOST_BASIC_INFO, |
| 51 reinterpret_cast<host_info_t>(&hostinfo), | 51 reinterpret_cast<host_info_t>(&hostinfo), |
| 52 &count); | 52 &count); |
| 53 if (result != KERN_SUCCESS) { | 53 if (result != KERN_SUCCESS) { |
| 54 NOTREACHED(); | 54 NOTREACHED(); |
| 55 return 0; | 55 return 0; |
| 56 } | 56 } |
| 57 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); | 57 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
| 58 return static_cast<int64>(hostinfo.max_mem); | 58 return static_cast<int64_t>(hostinfo.max_mem); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // static | 61 // static |
| 62 int64 SysInfo::AmountOfAvailablePhysicalMemory() { | 62 int64_t SysInfo::AmountOfAvailablePhysicalMemory() { |
| 63 base::mac::ScopedMachSendRight host(mach_host_self()); | 63 base::mac::ScopedMachSendRight host(mach_host_self()); |
| 64 vm_statistics_data_t vm_info; | 64 vm_statistics_data_t vm_info; |
| 65 mach_msg_type_number_t count = HOST_VM_INFO_COUNT; | 65 mach_msg_type_number_t count = HOST_VM_INFO_COUNT; |
| 66 | 66 |
| 67 if (host_statistics(host.get(), | 67 if (host_statistics(host.get(), |
| 68 HOST_VM_INFO, | 68 HOST_VM_INFO, |
| 69 reinterpret_cast<host_info_t>(&vm_info), | 69 reinterpret_cast<host_info_t>(&vm_info), |
| 70 &count) != KERN_SUCCESS) { | 70 &count) != KERN_SUCCESS) { |
| 71 NOTREACHED(); | 71 NOTREACHED(); |
| 72 return 0; | 72 return 0; |
| 73 } | 73 } |
| 74 | 74 |
| 75 return static_cast<int64>( | 75 return static_cast<int64_t>(vm_info.free_count - vm_info.speculative_count) * |
| 76 vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE; | 76 PAGE_SIZE; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // static | 79 // static |
| 80 std::string SysInfo::CPUModelName() { | 80 std::string SysInfo::CPUModelName() { |
| 81 char name[256]; | 81 char name[256]; |
| 82 size_t len = arraysize(name); | 82 size_t len = arraysize(name); |
| 83 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) | 83 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) |
| 84 return name; | 84 return name; |
| 85 return std::string(); | 85 return std::string(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 std::string SysInfo::HardwareModelName() { | 88 std::string SysInfo::HardwareModelName() { |
| 89 char model[256]; | 89 char model[256]; |
| 90 size_t len = sizeof(model); | 90 size_t len = sizeof(model); |
| 91 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) | 91 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) |
| 92 return std::string(model, 0, len); | 92 return std::string(model, 0, len); |
| 93 return std::string(); | 93 return std::string(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace base | 96 } // namespace base |
| OLD | NEW |