Chromium Code Reviews| 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> | 8 #include <AvailabilityMacros.h> |
| 9 #include <Carbon/Carbon.h> | 9 #include <Carbon/Carbon.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState(); | 101 BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState(); |
| 102 | 102 |
| 103 // Returns true if the current process was automatically launched as a | 103 // Returns true if the current process was automatically launched as a |
| 104 // 'Login Item' with 'hide on startup' flag. Used to suppress opening windows. | 104 // 'Login Item' with 'hide on startup' flag. Used to suppress opening windows. |
| 105 BASE_EXPORT bool WasLaunchedAsHiddenLoginItem(); | 105 BASE_EXPORT bool WasLaunchedAsHiddenLoginItem(); |
| 106 | 106 |
| 107 // Remove the quarantine xattr from the given file. Returns false if there was | 107 // Remove the quarantine xattr from the given file. Returns false if there was |
| 108 // an error, or true otherwise. | 108 // an error, or true otherwise. |
| 109 BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path); | 109 BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path); |
| 110 | 110 |
| 111 namespace internal { | |
| 112 | |
| 113 // Returns the running system's Mac OS X minor version. This is the |y| value | |
| 114 // in 10.y or 10.y.z. | |
| 115 BASE_EXPORT int MacOSXMinorVersion(); | |
| 116 | |
| 117 // Class to compare the running system's Mac OS X minor version with a known | |
| 118 // one. When ID is a MAC_OS_X_VERSION_10_* macro from AvailabilityMacros.h, | |
| 119 // some tests may compile to constants depending on deployment target | |
| 120 // (-mmacosx-version-min). For instance, OSVersion<9>::IsAtLeast() is always | |
| 121 // true with a deployment target of 10.10. ID can also be 0 to support an OS | |
| 122 // version that's newer than the build SDK. | |
| 123 template <int V, int ID> | |
| 124 class OSVersion { | |
| 125 public: | |
| 126 static constexpr bool Equals() { | |
| 127 return !DeploymentTargetIsGreater() && MacOSXMinorVersion() == V; | |
| 128 } | |
| 129 | |
| 130 static constexpr bool IsAtLeast() { | |
| 131 return DeploymentTargetIsGreater() || MacOSXMinorVersion() >= V; | |
|
Mark Mentovai
2016/08/26 15:27:26
This doesn’t short-circuit every case that it coul
Sidney San Martín
2016/08/28 21:27:17
Good catch, thanks. Let me know if this new patch
| |
| 132 } | |
| 133 | |
| 134 static constexpr bool IsAtMost() { | |
| 135 return !DeploymentTargetIsGreater() && MacOSXMinorVersion() <= V; | |
| 136 } | |
| 137 | |
| 138 private: | |
| 139 // Is the minimum OS version greater than this one? | |
| 140 static constexpr bool DeploymentTargetIsGreater() { | |
| 141 return ID && MAC_OS_X_VERSION_MIN_REQUIRED > ID; | |
| 142 } | |
| 143 }; | |
| 144 } // namespace internal | |
| 145 | |
| 111 // Run-time OS version checks. Use these instead of | 146 // Run-time OS version checks. Use these instead of |
| 112 // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "OrEarlier" and | 147 // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "IsAtLeastOS" and |
| 113 // "OrLater" variants to those that check for a specific version, unless you | 148 // "IsAtMostOS" variants to those that check for a specific version, unless you |
| 114 // know for sure that you need to check for a specific version. | 149 // know for sure that you need to check for a specific version. |
| 115 | 150 |
| 116 // Mavericks is OS X 10.9, Darwin 13. | 151 #define DECLARE_IS_OS_FUNCS(V, ID) \ |
|
Mark Mentovai
2016/08/26 15:27:26
This defines them too, so DEFINE instead of DECLAR
Sidney San Martín
2016/08/28 21:27:17
Done.
| |
| 117 BASE_EXPORT bool IsOSMavericks(); | 152 const auto IsOS10_##V = internal::OSVersion<V, ID>::Equals; \ |
| 153 const auto IsAtLeastOS10_##V = internal::OSVersion<V, ID>::IsAtLeast; \ | |
|
Mark Mentovai
2016/08/26 15:27:26
We would not otherwise find it useful to implement
Sidney San Martín
2016/08/28 21:27:17
As discussed, I'll try to ditch the 10.9 versions
| |
| 154 const auto IsAtMostOS10_##V = internal::OSVersion<V, ID>::IsAtMost; | |
| 118 | 155 |
| 119 // Yosemite is OS X 10.10, Darwin 14. | 156 DECLARE_IS_OS_FUNCS(9, MAC_OS_X_VERSION_10_9) |
| 120 BASE_EXPORT bool IsOSYosemite(); | 157 DECLARE_IS_OS_FUNCS(10, MAC_OS_X_VERSION_10_10) |
| 121 BASE_EXPORT bool IsOSYosemiteOrEarlier(); | |
| 122 BASE_EXPORT bool IsOSYosemiteOrLater(); | |
| 123 | 158 |
| 124 // El Capitan is OS X 10.11, Darwin 15. | 159 // Remove these guards when we bump our SDK version |
| 125 BASE_EXPORT bool IsOSElCapitan(); | 160 #if defined(MAC_OS_X_VERSION_10_11) |
| 126 BASE_EXPORT bool IsOSElCapitanOrEarlier(); | 161 DECLARE_IS_OS_FUNCS(11, MAC_OS_X_VERSION_10_11) |
| 127 BASE_EXPORT bool IsOSElCapitanOrLater(); | 162 #else |
| 163 DECLARE_IS_OS_FUNCS(11, 0) | |
|
Mark Mentovai
2016/08/26 15:27:26
Since you need to do this #if thing, maybe you can
Sidney San Martín
2016/08/28 21:27:17
Done. The static_asserts and surrounding #ifdef gu
| |
| 164 #endif | |
| 128 | 165 |
| 129 // Sierra is macOS 10.12, Darwin 16. | 166 #if defined(MAC_OS_X_VERSION_10_12) |
| 130 BASE_EXPORT bool IsOSSierra(); | 167 DECLARE_IS_OS_FUNCS(12, MAC_OS_X_VERSION_10_12) |
| 131 BASE_EXPORT bool IsOSSierraOrLater(); | 168 #else |
| 169 DECLARE_IS_OS_FUNCS(12, 0) | |
| 170 #endif | |
| 171 | |
| 172 #undef DECLARE_IS_OS_FUNCS | |
| 132 | 173 |
| 133 // This should be infrequently used. It only makes sense to use this to avoid | 174 // 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, | 175 // 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. | 176 // unborn) OS releases, or to log when the OS is newer than any known version. |
| 136 BASE_EXPORT bool IsOSLaterThanSierra_DontCallThis(); | 177 inline bool IsOSLaterThan10_12_DontCallThis() { |
| 137 | 178 return !IsAtMostOS10_12(); |
| 138 // Inline functions that are redundant due to version ranges being mutually- | 179 } |
| 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 | 180 |
| 191 // Retrieve the system's model identifier string from the IOKit registry: | 181 // Retrieve the system's model identifier string from the IOKit registry: |
| 192 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon | 182 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon |
| 193 // failure. | 183 // failure. |
| 194 BASE_EXPORT std::string GetModelIdentifier(); | 184 BASE_EXPORT std::string GetModelIdentifier(); |
| 195 | 185 |
| 196 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). | 186 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). |
| 197 // If any error occurs, none of the input pointers are touched. | 187 // If any error occurs, none of the input pointers are touched. |
| 198 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, | 188 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, |
| 199 std::string* type, | 189 std::string* type, |
| 200 int32_t* major, | 190 int32_t* major, |
| 201 int32_t* minor); | 191 int32_t* minor); |
| 202 | 192 |
| 203 } // namespace mac | 193 } // namespace mac |
| 204 } // namespace base | 194 } // namespace base |
| 205 | 195 |
| 206 #endif // BASE_MAC_MAC_UTIL_H_ | 196 #endif // BASE_MAC_MAC_UTIL_H_ |
| OLD | NEW |