Chromium Code Reviews| Index: base/mac/mac_util.h |
| diff --git a/base/mac/mac_util.h b/base/mac/mac_util.h |
| index 84948f7ce89fc8b35d87be7d052fa50254afc879..9c4a9a88e656ef7e3f90b5fee019178f058a9870 100644 |
| --- a/base/mac/mac_util.h |
| +++ b/base/mac/mac_util.h |
| @@ -108,85 +108,70 @@ BASE_EXPORT bool WasLaunchedAsHiddenLoginItem(); |
| // an error, or true otherwise. |
| BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path); |
| +namespace internal { |
| + |
| +// Returns the running system's Mac OS X minor version. This is the |y| value |
| +// in 10.y or 10.y.z. |
| +BASE_EXPORT int MacOSXMinorVersion(); |
| + |
| +// Class to compare the running system's Mac OS X minor version with a known |
| +// one. When ID is a MAC_OS_X_VERSION_10_* macro from AvailabilityMacros.h, |
| +// some tests may compile to constants depending on deployment target |
| +// (-mmacosx-version-min). For instance, OSVersion<9>::IsAtLeast() is always |
| +// true with a deployment target of 10.10. ID can also be 0 to support an OS |
| +// version that's newer than the build SDK. |
| +template <int V, int ID> |
| +class OSVersion { |
| + public: |
| + static constexpr bool Equals() { |
| + return !MinVersionIsGreater() && MacOSXMinorVersion() == V; |
| + } |
| + |
| + static constexpr bool IsAtLeast() { |
| + return MinVersionIsGreater() || MacOSXMinorVersion() >= V; |
| + } |
| + |
| + static constexpr bool IsAtMost() { |
| + return !MinVersionIsGreater() && MacOSXMinorVersion() <= V; |
| + } |
| + |
| + private: |
| + // Is the minimum OS version greater than this one? |
| + 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
|
| + return ID && MAC_OS_X_VERSION_MIN_REQUIRED > ID; |
| + } |
| +}; |
| +} |
|
Mark Mentovai
2016/08/25 13:58:56
// namespace
Sidney San Martín
2016/08/26 00:00:01
Done.
|
| + |
| // Run-time OS version checks. Use these instead of |
| -// base::SysInfo::OperatingSystemVersionNumbers. Prefer the "OrEarlier" and |
| -// "OrLater" variants to those that check for a specific version, unless you |
| +// base::SysInfo::OperatingSystemVersionNumbers. Prefer the "IsAtLeastOS" and |
| +// "IsAtMostOS" variants to those that check for a specific version, unless you |
| // know for sure that you need to check for a specific version. |
| -// Mavericks is OS X 10.9, Darwin 13. |
| -BASE_EXPORT bool IsOSMavericks(); |
| +#define DECLARE_IS_OS_FUNCS_ID(V, ID) \ |
| + const auto IsOS10_##V = internal::OSVersion<V, ID>::Equals; \ |
| + const auto IsAtLeastOS10_##V = internal::OSVersion<V, ID>::IsAtLeast; \ |
| + const auto IsAtMostOS10_##V = internal::OSVersion<V, ID>::IsAtMost; |
| + |
| +#define DECLARE_IS_OS_FUNCS(V) \ |
| + DECLARE_IS_OS_FUNCS_ID(V, MAC_OS_X_VERSION_10_##V) |
| -// Yosemite is OS X 10.10, Darwin 14. |
| -BASE_EXPORT bool IsOSYosemite(); |
| -BASE_EXPORT bool IsOSYosemiteOrEarlier(); |
| -BASE_EXPORT bool IsOSYosemiteOrLater(); |
| +DECLARE_IS_OS_FUNCS(9) |
| +DECLARE_IS_OS_FUNCS(10) |
| +DECLARE_IS_OS_FUNCS(11) |
| -// El Capitan is OS X 10.11, Darwin 15. |
| -BASE_EXPORT bool IsOSElCapitan(); |
| -BASE_EXPORT bool IsOSElCapitanOrEarlier(); |
| -BASE_EXPORT bool IsOSElCapitanOrLater(); |
| +// 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
|
| +DECLARE_IS_OS_FUNCS_ID(12, 0) |
| -// Sierra is macOS 10.12, Darwin 16. |
| -BASE_EXPORT bool IsOSSierra(); |
| -BASE_EXPORT bool IsOSSierraOrLater(); |
| +#undef DECLARE_IS_OS_FUNCS |
| +#undef DECLARE_IS_OS_FUNCS_ID |
| // This should be infrequently used. It only makes sense to use this to avoid |
| // codepaths that are very likely to break on future (unreleased, untested, |
| // unborn) OS releases, or to log when the OS is newer than any known version. |
| -BASE_EXPORT bool IsOSLaterThanSierra_DontCallThis(); |
| - |
| -// Inline functions that are redundant due to version ranges being mutually- |
| -// exclusive. |
| -inline bool IsOSYosemiteOrEarlier() { return !IsOSElCapitanOrLater(); } |
| -inline bool IsOSElCapitanOrEarlier() { return !IsOSSierraOrLater(); } |
| - |
| -// When the deployment target is set, the code produced cannot run on earlier |
| -// OS releases. That enables some of the IsOS* family to be implemented as |
| -// constant-value inline functions. The MAC_OS_X_VERSION_MIN_REQUIRED macro |
| -// contains the value of the deployment target. |
| - |
| -#if defined(MAC_OS_X_VERSION_10_9) && \ |
| - MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 |
| -#define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_9 |
| -inline bool IsOSMavericks() { return false; } |
| -#endif |
| - |
| -#if defined(MAC_OS_X_VERSION_10_10) && \ |
| - MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 |
| -#define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_10 |
| -inline bool IsOSYosemiteOrLater() { return true; } |
| -#endif |
| - |
| -#if defined(MAC_OS_X_VERSION_10_10) && \ |
| - MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_10 |
| -#define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_10 |
| -inline bool IsOSYosemite() { return false; } |
| -#endif |
| - |
| -#if defined(MAC_OS_X_VERSION_10_11) && \ |
| - MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11 |
| -#define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_11 |
| -inline bool IsOSElCapitanOrLater() { return true; } |
| -#endif |
| - |
| -#if defined(MAC_OS_X_VERSION_10_11) && \ |
| - MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_11 |
| -#define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_11 |
| -inline bool IsOSElCapitan() { return false; } |
| -#endif |
| - |
| -#if defined(MAC_OS_X_VERSION_10_12) && \ |
| - MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 |
| -#define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_12 |
| -inline bool IsOSSierraOrLater() { return true; } |
| -#endif |
| - |
| -#if defined(MAC_OS_X_VERSION_10_12) && \ |
| - MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_12 |
| -#define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_12 |
| -inline bool IsOSSierra() { return false; } |
| -inline bool IsOSLaterThanSierra_DontCallThis() { return true; } |
| -#endif |
| +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 :).
|
| + return !IsAtMostOS10_12(); |
| +} |
| // Retrieve the system's model identifier string from the IOKit registry: |
| // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon |