Skip to content

Commit

Permalink
base::mac::IsOSSierra() -> base::mac::IsOS10_12(), etc.
Browse files Browse the repository at this point in the history
BUG=636093
TBR=jam@chromium.org

Review-Url: https://codereview.chromium.org/2271653006
Cr-Commit-Position: refs/heads/master@{#415359}
  • Loading branch information
s4y authored and Commit bot committed Aug 30, 2016
1 parent e88d168 commit 07171a4
Show file tree
Hide file tree
Showing 48 changed files with 213 additions and 282 deletions.
131 changes: 61 additions & 70 deletions base/mac/mac_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef BASE_MAC_MAC_UTIL_H_
#define BASE_MAC_MAC_UTIL_H_

#include <AvailabilityMacros.h>
#include <Carbon/Carbon.h>
#include <stdint.h>
#include <string>
Expand Down Expand Up @@ -108,85 +107,77 @@ BASE_EXPORT bool WasLaunchedAsHiddenLoginItem();
// an error, or true otherwise.
BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path);

// 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
// know for sure that you need to check for a specific version.

// Mavericks is OS X 10.9, Darwin 13.
BASE_EXPORT bool IsOSMavericks();

// Yosemite is OS X 10.10, Darwin 14.
BASE_EXPORT bool IsOSYosemite();
BASE_EXPORT bool IsOSYosemiteOrEarlier();
BASE_EXPORT bool IsOSYosemiteOrLater();

// El Capitan is OS X 10.11, Darwin 15.
BASE_EXPORT bool IsOSElCapitan();
BASE_EXPORT bool IsOSElCapitanOrEarlier();
BASE_EXPORT bool IsOSElCapitanOrLater();
namespace internal {

// Sierra is macOS 10.12, Darwin 16.
BASE_EXPORT bool IsOSSierra();
BASE_EXPORT bool IsOSSierraOrLater();
// Returns the system's Mac OS X minor version. This is the |y| value
// in 10.y or 10.y.z.
BASE_EXPORT int MacOSXMinorVersion();

// 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
} // namespace internal

#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
// Run-time OS version checks. Use these instead of
// base::SysInfo::OperatingSystemVersionNumbers. Prefer the "AtLeast" and
// "AtMost" variants to those that check for a specific version, unless you
// know for sure that you need to check for a specific version.

#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; }
#define _DEFINE_IS_OS_FUNCS(V, ID) \
inline bool IsOS10_##V() { \
return MAC_OS_X_VERSION_MIN_REQUIRED <= ID && \
internal::MacOSXMinorVersion() == V; \
} \
inline bool IsAtLeastOS10_##V() { \
return MAC_OS_X_VERSION_MIN_REQUIRED >= ID || \
internal::MacOSXMinorVersion() >= V; \
} \
inline bool IsAtMostOS10_##V() { \
return MAC_OS_X_VERSION_MIN_REQUIRED <= ID && \
internal::MacOSXMinorVersion() <= V; \
}

// Apple adopted this format in 10.10: 10.11.0 becomes 101100
#define OS_X_VERSION_ID(V) 10##V##00
#define DEFINE_IS_OS_FUNCS(V) _DEFINE_IS_OS_FUNCS(V, OS_X_VERSION_ID(V))

// Sanity check that our computed IDs match the SDK
#define STR(S) _STR(S)
#define _STR(S) #S
#define ASSERT_OS_ID_CONSTANT(V) \
static_assert(OS_X_VERSION_ID(V) == MAC_OS_X_VERSION_10_##V, \
"ID for macOS 10." #V \
" (" STR(OS_X_VERSION_ID(V)) ") doesn't match the SDK (" STR( \
MAC_OS_X_VERSION_10_##V) ").");

// 10.9 uses an old format.
// TODO(sdy): Ditch, most callers are better served by !IsAtLeastOS10_10().
_DEFINE_IS_OS_FUNCS(9, MAC_OS_X_VERSION_10_9)

DEFINE_IS_OS_FUNCS(10)
ASSERT_OS_ID_CONSTANT(10)

DEFINE_IS_OS_FUNCS(11)
#ifdef MAC_OS_X_VERSION_10_11
ASSERT_OS_ID_CONSTANT(11)
#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; }
DEFINE_IS_OS_FUNCS(12)
#ifdef MAC_OS_X_VERSION_10_12
ASSERT_OS_ID_CONSTANT(12)
#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
#undef ASSERT_OS_ID_CONSTANT
#undef _STR
#undef STR

#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
#undef DEFINE_IS_OS_FUNCS
#undef MAC_OS_X_VERISON_ID
#undef _DEFINE_IS_OS_FUNCS

#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
// 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.
inline bool IsOSLaterThan10_12_DontCallThis() {
return !IsAtMostOS10_12();
}

// Retrieve the system's model identifier string from the IOKit registry:
// for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
Expand Down
63 changes: 4 additions & 59 deletions base/mac/mac_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -448,69 +448,14 @@ int MacOSXMinorVersionInternal() {
return mac_os_x_minor_version;
}

// Returns the running system's Mac OS X minor version. This is the |y| value
// in 10.y or 10.y.z.
} // namespace

namespace internal {
int MacOSXMinorVersion() {
static int mac_os_x_minor_version = MacOSXMinorVersionInternal();
return mac_os_x_minor_version;
}

enum {
MAVERICKS_MINOR_VERSION = 9,
YOSEMITE_MINOR_VERSION = 10,
EL_CAPITAN_MINOR_VERSION = 11,
SIERRA_MINOR_VERSION = 12,
};

} // namespace

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_9)
bool IsOSMavericks() {
return MacOSXMinorVersion() == MAVERICKS_MINOR_VERSION;
}
#endif

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_10)
bool IsOSYosemite() {
return MacOSXMinorVersion() == YOSEMITE_MINOR_VERSION;
}
#endif

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_10)
bool IsOSYosemiteOrLater() {
return MacOSXMinorVersion() >= YOSEMITE_MINOR_VERSION;
}
#endif

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_11)
bool IsOSElCapitan() {
return MacOSXMinorVersion() == EL_CAPITAN_MINOR_VERSION;
}
#endif

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_11)
bool IsOSElCapitanOrLater() {
return MacOSXMinorVersion() >= EL_CAPITAN_MINOR_VERSION;
}
#endif

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_12)
bool IsOSSierra() {
return MacOSXMinorVersion() == SIERRA_MINOR_VERSION;
}
#endif

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_12)
bool IsOSSierraOrLater() {
return MacOSXMinorVersion() >= SIERRA_MINOR_VERSION;
}
#endif

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_12)
bool IsOSLaterThanSierra_DontCallThis() {
return MacOSXMinorVersion() > SIERRA_MINOR_VERSION;
}
#endif
} // namespace internal

