From 81ceb2bc5087d3e7c3686e3ace0f7574a02e66fb Mon Sep 17 00:00:00 2001 From: "avi@chromium.org" Date: Thu, 12 Jun 2014 18:28:19 +0000 Subject: [PATCH] Update OS version functions. 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 --- base/mac/mac_util.h | 22 ++++++++++++-- base/mac/mac_util.mm | 21 ++++++++++--- base/mac/mac_util_unittest.mm | 36 +++++++++++++++++++---- base/process/memory_mac.mm | 2 +- base/test/expectations/expectation.cc | 5 +++- chrome/browser/chrome_browser_main_mac.mm | 11 ++++++- sandbox/mac/os_compatibility.cc | 2 +- tools/metrics/histograms/histograms.xml | 9 ++++-- 8 files changed, 90 insertions(+), 18 deletions(-) diff --git a/base/mac/mac_util.h b/base/mac/mac_util.h index e827f37c9fb9c3..5b5eebd8dc27b6 100644 --- a/base/mac/mac_util.h +++ b/base/mac/mac_util.h @@ -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 @@ -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: diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm index 5f08a44928e634..08b587f3316578 100644 --- a/base/mac/mac_util.mm +++ b/base/mac/mac_util.mm @@ -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); @@ -479,6 +479,7 @@ int MacOSXMinorVersion() { LION_MINOR_VERSION = 7, MOUNTAIN_LION_MINOR_VERSION = 8, MAVERICKS_MINOR_VERSION = 9, + YOSEMITE_MINOR_VERSION = 10, }; } // namespace @@ -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 diff --git a/base/mac/mac_util_unittest.mm b/base/mac/mac_util_unittest.mm index 079f3c2ced8bf4..956036eaf1bc5a 100644 --- a/base/mac/mac_util_unittest.mm +++ b/base/mac/mac_util_unittest.mm @@ -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()); @@ -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()); @@ -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()); @@ -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 { diff --git a/base/process/memory_mac.mm b/base/process/memory_mac.mm index 8503bbb809f3bc..789120f75294cb 100644 --- a/base/process/memory_mac.mm +++ b/base/process/memory_mac.mm @@ -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) { diff --git a/base/test/expectations/expectation.cc b/base/test/expectations/expectation.cc index 86ce655621d5e6..9b06e282f27a2e 100644 --- a/base/test/expectations/expectation.cc +++ b/base/test/expectations/expectation.cc @@ -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") { @@ -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) diff --git a/chrome/browser/chrome_browser_main_mac.mm b/chrome/browser/chrome_browser_main_mac.mm index 61a1faae2aba2b..e525ed09df8c6c 100644 --- a/chrome/browser/chrome_browser_main_mac.mm +++ b/chrome/browser/chrome_browser_main_mac.mm @@ -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, @@ -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; } diff --git a/sandbox/mac/os_compatibility.cc b/sandbox/mac/os_compatibility.cc index be0ca3ef785e12..4485006edb5ca1 100644 --- a/sandbox/mac/os_compatibility.cc +++ b/sandbox/mac/os_compatibility.cc @@ -112,7 +112,7 @@ const LaunchdCompatibilityShim GetLaunchdCompatibilityShim() { shim.look_up2_get_request_name = &LaunchdLookUp2GetRequestName; } else if (base::mac::IsOSLionOrLater() && - !base::mac::IsOSLaterThanMavericks_DontCallThis()) { + !base::mac::IsOSYosemiteOrLater()) { shim.look_up2_get_request_name = &LaunchdLookUp2GetRequestName; } else { diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index f33a46bb77b24c..9f0f16be938fb8 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -33755,9 +33755,12 @@ Therefore, the affected-histogram name has to have at least one dot in it. - - - + + + + + +