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

Side by Side Diff: base/mac/mac_util.h

Issue 2289173002: Just skip deployment target checks for OS versions newer than our SDK (Closed)
Patch Set: Drop _ prefix, CHECK -> TEST Created 4 years, 3 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 | « no previous file | 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 (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 #ifndef BASE_MAC_MAC_UTIL_H_ 5 #ifndef BASE_MAC_MAC_UTIL_H_
6 #define BASE_MAC_MAC_UTIL_H_ 6 #define BASE_MAC_MAC_UTIL_H_
7 7
8 #include <Carbon/Carbon.h> 8 #include <Carbon/Carbon.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string> 10 #include <string>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // in 10.y or 10.y.z. 113 // in 10.y or 10.y.z.
114 BASE_EXPORT int MacOSXMinorVersion(); 114 BASE_EXPORT int MacOSXMinorVersion();
115 115
116 } // namespace internal 116 } // namespace internal
117 117
118 // Run-time OS version checks. Use these instead of 118 // Run-time OS version checks. Use these instead of
119 // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "AtLeast" and 119 // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "AtLeast" and
120 // "AtMost" variants to those that check for a specific version, unless you 120 // "AtMost" variants to those that check for a specific version, unless you
121 // know for sure that you need to check for a specific version. 121 // know for sure that you need to check for a specific version.
122 122
123 #define _DEFINE_IS_OS_FUNCS(V, ID) \ 123 #define DEFINE_IS_OS_FUNCS(V, TEST_DEPLOYMENT_TARGET) \
124 inline bool IsOS10_##V() { \ 124 inline bool IsOS10_##V() { \
125 return MAC_OS_X_VERSION_MIN_REQUIRED <= ID && \ 125 TEST_DEPLOYMENT_TARGET(>, V, false) \
126 internal::MacOSXMinorVersion() == V; \ 126 return internal::MacOSXMinorVersion() == V; \
127 } \ 127 } \
128 inline bool IsAtLeastOS10_##V() { \ 128 inline bool IsAtLeastOS10_##V() { \
129 return MAC_OS_X_VERSION_MIN_REQUIRED >= ID || \ 129 TEST_DEPLOYMENT_TARGET(>=, V, true) \
130 internal::MacOSXMinorVersion() >= V; \ 130 return internal::MacOSXMinorVersion() >= V; \
131 } \ 131 } \
132 inline bool IsAtMostOS10_##V() { \ 132 inline bool IsAtMostOS10_##V() { \
133 return MAC_OS_X_VERSION_MIN_REQUIRED <= ID && \ 133 TEST_DEPLOYMENT_TARGET(>, V, false) \
134 internal::MacOSXMinorVersion() <= V; \ 134 return internal::MacOSXMinorVersion() <= V; \
135 } 135 }
136 136
137 // Apple adopted this format in 10.10: 10.11.0 becomes 101100 137 #define TEST_DEPLOYMENT_TARGET(OP, V, RET) \
138 #define OS_X_VERSION_ID(V) 10##V##00 138 if (MAC_OS_X_VERSION_MIN_REQUIRED OP MAC_OS_X_VERSION_10_##V) \
139 #define DEFINE_IS_OS_FUNCS(V) _DEFINE_IS_OS_FUNCS(V, OS_X_VERSION_ID(V)) 139 return RET;
140 #define IGNORE_DEPLOYMENT_TARGET(OP, V, RET)
140 141
141 // Sanity check that our computed IDs match the SDK 142 DEFINE_IS_OS_FUNCS(9, TEST_DEPLOYMENT_TARGET)
142 #define STR(S) _STR(S) 143 DEFINE_IS_OS_FUNCS(10, TEST_DEPLOYMENT_TARGET)
143 #define _STR(S) #S
144 #define ASSERT_OS_ID_CONSTANT(V) \
145 static_assert(OS_X_VERSION_ID(V) == MAC_OS_X_VERSION_10_##V, \
146 "ID for macOS 10." #V \
147 " (" STR(OS_X_VERSION_ID(V)) ") doesn't match the SDK (" STR( \
148 MAC_OS_X_VERSION_10_##V) ").");
149 144
150 // 10.9 uses an old format.
151 // TODO(sdy): Ditch, most callers are better served by !IsAtLeastOS10_10().
152 _DEFINE_IS_OS_FUNCS(9, MAC_OS_X_VERSION_10_9)
153
154 DEFINE_IS_OS_FUNCS(10)
155 ASSERT_OS_ID_CONSTANT(10)
156
157 DEFINE_IS_OS_FUNCS(11)
158 #ifdef MAC_OS_X_VERSION_10_11 145 #ifdef MAC_OS_X_VERSION_10_11
159 ASSERT_OS_ID_CONSTANT(11) 146 DEFINE_IS_OS_FUNCS(11, TEST_DEPLOYMENT_TARGET)
147 #else
148 DEFINE_IS_OS_FUNCS(11, IGNORE_DEPLOYMENT_TARGET)
160 #endif 149 #endif
161 150
162 DEFINE_IS_OS_FUNCS(12)
163 #ifdef MAC_OS_X_VERSION_10_12 151 #ifdef MAC_OS_X_VERSION_10_12
164 ASSERT_OS_ID_CONSTANT(12) 152 DEFINE_IS_OS_FUNCS(12, TEST_DEPLOYMENT_TARGET)
153 #else
154 DEFINE_IS_OS_FUNCS(12, IGNORE_DEPLOYMENT_TARGET)
165 #endif 155 #endif
166 156
167 #undef ASSERT_OS_ID_CONSTANT 157 #undef IGNORE_DEPLOYMENT_TARGET
168 #undef _STR 158 #undef TEST_DEPLOYMENT_TARGET
169 #undef STR
170
171 #undef DEFINE_IS_OS_FUNCS 159 #undef DEFINE_IS_OS_FUNCS
172 #undef MAC_OS_X_VERISON_ID
173 #undef _DEFINE_IS_OS_FUNCS
174 160
175 // This should be infrequently used. It only makes sense to use this to avoid 161 // This should be infrequently used. It only makes sense to use this to avoid
176 // codepaths that are very likely to break on future (unreleased, untested, 162 // codepaths that are very likely to break on future (unreleased, untested,
177 // unborn) OS releases, or to log when the OS is newer than any known version. 163 // unborn) OS releases, or to log when the OS is newer than any known version.
178 inline bool IsOSLaterThan10_12_DontCallThis() { 164 inline bool IsOSLaterThan10_12_DontCallThis() {
179 return !IsAtMostOS10_12(); 165 return !IsAtMostOS10_12();
180 } 166 }
181 167
182 // Retrieve the system's model identifier string from the IOKit registry: 168 // Retrieve the system's model identifier string from the IOKit registry:
183 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon 169 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
184 // failure. 170 // failure.
185 BASE_EXPORT std::string GetModelIdentifier(); 171 BASE_EXPORT std::string GetModelIdentifier();
186 172
187 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). 173 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1).
188 // If any error occurs, none of the input pointers are touched. 174 // If any error occurs, none of the input pointers are touched.
189 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, 175 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident,
190 std::string* type, 176 std::string* type,
191 int32_t* major, 177 int32_t* major,
192 int32_t* minor); 178 int32_t* minor);
193 179
194 } // namespace mac 180 } // namespace mac
195 } // namespace base 181 } // namespace base
196 182
197 #endif // BASE_MAC_MAC_UTIL_H_ 183 #endif // BASE_MAC_MAC_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698