Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import <Foundation/Foundation.h> | |
| 9 #include <mach/mach_host.h> | 10 #include <mach/mach_host.h> |
| 10 #include <mach/mach_init.h> | 11 #include <mach/mach_init.h> |
| 11 #include <stddef.h> | 12 #include <stddef.h> |
| 12 #include <stdint.h> | 13 #include <stdint.h> |
| 13 #include <sys/sysctl.h> | 14 #include <sys/sysctl.h> |
| 14 #include <sys/types.h> | 15 #include <sys/types.h> |
| 15 | 16 |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/mac/mac_util.h" | |
| 17 #include "base/mac/scoped_mach_port.h" | 19 #include "base/mac/scoped_mach_port.h" |
| 20 #import "base/mac/sdk_forward_declarations.h" | |
| 18 #include "base/macros.h" | 21 #include "base/macros.h" |
| 19 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 20 | 23 |
| 21 namespace base { | 24 namespace base { |
| 22 | 25 |
| 23 // static | 26 // static |
| 24 std::string SysInfo::OperatingSystemName() { | 27 std::string SysInfo::OperatingSystemName() { |
| 25 return "Mac OS X"; | 28 return "Mac OS X"; |
| 26 } | 29 } |
| 27 | 30 |
| 28 // static | 31 // static |
| 29 std::string SysInfo::OperatingSystemVersion() { | 32 std::string SysInfo::OperatingSystemVersion() { |
| 30 int32_t major, minor, bugfix; | 33 int32_t major, minor, bugfix; |
| 31 OperatingSystemVersionNumbers(&major, &minor, &bugfix); | 34 OperatingSystemVersionNumbers(&major, &minor, &bugfix); |
| 32 return base::StringPrintf("%d.%d.%d", major, minor, bugfix); | 35 return base::StringPrintf("%d.%d.%d", major, minor, bugfix); |
| 33 } | 36 } |
| 34 | 37 |
| 35 // static | 38 // static |
| 36 void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version, | 39 void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version, |
| 37 int32_t* minor_version, | 40 int32_t* minor_version, |
| 38 int32_t* bugfix_version) { | 41 int32_t* bugfix_version) { |
| 39 Gestalt(gestaltSystemVersionMajor, | 42 NSProcessInfo* processInfo = [NSProcessInfo processInfo]; |
| 40 reinterpret_cast<SInt32*>(major_version)); | 43 if ([processInfo respondsToSelector:@selector(operatingSystemVersion)]) { |
|
Nico
2016/03/31 13:59:16
Didn't someone say yesterday that this silently wo
| |
| 41 Gestalt(gestaltSystemVersionMinor, | 44 NSOperatingSystemVersion version = [processInfo operatingSystemVersion]; |
| 42 reinterpret_cast<SInt32*>(minor_version)); | 45 *major_version = version.majorVersion; |
| 43 Gestalt(gestaltSystemVersionBugFix, | 46 *minor_version = version.minorVersion; |
| 44 reinterpret_cast<SInt32*>(bugfix_version)); | 47 *bugfix_version = version.patchVersion; |
| 48 } else { | |
| 49 DCHECK(base::mac::IsOSMavericks()); | |
| 50 #pragma clang diagnostic push | |
|
Nico
2016/03/31 14:07:41
Cool, can you add a comment here explaining why it
tapted
2016/03/31 18:07:40
Done. Added:
// -[NSProcessInfo operatingSyst
| |
| 51 #pragma clang diagnostic ignored "-Wdeprecated-declarations" | |
| 52 Gestalt(gestaltSystemVersionMajor, | |
| 53 reinterpret_cast<SInt32*>(major_version)); | |
| 54 Gestalt(gestaltSystemVersionMinor, | |
| 55 reinterpret_cast<SInt32*>(minor_version)); | |
| 56 Gestalt(gestaltSystemVersionBugFix, | |
| 57 reinterpret_cast<SInt32*>(bugfix_version)); | |
| 58 #pragma clang diagnostic pop | |
| 59 } | |
| 45 } | 60 } |
| 46 | 61 |
| 47 // static | 62 // static |
| 48 int64_t SysInfo::AmountOfPhysicalMemory() { | 63 int64_t SysInfo::AmountOfPhysicalMemory() { |
| 49 struct host_basic_info hostinfo; | 64 struct host_basic_info hostinfo; |
| 50 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; | 65 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
| 51 base::mac::ScopedMachSendRight host(mach_host_self()); | 66 base::mac::ScopedMachSendRight host(mach_host_self()); |
| 52 int result = host_info(host.get(), | 67 int result = host_info(host.get(), |
| 53 HOST_BASIC_INFO, | 68 HOST_BASIC_INFO, |
| 54 reinterpret_cast<host_info_t>(&hostinfo), | 69 reinterpret_cast<host_info_t>(&hostinfo), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 105 |
| 91 std::string SysInfo::HardwareModelName() { | 106 std::string SysInfo::HardwareModelName() { |
| 92 char model[256]; | 107 char model[256]; |
| 93 size_t len = sizeof(model); | 108 size_t len = sizeof(model); |
| 94 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) | 109 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) |
| 95 return std::string(model, 0, len); | 110 return std::string(model, 0, len); |
| 96 return std::string(); | 111 return std::string(); |
| 97 } | 112 } |
| 98 | 113 |
| 99 } // namespace base | 114 } // namespace base |
| OLD | NEW |