Skip to content

Commit

Permalink
Update OS version functions.
Browse files Browse the repository at this point in the history
BUG=none
TEST=covered
R=asvitkine@chromium.org, mark@chromium.org

Review URL: https://codereview.chromium.org/325423005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276752 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
avi@chromium.org committed Jun 12, 2014
1 parent 97199bb commit 81ceb2b
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 18 deletions.
22 changes: 20 additions & 2 deletions base/mac/mac_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,23 @@ BASE_EXPORT bool IsOSMountainLionOrLater();

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

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

// 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 IsOSLaterThanMavericks_DontCallThis();
BASE_EXPORT bool IsOSLaterThanYosemite_DontCallThis();

// Inline functions that are redundant due to version ranges being mutually-
// exclusive.
inline bool IsOSLionOrEarlier() { return !IsOSMountainLionOrLater(); }
inline bool IsOSMountainLionOrEarlier() { return !IsOSMavericksOrLater(); }
inline bool IsOSMavericksOrEarlier() { return !IsOSYosemiteOrLater(); }

// 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
Expand Down Expand Up @@ -192,7 +198,19 @@ inline bool IsOSMavericksOrLater() { return true; }
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; }
inline bool IsOSLaterThanMavericks_DontCallThis() { 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_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; }
inline bool IsOSLaterThanYosemite_DontCallThis() { return true; }
#endif

// Retrieve the system's model identifier string from the IOKit registry:
Expand Down
21 changes: 17 additions & 4 deletions base/mac/mac_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ int MacOSXMinorVersionInternal() {
// immediate death.
CHECK(darwin_major_version >= 6);
int mac_os_x_minor_version = darwin_major_version - 4;
DLOG_IF(WARNING, darwin_major_version > 13) << "Assuming Darwin "
DLOG_IF(WARNING, darwin_major_version > 14) << "Assuming Darwin "
<< base::IntToString(darwin_major_version) << " is Mac OS X 10."
<< base::IntToString(mac_os_x_minor_version);

Expand All @@ -479,6 +479,7 @@ int MacOSXMinorVersion() {
LION_MINOR_VERSION = 7,
MOUNTAIN_LION_MINOR_VERSION = 8,
MAVERICKS_MINOR_VERSION = 9,
YOSEMITE_MINOR_VERSION = 10,
};

} // namespace
Expand Down Expand Up @@ -525,9 +526,21 @@ bool IsOSMavericksOrLater() {
}
#endif

