[email protected] | c6d5f8c | 2012-07-11 12:15:08 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/sys_info.h" |
| 6 | |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 7 | #include <ApplicationServices/ApplicationServices.h> |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 8 | #include <CoreServices/CoreServices.h> |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 9 | #include <mach/mach_host.h> |
| 10 | #include <mach/mach_init.h> |
[email protected] | d5df0c8c | 2012-09-08 09:53:01 | [diff] [blame] | 11 | #include <sys/sysctl.h> |
| 12 | #include <sys/types.h> |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 13 | |
| 14 | #include "base/logging.h" |
[email protected] | 431d0a1 | 2012-10-16 20:17:58 | [diff] [blame] | 15 | #include "base/mac/scoped_mach_port.h" |
[email protected] | 6e001bb | 2011-05-25 20:53:18 | [diff] [blame] | 16 | #include "base/stringprintf.h" |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 17 | |
| 18 | namespace base { |
| 19 | |
| 20 | // static |
[email protected] | 6e001bb | 2011-05-25 20:53:18 | [diff] [blame] | 21 | std::string SysInfo::OperatingSystemName() { |
| 22 | return "Mac OS X"; |
| 23 | } |
| 24 | |
| 25 | // static |
| 26 | std::string SysInfo::OperatingSystemVersion() { |
| 27 | int32 major, minor, bugfix; |
| 28 | OperatingSystemVersionNumbers(&major, &minor, &bugfix); |
| 29 | return base::StringPrintf("%d.%d.%d", major, minor, bugfix); |
| 30 | } |
| 31 | |
| 32 | // static |
[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 33 | void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
| 34 | int32* minor_version, |
| 35 | int32* bugfix_version) { |
[email protected] | 0203ed7 | 2009-07-02 13:59:08 | [diff] [blame] | 36 | Gestalt(gestaltSystemVersionMajor, |
[email protected] | 3a3e5b3 | 2009-08-21 22:30:47 | [diff] [blame] | 37 | reinterpret_cast<SInt32*>(major_version)); |
[email protected] | 0203ed7 | 2009-07-02 13:59:08 | [diff] [blame] | 38 | Gestalt(gestaltSystemVersionMinor, |
[email protected] | 3a3e5b3 | 2009-08-21 22:30:47 | [diff] [blame] | 39 | reinterpret_cast<SInt32*>(minor_version)); |
[email protected] | 0203ed7 | 2009-07-02 13:59:08 | [diff] [blame] | 40 | Gestalt(gestaltSystemVersionBugFix, |
[email protected] | 3a3e5b3 | 2009-08-21 22:30:47 | [diff] [blame] | 41 | reinterpret_cast<SInt32*>(bugfix_version)); |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 42 | } |
| 43 | |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 44 | // static |
| 45 | int64 SysInfo::AmountOfPhysicalMemory() { |
| 46 | struct host_basic_info hostinfo; |
| 47 | mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
[email protected] | 431d0a1 | 2012-10-16 20:17:58 | [diff] [blame] | 48 | base::mac::ScopedMachPort host(mach_host_self()); |
| 49 | int result = host_info(host, |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 50 | HOST_BASIC_INFO, |
| 51 | reinterpret_cast<host_info_t>(&hostinfo), |
| 52 | &count); |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 53 | if (result != KERN_SUCCESS) { |
| 54 | NOTREACHED(); |
| 55 | return 0; |
| 56 | } |
[email protected] | c6d5f8c | 2012-07-11 12:15:08 | [diff] [blame] | 57 | DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 58 | return static_cast<int64>(hostinfo.max_mem); |
| 59 | } |
| 60 | |
[email protected] | d5df0c8c | 2012-09-08 09:53:01 | [diff] [blame] | 61 | // static |
[email protected] | 52bdcda | 2012-10-27 06:10:37 | [diff] [blame^] | 62 | int64 SysInfo::AmountOfAvailablePhysicalMemory() { |
| 63 | // TODO(hongbo): Add implementation for Mac. |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | // static |
[email protected] | d5df0c8c | 2012-09-08 09:53:01 | [diff] [blame] | 68 | std::string SysInfo::CPUModelName() { |
| 69 | char name[256]; |
| 70 | size_t len = arraysize(name); |
| 71 | if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) |
| 72 | return name; |
| 73 | return std::string(); |
| 74 | } |
| 75 | |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 76 | } // namespace base |