std::string GetModelIdentifier() {
std::string return_string;
Expand Down
92 changes: 52 additions & 40 deletions base/mac/mac_util_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,49 +146,61 @@

if (major == 10) {
if (minor == 9) {
EXPECT_TRUE(IsOSMavericks());
EXPECT_FALSE(IsOSYosemite());
EXPECT_TRUE(IsOSYosemiteOrEarlier());
EXPECT_FALSE(IsOSYosemiteOrLater());
EXPECT_FALSE(IsOSElCapitan());
EXPECT_TRUE(IsOSElCapitanOrEarlier());
EXPECT_FALSE(IsOSElCapitanOrLater());
EXPECT_FALSE(IsOSSierra());
EXPECT_FALSE(IsOSSierraOrLater());
EXPECT_FALSE(IsOSLaterThanSierra_DontCallThis());
EXPECT_TRUE(IsOS10_9());
EXPECT_TRUE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());
EXPECT_FALSE(IsOS10_10());
EXPECT_TRUE(IsAtMostOS10_10());
EXPECT_FALSE(IsAtLeastOS10_10());
EXPECT_FALSE(IsOS10_11());
EXPECT_TRUE(IsAtMostOS10_11());
EXPECT_FALSE(IsAtLeastOS10_11());
EXPECT_FALSE(IsOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());
EXPECT_TRUE(IsAtMostOS10_12());
EXPECT_FALSE(IsOSLaterThan10_12_DontCallThis());
} else if (minor == 10) {
EXPECT_FALSE(IsOSMavericks());
EXPECT_TRUE(IsOSYosemite());
EXPECT_TRUE(IsOSYosemiteOrEarlier());
EXPECT_TRUE(IsOSYosemiteOrLater());
EXPECT_FALSE(IsOSElCapitan());
EXPECT_TRUE(IsOSElCapitanOrEarlier());
EXPECT_FALSE(IsOSElCapitanOrLater());
EXPECT_FALSE(IsOSSierra());
EXPECT_FALSE(IsOSSierraOrLater());
EXPECT_FALSE(IsOSLaterThanSierra_DontCallThis());
EXPECT_FALSE(IsOS10_9());
EXPECT_FALSE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());
EXPECT_TRUE(IsOS10_10());
EXPECT_TRUE(IsAtMostOS10_10());
EXPECT_TRUE(IsAtLeastOS10_10());
EXPECT_FALSE(IsOS10_11());
EXPECT_TRUE(IsAtMostOS10_11());
EXPECT_FALSE(IsAtLeastOS10_11());
EXPECT_FALSE(IsOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());
EXPECT_TRUE(IsAtMostOS10_12());
EXPECT_FALSE(IsOSLaterThan10_12_DontCallThis());
} else if (minor == 11) {
EXPECT_FALSE(IsOSMavericks());
EXPECT_FALSE(IsOSYosemite());
EXPECT_FALSE(IsOSYosemiteOrEarlier());
EXPECT_TRUE(IsOSYosemiteOrLater());
EXPECT_TRUE(IsOSElCapitan());
EXPECT_TRUE(IsOSElCapitanOrEarlier());
EXPECT_TRUE(IsOSElCapitanOrLater());
EXPECT_FALSE(IsOSSierra());
EXPECT_FALSE(IsOSSierraOrLater());
EXPECT_FALSE(IsOSLaterThanSierra_DontCallThis());
EXPECT_FALSE(IsOS10_9());
EXPECT_FALSE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());
EXPECT_FALSE(IsOS10_10());
EXPECT_FALSE(IsAtMostOS10_10());
EXPECT_TRUE(IsAtLeastOS10_10());
EXPECT_TRUE(IsOS10_11());
EXPECT_TRUE(IsAtMostOS10_11());
EXPECT_TRUE(IsAtLeastOS10_11());
EXPECT_FALSE(IsOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());
EXPECT_TRUE(IsAtMostOS10_12());
EXPECT_FALSE(IsOSLaterThan10_12_DontCallThis());
} else if (minor == 12) {
EXPECT_FALSE(IsOSMavericks());
EXPECT_FALSE(IsOSYosemite());
EXPECT_FALSE(IsOSYosemiteOrEarlier());
EXPECT_TRUE(IsOSYosemiteOrLater());
EXPECT_FALSE(IsOSElCapitan());
EXPECT_FALSE(IsOSElCapitanOrEarlier());
EXPECT_TRUE(IsOSElCapitanOrLater());
EXPECT_TRUE(IsOSSierra());
EXPECT_TRUE(IsOSSierraOrLater());
EXPECT_FALSE(IsOSLaterThanSierra_DontCallThis());
EXPECT_FALSE(IsOS10_9());
EXPECT_FALSE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());
EXPECT_FALSE(IsOS10_10());
EXPECT_FALSE(IsAtMostOS10_10());
EXPECT_TRUE(IsAtLeastOS10_10());
EXPECT_FALSE(IsOS10_11());
EXPECT_FALSE(IsAtMostOS10_11());
EXPECT_TRUE(IsAtLeastOS10_11());
EXPECT_TRUE(IsOS10_12());
EXPECT_TRUE(IsAtMostOS10_12());
EXPECT_TRUE(IsAtLeastOS10_12());
EXPECT_FALSE(IsOSLaterThan10_12_DontCallThis());
} else {
// Not nine, ten, eleven, or twelve. Ah, ah, ah.
EXPECT_TRUE(false);
Expand Down
2 changes: 1 addition & 1 deletion base/process/memory_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void oom_killer_new() {
// === Core Foundation CFAllocators ===

bool CanGetContextForCFAllocator() {
return !base::mac::IsOSLaterThanSierra_DontCallThis();
return !base::mac::IsOSLaterThan10_12_DontCallThis();
}

CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) {
Expand Down
2 changes: 1 addition & 1 deletion base/sys_info_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// cases in 10.9, rely on ::Gestalt(..). Since this code is only needed for
// 10.9.0 and 10.9.1 and uses the recommended replacement thereafter,
// suppress the warning for this fallback case.
DCHECK(base::mac::IsOSMavericks());
DCHECK(base::mac::IsOS10_9());
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Gestalt(gestaltSystemVersionMajor,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/app_controller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ - (void)application:(NSApplication*)application
#pragma mark - Handoff Manager

- (BOOL)shouldUseHandoff {
return base::mac::IsOSYosemiteOrLater();
return base::mac::IsAtLeastOS10_10();
}

- (void)passURLToHandoffManager:(const GURL&)handoffURL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void TestControls(AppWindow* app_window) {
// fullscreen action. The above check that collectionBehavior does not include
// NSWindowCollectionBehaviorFullScreenPrimary is sufficient to determine that
// the window can't be fullscreened.
if (base::mac::IsOSMavericks()) {
if (base::mac::IsOS10_9()) {
EXPECT_EQ(can_fullscreen,
[[ns_window standardWindowButton:NSWindowZoomButton] isEnabled]);
}
Expand Down Expand Up @@ -636,7 +636,7 @@ void TestControls(AppWindow* app_window) {
// NOTE: This doesn't work with Views, but the regular test does, so use that.
bool mac_views = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableMacViewsNativeAppWindows);
if (base::mac::IsOSMavericks() && !mac_views) {
if (base::mac::IsOS10_9() && !mac_views) {
// -[NSView setNeedsDisplay:YES] doesn't synchronously display the view, it
// gets drawn by another event in the queue, so let that run first.
content::RunAllPendingInMessageLoop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ - (void)viewDidLoad {
if (bridge_) {
// When running on 10.10, expect both -awakeFromNib and -viewDidLoad to be
// called, but only initialize once.
DCHECK(base::mac::IsOSYosemiteOrLater());
DCHECK(base::mac::IsAtLeastOS10_10());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1640,10 +1640,10 @@ virtual void AddCommandLineSwitches() {}
153.0, 143.0, 142.0 };
CGFloat* view_widths = NULL;
bool is_mode_material = ui::MaterialDesignController::IsModeMaterial();
if (base::mac::IsOSElCapitan()) {
if (base::mac::IsOS10_11()) {
view_widths = is_mode_material ? material_view_widths_el_capitan
: view_widths_el_capitan;
} else if (base::mac::IsOSYosemite()) {
} else if (base::mac::IsOS10_10()) {
view_widths = is_mode_material ? material_view_widths_yosemite
: view_widths_yosemite;
} else {
Expand Down
Loading

0 comments on commit 07171a4

Please sign in to comment.