#if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_9)
bool IsOSLaterThanMavericks_DontCallThis() {
return MacOSXMinorVersion() > MAVERICKS_MINOR_VERSION;
#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_10)
bool IsOSLaterThanYosemite_DontCallThis() {
return MacOSXMinorVersion() > YOSEMITE_MINOR_VERSION;
}
#endif

Expand Down
36 changes: 31 additions & 5 deletions base/mac/mac_util_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,11 @@
EXPECT_TRUE(IsOSMountainLionOrEarlier());
EXPECT_FALSE(IsOSMountainLionOrLater());
EXPECT_FALSE(IsOSMavericks());
EXPECT_TRUE(IsOSMavericksOrEarlier());
EXPECT_FALSE(IsOSMavericksOrLater());
EXPECT_FALSE(IsOSLaterThanMavericks_DontCallThis());
EXPECT_FALSE(IsOSYosemite());
EXPECT_FALSE(IsOSYosemiteOrLater());
EXPECT_FALSE(IsOSLaterThanYosemite_DontCallThis());
} else if (minor == 7) {
EXPECT_FALSE(IsOSSnowLeopard());
EXPECT_TRUE(IsOSLion());
Expand All @@ -161,8 +164,11 @@
EXPECT_TRUE(IsOSMountainLionOrEarlier());
EXPECT_FALSE(IsOSMountainLionOrLater());
EXPECT_FALSE(IsOSMavericks());
EXPECT_TRUE(IsOSMavericksOrEarlier());
EXPECT_FALSE(IsOSMavericksOrLater());
EXPECT_FALSE(IsOSLaterThanMavericks_DontCallThis());
EXPECT_FALSE(IsOSYosemite());
EXPECT_FALSE(IsOSYosemiteOrLater());
EXPECT_FALSE(IsOSLaterThanYosemite_DontCallThis());
} else if (minor == 8) {
EXPECT_FALSE(IsOSSnowLeopard());
EXPECT_FALSE(IsOSLion());
Expand All @@ -172,8 +178,11 @@
EXPECT_TRUE(IsOSMountainLionOrEarlier());
EXPECT_TRUE(IsOSMountainLionOrLater());
EXPECT_FALSE(IsOSMavericks());
EXPECT_TRUE(IsOSMavericksOrEarlier());
EXPECT_FALSE(IsOSMavericksOrLater());
EXPECT_FALSE(IsOSLaterThanMavericks_DontCallThis());
EXPECT_FALSE(IsOSYosemite());
EXPECT_FALSE(IsOSYosemiteOrLater());
EXPECT_FALSE(IsOSLaterThanYosemite_DontCallThis());
} else if (minor == 9) {
EXPECT_FALSE(IsOSSnowLeopard());
EXPECT_FALSE(IsOSLion());
Expand All @@ -183,10 +192,27 @@
EXPECT_FALSE(IsOSMountainLionOrEarlier());
EXPECT_TRUE(IsOSMountainLionOrLater());
EXPECT_TRUE(IsOSMavericks());
EXPECT_TRUE(IsOSMavericksOrEarlier());
EXPECT_TRUE(IsOSMavericksOrLater());
EXPECT_FALSE(IsOSLaterThanMavericks_DontCallThis());
EXPECT_FALSE(IsOSYosemite());
EXPECT_FALSE(IsOSYosemiteOrLater());
EXPECT_FALSE(IsOSLaterThanYosemite_DontCallThis());
} else if (minor == 10) {
EXPECT_FALSE(IsOSSnowLeopard());
EXPECT_FALSE(IsOSLion());
EXPECT_FALSE(IsOSLionOrEarlier());
EXPECT_TRUE(IsOSLionOrLater());
EXPECT_FALSE(IsOSMountainLion());
EXPECT_FALSE(IsOSMountainLionOrEarlier());
EXPECT_TRUE(IsOSMountainLionOrLater());
EXPECT_FALSE(IsOSMavericks());
EXPECT_FALSE(IsOSMavericksOrEarlier());
EXPECT_TRUE(IsOSMavericksOrLater());
EXPECT_TRUE(IsOSYosemite());
EXPECT_TRUE(IsOSYosemiteOrLater());
EXPECT_FALSE(IsOSLaterThanYosemite_DontCallThis());
} else {
// Not five, six, seven, eight, or nine. Ah, ah, ah.
// Not six, seven, eight, nine, or ten. Ah, ah, ah.
EXPECT_TRUE(false);
}
} else {
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 @@ -438,7 +438,7 @@ void oom_killer_new() {
// === Core Foundation CFAllocators ===

bool CanGetContextForCFAllocator() {
return !base::mac::IsOSLaterThanMavericks_DontCallThis();
return !base::mac::IsOSYosemiteOrLater();
}

CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) {
Expand Down
5 changes: 4 additions & 1 deletion base/test/expectations/expectation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ static bool IsValidPlatform(const Platform* platform) {
variant != "10.6" &&
variant != "10.7" &&
variant != "10.8" &&
variant != "10.9") {
variant != "10.9" &&
variant != "10.10") {
return false;
}
} else if (name == "Linux") {
Expand Down Expand Up @@ -111,6 +112,8 @@ Platform GetCurrentPlatform() {
platform.variant = "10.8";
else if (base::mac::IsOSMavericks())
platform.variant = "10.9";
else if (base::mac::IsOSYosemite())
platform.variant = "10.10";
#elif defined(OS_CHROMEOS)
platform.name = "ChromeOS";
#elif defined(OS_ANDROID)
Expand Down
11 changes: 10 additions & 1 deletion chrome/browser/chrome_browser_main_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
MOUNTAIN_LION_DUNNO,
MAVERICKS_DUNNO,

// More known cats.
YOSEMITE_32, // Unexpected, Yosemite requires a 64-bit CPU.
YOSEMITE_64,
YOSEMITE_DUNNO,

// Newer than any known cat.
FUTURE_CAT_32, // Unexpected, it's unlikely Apple will un-obsolete old CPUs.
FUTURE_CAT_64,
Expand Down Expand Up @@ -113,7 +118,11 @@ CatSixtyFour CatSixtyFourValue() {
return cpu64_known ? (cpu64 ? MAVERICKS_64 : MAVERICKS_32) :
MAVERICKS_DUNNO;
}
if (base::mac::IsOSLaterThanMavericks_DontCallThis()) {
if (base::mac::IsOSYosemite()) {
return cpu64_known ? (cpu64 ? YOSEMITE_64 : YOSEMITE_32) :
YOSEMITE_DUNNO;
}
if (base::mac::IsOSLaterThanYosemite_DontCallThis()) {
return cpu64_known ? (cpu64 ? FUTURE_CAT_64 : FUTURE_CAT_32) :
FUTURE_CAT_DUNNO;
}
Expand Down
2 changes: 1 addition & 1 deletion sandbox/mac/os_compatibility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const LaunchdCompatibilityShim GetLaunchdCompatibilityShim() {
shim.look_up2_get_request_name =
&LaunchdLookUp2GetRequestName<look_up2_request_10_6>;
} else if (base::mac::IsOSLionOrLater() &&
!base::mac::IsOSLaterThanMavericks_DontCallThis()) {
!base::mac::IsOSYosemiteOrLater()) {
shim.look_up2_get_request_name =
&LaunchdLookUp2GetRequestName<look_up2_request_10_7>;
} else {
Expand Down
9 changes: 6 additions & 3 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33755,9 +33755,12 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="12" label="Lion (10.7), 8-bit (?)"/>
<int value="13" label="Mountain Lion (10.8), 8-bit (?)"/>
<int value="14" label="Mavericks (10.9), 8-bit (?)"/>
<int value="15" label="FutureCat (&gt;10.9), 32-bit (?)"/>
<int value="16" label="FutureCat (&gt;10.9), 64-bit"/>
<int value="17" label="FutureCat (&gt;10.9), 8-bit (?)"/>
<int value="15" label="Yosemite (10.10), 32-bit (?)"/>
<int value="16" label="Yosemite (10.10), 64-bit"/>
<int value="17" label="Yosemite (10.10), 8-bit (?)"/>
<int value="18" label="FutureCat (&gt;10.10), 32-bit (?)"/>
<int value="19" label="FutureCat (&gt;10.10), 64-bit"/>
<int value="20" label="FutureCat (&gt;10.10), 8-bit (?)"/>
</enum>

<enum name="ChannelLayout" type="int">
Expand Down

0 comments on commit 81ceb2b

Please sign in to comment.