Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: base/sys_info_mac.mm

Issue 1842213002: Mac: Avoid deprecated use of ::Gestalt() in base/sys_info_mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20160329-Mac-DeploymentTarget
Patch Set: clearer Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/sys_info_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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)]) {
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 // -[NSProcessInfo operatingSystemVersion] is documented available in 10.10.
50 // It's also available via a private API since 10.9.2. For the remaining
51 // cases in 10.9, rely on ::Gestalt(..). Since this code is only needed for
52 // 10.9.0 and 10.9.1 and uses the recommended replacement thereafter,
53 // suppress the warning for this fallback case.
54 DCHECK(base::mac::IsOSMavericks());
55 #pragma clang diagnostic push
56 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
57 Gestalt(gestaltSystemVersionMajor,
58 reinterpret_cast<SInt32*>(major_version));
59 Gestalt(gestaltSystemVersionMinor,
60 reinterpret_cast<SInt32*>(minor_version));
61 Gestalt(gestaltSystemVersionBugFix,
62 reinterpret_cast<SInt32*>(bugfix_version));
63 #pragma clang diagnostic pop
64 }
45 } 65 }
46 66
47 // static 67 // static
48 int64_t SysInfo::AmountOfPhysicalMemory() { 68 int64_t SysInfo::AmountOfPhysicalMemory() {
49 struct host_basic_info hostinfo; 69 struct host_basic_info hostinfo;
50 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; 70 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
51 base::mac::ScopedMachSendRight host(mach_host_self()); 71 base::mac::ScopedMachSendRight host(mach_host_self());
52 int result = host_info(host.get(), 72 int result = host_info(host.get(),
53 HOST_BASIC_INFO, 73 HOST_BASIC_INFO,
54 reinterpret_cast<host_info_t>(&hostinfo), 74 reinterpret_cast<host_info_t>(&hostinfo),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 110
91 std::string SysInfo::HardwareModelName() { 111 std::string SysInfo::HardwareModelName() {
92 char model[256]; 112 char model[256];
93 size_t len = sizeof(model); 113 size_t len = sizeof(model);
94 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) 114 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0)
95 return std::string(model, 0, len); 115 return std::string(model, 0, len);
96 return std::string(); 116 return std::string();
97 } 117 }
98 118
99 } // namespace base 119 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698