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> | |
| 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 // Apple adopted this format in 10.10: 10.11.0 becomes 101100 |
| 117 BASE_EXPORT bool IsOSMavericks(); | 124 #define OS_X_VERSION_ID(V) 10##V##00 |
| 118 | 125 |
| 119 // Yosemite is OS X 10.10, Darwin 14. | 126 #define DEFINE_IS_OS_FUNCS(V) _DEFINE_IS_OS_FUNCS(V, OS_X_VERSION_ID(V)) |
|
Mark Mentovai
2016/08/29 17:48:42
I would put this after the #define _DEFINE_IS_OS_F
Sidney San Martín
2016/08/29 18:34:54
Done.
| |
| 120 BASE_EXPORT bool IsOSYosemite(); | 127 #define _DEFINE_IS_OS_FUNCS(V, ID) \ |
| 121 BASE_EXPORT bool IsOSYosemiteOrEarlier(); | 128 inline bool IsOS10_##V() { \ |
| 122 BASE_EXPORT bool IsOSYosemiteOrLater(); | 129 return MAC_OS_X_VERSION_MIN_REQUIRED <= ID && \ |
| 130 internal::MacOSXMinorVersion() == V; \ | |
| 131 } \ | |
| 132 inline bool IsAtLeastOS10_##V() { \ | |
| 133 return MAC_OS_X_VERSION_MIN_REQUIRED >= ID || \ | |
| 134 internal::MacOSXMinorVersion() >= V; \ | |
| 135 } \ | |
| 136 inline bool IsAtMostOS10_##V() { \ | |
| 137 return MAC_OS_X_VERSION_MIN_REQUIRED <= ID && \ | |
| 138 internal::MacOSXMinorVersion() <= V; \ | |
| 139 } | |
| 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 #ifdef MAC_OS_X_VERSION_10_10 | |
|
Mark Mentovai
2016/08/29 17:48:42
You shouldn’t need this #ifdef because I think we
Sidney San Martín
2016/08/29 18:34:54
Done.
| |
| 156 ASSERT_OS_ID_CONSTANT(10) | |
| 157 #endif | |
| 158 | |
| 159 DEFINE_IS_OS_FUNCS(11) | |
| 160 #ifdef MAC_OS_X_VERSION_10_11 | |
| 161 ASSERT_OS_ID_CONSTANT(11) | |
| 162 #endif | |
| 163 | |
| 164 DEFINE_IS_OS_FUNCS(12) | |
| 165 #ifdef MAC_OS_X_VERSION_10_12 | |
| 166 ASSERT_OS_ID_CONSTANT(12) | |
| 167 #endif | |
| 168 | |
| 169 #undef ASSERT_OS_ID_CONSTANT | |
| 170 #undef _STR | |
| 171 #undef STR | |
| 172 | |
| 173 #undef _DEFINE_IS_OS_FUNCS | |
| 174 #undef DEFINE_IS_OS_FUNCS | |
| 175 | |
| 176 #undef MAC_OS_X_VERISON_ID | |
| 132 | 177 |
| 133 // This should be infrequently used. It only makes sense to use this to avoid | 178 // 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, | 179 // 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. | 180 // unborn) OS releases, or to log when the OS is newer than any known version. |
| 136 BASE_EXPORT bool IsOSLaterThanSierra_DontCallThis(); | 181 inline bool IsOSLaterThan10_12_DontCallThis() { |
| 137 | 182 return !IsAtMostOS10_12(); |
| 138 // Inline functions that are redundant due to version ranges being mutually- | 183 } |
| 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 | 184 |
| 191 // Retrieve the system's model identifier string from the IOKit registry: | 185 // Retrieve the system's model identifier string from the IOKit registry: |
| 192 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon | 186 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon |
| 193 // failure. | 187 // failure. |
| 194 BASE_EXPORT std::string GetModelIdentifier(); | 188 BASE_EXPORT std::string GetModelIdentifier(); |
| 195 | 189 |
| 196 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). | 190 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). |
| 197 // If any error occurs, none of the input pointers are touched. | 191 // If any error occurs, none of the input pointers are touched. |
| 198 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, | 192 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, |
| 199 std::string* type, | 193 std::string* type, |
| 200 int32_t* major, | 194 int32_t* major, |
| 201 int32_t* minor); | 195 int32_t* minor); |
| 202 | 196 |
| 203 } // namespace mac | 197 } // namespace mac |
| 204 } // namespace base | 198 } // namespace base |
| 205 | 199 |
| 206 #endif // BASE_MAC_MAC_UTIL_H_ | 200 #endif // BASE_MAC_MAC_UTIL_H_ |
| OLD | NEW |