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 #include "base/mac/mac_util.h" | 5 #include "base/mac/mac_util.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #import <IOKit/IOKitLib.h> | 8 #import <IOKit/IOKitLib.h> |
| 9 #include <errno.h> | 9 #include <errno.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 // immediate death. | 441 // immediate death. |
| 442 CHECK(darwin_major_version >= 6); | 442 CHECK(darwin_major_version >= 6); |
| 443 int mac_os_x_minor_version = darwin_major_version - 4; | 443 int mac_os_x_minor_version = darwin_major_version - 4; |
| 444 DLOG_IF(WARNING, darwin_major_version > 16) << "Assuming Darwin " | 444 DLOG_IF(WARNING, darwin_major_version > 16) << "Assuming Darwin " |
| 445 << base::IntToString(darwin_major_version) << " is Mac OS X 10." | 445 << base::IntToString(darwin_major_version) << " is Mac OS X 10." |
| 446 << base::IntToString(mac_os_x_minor_version); | 446 << base::IntToString(mac_os_x_minor_version); |
| 447 | 447 |
| 448 return mac_os_x_minor_version; | 448 return mac_os_x_minor_version; |
| 449 } | 449 } |
| 450 | 450 |
| 451 // Returns the running system's Mac OS X minor version. This is the |y| value | 451 } // namespace |
| 452 // in 10.y or 10.y.z. | 452 |
| 453 int MacOSXMinorVersion() { | 453 int internal::MacOSXMinorVersion() { |
|
Mark Mentovai
2016/08/25 13:58:56
Can we actually write it this way now? I thought w
Sidney San Martín
2016/08/26 00:00:01
It's fine C++-wise, and I couldn't find anything a
| |
| 454 static int mac_os_x_minor_version = MacOSXMinorVersionInternal(); | 454 static int mac_os_x_minor_version = MacOSXMinorVersionInternal(); |
| 455 return mac_os_x_minor_version; | 455 return mac_os_x_minor_version; |
| 456 } | 456 } |
| 457 | 457 |
| 458 enum { | |
| 459 MAVERICKS_MINOR_VERSION = 9, | |
| 460 YOSEMITE_MINOR_VERSION = 10, | |
| 461 EL_CAPITAN_MINOR_VERSION = 11, | |
| 462 SIERRA_MINOR_VERSION = 12, | |
| 463 }; | |
| 464 | |
| 465 } // namespace | |
| 466 | |
| 467 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_9) | |
| 468 bool IsOSMavericks() { | |
| 469 return MacOSXMinorVersion() == MAVERICKS_MINOR_VERSION; | |
| 470 } | |
| 471 #endif | |
| 472 | |
| 473 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_10) | |
| 474 bool IsOSYosemite() { | |
| 475 return MacOSXMinorVersion() == YOSEMITE_MINOR_VERSION; | |
| 476 } | |
| 477 #endif | |
| 478 | |
| 479 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_10) | |
| 480 bool IsOSYosemiteOrLater() { | |
| 481 return MacOSXMinorVersion() >= YOSEMITE_MINOR_VERSION; | |
| 482 } | |
| 483 #endif | |
| 484 | |
| 485 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_11) | |
| 486 bool IsOSElCapitan() { | |
| 487 return MacOSXMinorVersion() == EL_CAPITAN_MINOR_VERSION; | |
| 488 } | |
| 489 #endif | |
| 490 | |
| 491 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_11) | |
| 492 bool IsOSElCapitanOrLater() { | |
| 493 return MacOSXMinorVersion() >= EL_CAPITAN_MINOR_VERSION; | |
| 494 } | |
| 495 #endif | |
| 496 | |
| 497 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_12) | |
| 498 bool IsOSSierra() { | |
| 499 return MacOSXMinorVersion() == SIERRA_MINOR_VERSION; | |
| 500 } | |
| 501 #endif | |
| 502 | |
| 503 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_12) | |
| 504 bool IsOSSierraOrLater() { | |
| 505 return MacOSXMinorVersion() >= SIERRA_MINOR_VERSION; | |
| 506 } | |
| 507 #endif | |
| 508 | |
| 509 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_12) | |
| 510 bool IsOSLaterThanSierra_DontCallThis() { | |
| 511 return MacOSXMinorVersion() > SIERRA_MINOR_VERSION; | |
| 512 } | |
| 513 #endif | |
| 514 | |
| 515 std::string GetModelIdentifier() { | 458 std::string GetModelIdentifier() { |
| 516 std::string return_string; | 459 std::string return_string; |
| 517 ScopedIOObject<io_service_t> platform_expert( | 460 ScopedIOObject<io_service_t> platform_expert( |
| 518 IOServiceGetMatchingService(kIOMasterPortDefault, | 461 IOServiceGetMatchingService(kIOMasterPortDefault, |
| 519 IOServiceMatching("IOPlatformExpertDevice"))); | 462 IOServiceMatching("IOPlatformExpertDevice"))); |
| 520 if (platform_expert) { | 463 if (platform_expert) { |
| 521 ScopedCFTypeRef<CFDataRef> model_data( | 464 ScopedCFTypeRef<CFDataRef> model_data( |
| 522 static_cast<CFDataRef>(IORegistryEntryCreateCFProperty( | 465 static_cast<CFDataRef>(IORegistryEntryCreateCFProperty( |
| 523 platform_expert, | 466 platform_expert, |
| 524 CFSTR("model"), | 467 CFSTR("model"), |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 550 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp)) | 493 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp)) |
| 551 return false; | 494 return false; |
| 552 *type = ident.substr(0, number_loc); | 495 *type = ident.substr(0, number_loc); |
| 553 *major = major_tmp; | 496 *major = major_tmp; |
| 554 *minor = minor_tmp; | 497 *minor = minor_tmp; |
| 555 return true; | 498 return true; |
| 556 } | 499 } |
| 557 | 500 |
| 558 } // namespace mac | 501 } // namespace mac |
| 559 } // namespace base | 502 } // namespace base |
| OLD | NEW |