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 #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 <AvailabilityMacros.h> | |
9 #include <Carbon/Carbon.h> | 8 #include <Carbon/Carbon.h> |
10 #include <stdint.h> | 9 #include <stdint.h> |
11 #include <string> | 10 #include <string> |
12 | 11 |
13 #include "base/base_export.h" | 12 #include "base/base_export.h" |
14 | 13 |
15 namespace base { | 14 namespace base { |
16 | 15 |
17 class FilePath; | 16 class FilePath; |
18 | 17 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState(); | 100 BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState(); |
102 | 101 |
103 // Returns true if the current process was automatically launched as a | 102 // Returns true if the current process was automatically launched as a |
104 // 'Login Item' with 'hide on startup' flag. Used to suppress opening windows. | 103 // 'Login Item' with 'hide on startup' flag. Used to suppress opening windows. |
105 BASE_EXPORT bool WasLaunchedAsHiddenLoginItem(); | 104 BASE_EXPORT bool WasLaunchedAsHiddenLoginItem(); |
106 | 105 |
107 // Remove the quarantine xattr from the given file. Returns false if there was | 106 // Remove the quarantine xattr from the given file. Returns false if there was |
108 // an error, or true otherwise. | 107 // an error, or true otherwise. |
109 BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path); | 108 BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path); |
110 | 109 |
| 110 namespace internal { |
| 111 |
| 112 // Returns the system's Mac OS X minor version. This is the |y| value |
| 113 // in 10.y or 10.y.z. |
| 114 BASE_EXPORT int MacOSXMinorVersion(); |
| 115 |
| 116 } // namespace internal |
| 117 |
111 // Run-time OS version checks. Use these instead of | 118 // Run-time OS version checks. Use these instead of |
112 // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "OrEarlier" and | 119 // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "AtLeast" and |
113 // "OrLater" variants to those that check for a specific version, unless you | 120 // "AtMost" variants to those that check for a specific version, unless you |
114 // 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. |
115 | 122 |
116 // Mavericks is OS X 10.9, Darwin 13. | 123 #define _DEFINE_IS_OS_FUNCS(V, ID) \ |
117 BASE_EXPORT bool IsOSMavericks(); | 124 inline bool IsOS10_##V() { \ |
| 125 return MAC_OS_X_VERSION_MIN_REQUIRED <= ID && \ |
| 126 internal::MacOSXMinorVersion() == V; \ |
| 127 } \ |
| 128 inline bool IsAtLeastOS10_##V() { \ |
| 129 return MAC_OS_X_VERSION_MIN_REQUIRED >= ID || \ |
| 130 internal::MacOSXMinorVersion() >= V; \ |
| 131 } \ |
| 132 inline bool IsAtMostOS10_##V() { \ |
| 133 return MAC_OS_X_VERSION_MIN_REQUIRED <= ID && \ |
| 134 internal::MacOSXMinorVersion() <= V; \ |
| 135 } |
118 | 136 |
119 // Yosemite is OS X 10.10, Darwin 14. | 137 // Apple adopted this format in 10.10: 10.11.0 becomes 101100 |
120 BASE_EXPORT bool IsOSYosemite(); | 138 #define OS_X_VERSION_ID(V) 10##V##00 |
121 BASE_EXPORT bool IsOSYosemiteOrEarlier(); | 139 #define DEFINE_IS_OS_FUNCS(V) _DEFINE_IS_OS_FUNCS(V, OS_X_VERSION_ID(V)) |
122 BASE_EXPORT bool IsOSYosemiteOrLater(); | |
123 | 140 |
124 // El Capitan is OS X 10.11, Darwin 15. | 141 // Sanity check that our computed IDs match the SDK |
125 BASE_EXPORT bool IsOSElCapitan(); | 142 #define STR(S) _STR(S) |
126 BASE_EXPORT bool IsOSElCapitanOrEarlier(); | 143 #define _STR(S) #S |
127 BASE_EXPORT bool IsOSElCapitanOrLater(); | 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) ")."); |
128 | 149 |
129 // Sierra is macOS 10.12, Darwin 16. | 150 // 10.9 uses an old format. |
130 BASE_EXPORT bool IsOSSierra(); | 151 // TODO(sdy): Ditch, most callers are better served by !IsAtLeastOS10_10(). |
131 BASE_EXPORT bool IsOSSierraOrLater(); | 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 |
| 159 ASSERT_OS_ID_CONSTANT(11) |
| 160 #endif |
| 161 |
| 162 DEFINE_IS_OS_FUNCS(12) |
| 163 #ifdef MAC_OS_X_VERSION_10_12 |
| 164 ASSERT_OS_ID_CONSTANT(12) |
| 165 #endif |
| 166 |
| 167 #undef ASSERT_OS_ID_CONSTANT |
| 168 #undef _STR |
| 169 #undef STR |
| 170 |
| 171 #undef DEFINE_IS_OS_FUNCS |
| 172 #undef MAC_OS_X_VERISON_ID |
| 173 #undef _DEFINE_IS_OS_FUNCS |
132 | 174 |
133 // This should be infrequently used. It only makes sense to use this to avoid | 175 // This should be infrequently used. It only makes sense to use this to avoid |
134 // codepaths that are very likely to break on future (unreleased, untested, | 176 // codepaths that are very likely to break on future (unreleased, untested, |
135 // unborn) OS releases, or to log when the OS is newer than any known version. | 177 // unborn) OS releases, or to log when the OS is newer than any known version. |
136 BASE_EXPORT bool IsOSLaterThanSierra_DontCallThis(); | 178 inline bool IsOSLaterThan10_12_DontCallThis() { |
137 | 179 return !IsAtMostOS10_12(); |
138 // Inline functions that are redundant due to version ranges being mutually- | 180 } |
139 // exclusive. | |
140 inline bool IsOSYosemiteOrEarlier() { return !IsOSElCapitanOrLater(); } | |
141 inline bool IsOSElCapitanOrEarlier() { return !IsOSSierraOrLater(); } | |
142 | |
143 // When the deployment target is set, the code produced cannot run on earlier | |
144 // OS releases. That enables some of the IsOS* family to be implemented as | |
145 // constant-value inline functions. The MAC_OS_X_VERSION_MIN_REQUIRED macro | |
146 // contains the value of the deployment target. | |
147 | |
148 #if defined(MAC_OS_X_VERSION_10_9) && \ | |
149 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 | |
150 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_9 | |
151 inline bool IsOSMavericks() { return false; } | |
152 #endif | |
153 | |
154 #if defined(MAC_OS_X_VERSION_10_10) && \ | |
155 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 | |
156 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_10 | |
157 inline bool IsOSYosemiteOrLater() { return true; } | |
158 #endif | |
159 | |
160 #if defined(MAC_OS_X_VERSION_10_10) && \ | |
161 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_10 | |
162 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_10 | |
163 inline bool IsOSYosemite() { return false; } | |
164 #endif | |
165 | |
166 #if defined(MAC_OS_X_VERSION_10_11) && \ | |
167 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11 | |
168 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_11 | |
169 inline bool IsOSElCapitanOrLater() { return true; } | |
170 #endif | |
171 | |
172 #if defined(MAC_OS_X_VERSION_10_11) && \ | |
173 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_11 | |
174 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_11 | |
175 inline bool IsOSElCapitan() { return false; } | |
176 #endif | |
177 | |
178 #if defined(MAC_OS_X_VERSION_10_12) && \ | |
179 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 | |
180 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_12 | |
181 inline bool IsOSSierraOrLater() { return true; } | |
182 #endif | |
183 | |
184 #if defined(MAC_OS_X_VERSION_10_12) && \ | |
185 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_12 | |
186 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_12 | |
187 inline bool IsOSSierra() { return false; } | |
188 inline bool IsOSLaterThanSierra_DontCallThis() { return true; } | |
189 #endif | |
190 | 181 |
191 // Retrieve the system's model identifier string from the IOKit registry: | 182 // Retrieve the system's model identifier string from the IOKit registry: |
192 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon | 183 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon |
193 // failure. | 184 // failure. |
194 BASE_EXPORT std::string GetModelIdentifier(); | 185 BASE_EXPORT std::string GetModelIdentifier(); |
195 | 186 |
196 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). | 187 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). |
197 // If any error occurs, none of the input pointers are touched. | 188 // If any error occurs, none of the input pointers are touched. |
198 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, | 189 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, |
199 std::string* type, | 190 std::string* type, |
200 int32_t* major, | 191 int32_t* major, |
201 int32_t* minor); | 192 int32_t* minor); |
202 | 193 |
203 } // namespace mac | 194 } // namespace mac |
204 } // namespace base | 195 } // namespace base |
205 | 196 |
206 #endif // BASE_MAC_MAC_UTIL_H_ | 197 #endif // BASE_MAC_MAC_UTIL_H_ |
OLD | NEW |