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 !MinVersionIsGreater() && MacOSXMinorVersion() == V; | |
| 128 } | |
| 129 | |
| 130 static constexpr bool IsAtLeast() { | |
| 131 return MinVersionIsGreater() || MacOSXMinorVersion() >= V; | |
| 132 } | |
| 133 | |
| 134 static constexpr bool IsAtMost() { | |
| 135 return !MinVersionIsGreater() && MacOSXMinorVersion() <= V; | |
| 136 } | |
| 137 | |
| 138 private: | |
| 139 // Is the minimum OS version greater than this one? | |
| 140 static constexpr bool MinVersionIsGreater() { | |
|
Mark Mentovai
2016/08/25 13:58:56
DeploymentTargetIsGreater() or MinRuntimeVersionIs
Sidney San Martín
2016/08/26 00:00:01
I like DeploymentTargetIsGreater(), even though it
| |
| 141 return ID && MAC_OS_X_VERSION_MIN_REQUIRED > ID; | |
| 142 } | |
| 143 }; | |
| 144 } | |
|
Mark Mentovai
2016/08/25 13:58:56
// namespace
Sidney San Martín
2016/08/26 00:00:01
Done.
| |
| 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_ID(V, ID) \ |
| 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; \ | |
| 154 const auto IsAtMostOS10_##V = internal::OSVersion<V, ID>::IsAtMost; | |
| 118 | 155 |
| 119 // Yosemite is OS X 10.10, Darwin 14. | 156 #define DECLARE_IS_OS_FUNCS(V) \ |
| 120 BASE_EXPORT bool IsOSYosemite(); | 157 DECLARE_IS_OS_FUNCS_ID(V, MAC_OS_X_VERSION_10_##V) |
| 121 BASE_EXPORT bool IsOSYosemiteOrEarlier(); | |
| 122 BASE_EXPORT bool IsOSYosemiteOrLater(); | |
| 123 | 158 |
| 124 // El Capitan is OS X 10.11, Darwin 15. | 159 DECLARE_IS_OS_FUNCS(9) |
| 125 BASE_EXPORT bool IsOSElCapitan(); | 160 DECLARE_IS_OS_FUNCS(10) |
| 126 BASE_EXPORT bool IsOSElCapitanOrEarlier(); | 161 DECLARE_IS_OS_FUNCS(11) |
| 127 BASE_EXPORT bool IsOSElCapitanOrLater(); | |
| 128 | 162 |
| 129 // Sierra is macOS 10.12, Darwin 16. | 163 // Until we switch to an SDK that knows about 10.12. |
|
Mark Mentovai
2016/08/25 13:58:56
I don’t think that the SDK we use for official bui
Sidney San Martín
2016/08/26 00:00:01
Done, let me know if I overlooked a more obvious w
| |
| 130 BASE_EXPORT bool IsOSSierra(); | 164 DECLARE_IS_OS_FUNCS_ID(12, 0) |
| 131 BASE_EXPORT bool IsOSSierraOrLater(); | 165 |
| 166 #undef DECLARE_IS_OS_FUNCS | |
| 167 #undef DECLARE_IS_OS_FUNCS_ID | |
| 132 | 168 |
| 133 // This should be infrequently used. It only makes sense to use this to avoid | 169 // 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, | 170 // 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. | 171 // unborn) OS releases, or to log when the OS is newer than any known version. |
| 136 BASE_EXPORT bool IsOSLaterThanSierra_DontCallThis(); | 172 inline bool IsOSLaterThanSierra_DontCallThis() { |
|
Mark Mentovai
2016/08/25 13:58:56
Probaby should rename this IsLaterThanOS10_12_Dont
Sidney San Martín
2016/08/26 00:00:01
Done, good catch :).
| |
| 137 | 173 return !IsAtMostOS10_12(); |
| 138 // Inline functions that are redundant due to version ranges being mutually- | 174 } |
| 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 | 175 |
| 191 // Retrieve the system's model identifier string from the IOKit registry: | 176 // Retrieve the system's model identifier string from the IOKit registry: |
| 192 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon | 177 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon |
| 193 // failure. | 178 // failure. |
| 194 BASE_EXPORT std::string GetModelIdentifier(); | 179 BASE_EXPORT std::string GetModelIdentifier(); |
| 195 | 180 |
| 196 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). | 181 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). |
| 197 // If any error occurs, none of the input pointers are touched. | 182 // If any error occurs, none of the input pointers are touched. |
| 198 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, | 183 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, |
| 199 std::string* type, | 184 std::string* type, |
| 200 int32_t* major, | 185 int32_t* major, |
| 201 int32_t* minor); | 186 int32_t* minor); |
| 202 | 187 |
| 203 } // namespace mac | 188 } // namespace mac |
| 204 } // namespace base | 189 } // namespace base |
| 205 | 190 |
| 206 #endif // BASE_MAC_MAC_UTIL_H_ | 191 #endif // BASE_MAC_MAC_UTIL_H_ |
| OLD | NEW |