Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: base/mac/mac_util.mm

Issue 7144007: Improve and unify Mac OS X run-time version checks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/mac/mac_util.h ('k') | base/mac/mac_util_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <string.h>
9 #include <sys/utsname.h>
8 10
9 #include "base/file_path.h" 11 #include "base/file_path.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/mac/foundation_util.h" 13 #include "base/mac/foundation_util.h"
12 #include "base/mac/scoped_cftyperef.h" 14 #include "base/mac/scoped_cftyperef.h"
13 #include "base/memory/scoped_nsobject.h" 15 #include "base/memory/scoped_nsobject.h"
16 #include "base/string_number_conversions.h"
14 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
15 18
16 namespace base { 19 namespace base {
17 namespace mac { 20 namespace mac {
18 21
19 namespace { 22 namespace {
20 23
21 // The current count of outstanding requests for full screen mode from browser 24 // The current count of outstanding requests for full screen mode from browser
22 // windows, plugins, etc. 25 // windows, plugins, etc.
23 int g_full_screen_requests[kNumFullScreenModes] = { 0, 0, 0}; 26 int g_full_screen_requests[kNumFullScreenModes] = { 0, 0, 0};
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 return false; 459 return false;
457 460
458 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); 461 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp());
459 if (!item.get()) { 462 if (!item.get()) {
460 LOG(ERROR) << "Process launched at Login but can't access Login Item List."; 463 LOG(ERROR) << "Process launched at Login but can't access Login Item List.";
461 return false; 464 return false;
462 } 465 }
463 return IsHiddenLoginItem(item); 466 return IsHiddenLoginItem(item);
464 } 467 }
465 468
469 namespace {
470
471 // Returns the running system's Darwin major version. Don't call this, it's
472 // an implementation detail and its result is meant to be cached by
473 // MacOSXMinorVersion.
474 int DarwinMajorVersionInternal() {
475 // base::OperatingSystemVersionNumbers calls Gestalt, which is a
476 // higher-level operation than is needed. It might perform unnecessary
477 // operations. On 10.6, it was observed to be able to spawn threads (see
478 // http://crbug.com/53200). It might also read files or perform other
479 // blocking operations. Actually, nobody really knows for sure just what
480 // Gestalt might do, or what it might be taught to do in the future.
481 //
482 // uname, on the other hand, is implemented as a simple series of sysctl
483 // system calls to obtain the relevant data from the kernel. The data is
484 // compiled right into the kernel, so no threads or blocking or other
485 // funny business is necessary.
486
487 struct utsname uname_info;
488 if (uname(&uname_info) != 0) {
489 PLOG(ERROR) << "uname";
490 return 0;
491 }
492
493 if (strcmp(uname_info.sysname, "Darwin") != 0) {
494 LOG(ERROR) << "unexpected uname sysname " << uname_info.sysname;
495 return 0;
496 }
497
498 int darwin_major_version = 0;
499 char* dot = strchr(uname_info.release, '.');
500 if (dot) {
501 if (!base::StringToInt(uname_info.release, dot, &darwin_major_version)) {
502 dot = NULL;
503 }
504 }
505
506 if (!dot) {
507 LOG(ERROR) << "could not parse uname release " << uname_info.release;
508 return 0;
509 }
510
511 return darwin_major_version;
512 }
513
514 // Returns the running system's Mac OS X minor version. This is the |y| value
515 // in 10.y or 10.y.z. Don't call this, it's an implementation detail and the
516 // result is meant to be cached by MacOSXMinorVersion.
517 int MacOSXMinorVersionInternal() {
518 int darwin_major_version = DarwinMajorVersionInternal();
519
520 // The Darwin major version is always 4 greater than the Mac OS X minor
521 // version for Darwin versions beginning with 6, corresponding to Mac OS X
522 // 10.2. Since this correspondence may change in the future, warn when
523 // encountering a version higher than anything seen before. Older Darwin
524 // versions, or versions that can't be determined, result in
525 // immediate death.
526 CHECK(darwin_major_version >= 6);
527 int mac_os_x_minor_version = darwin_major_version - 4;
528 LOG_IF(WARNING, darwin_major_version > 11) << "Assuming Darwin "
529 << base::IntToString(darwin_major_version) << " is Mac OS X 10."
530 << base::IntToString(mac_os_x_minor_version);
531
532 return mac_os_x_minor_version;
533 }
534
535 // Returns the running system's Mac OS X minor version. This is the |y| value
536 // in 10.y or 10.y.z.
537 int MacOSXMinorVersion() {
538 static int mac_os_x_minor_version = MacOSXMinorVersionInternal();
539 return mac_os_x_minor_version;
540 }
541
542 enum {
543 LEOPARD_MINOR_VERSION = 5,
544 SNOW_LEOPARD_MINOR_VERSION = 6,
545 LION_MINOR_VERSION = 7
546 };
547
548 } // namespace
549
550 bool IsOSLeopard() {
551 return MacOSXMinorVersion() == LEOPARD_MINOR_VERSION;
552 }
553
554 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_6)
555 bool IsOSLeopardOrEarlier() {
556 return MacOSXMinorVersion() <= LEOPARD_MINOR_VERSION;
557 }
558 #endif
559
560 bool IsOSSnowLeopard() {
561 return MacOSXMinorVersion() == SNOW_LEOPARD_MINOR_VERSION;
562 }
563
564 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_7)
565 bool IsOSSnowLeopardOrEarlier() {
566 return MacOSXMinorVersion() <= SNOW_LEOPARD_MINOR_VERSION;
567 }
568 #endif
569
570 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_6)
571 bool IsOSSnowLeopardOrLater() {
572 return MacOSXMinorVersion() >= SNOW_LEOPARD_MINOR_VERSION;
573 }
574 #endif
575
576 bool IsOSLion() {
577 return MacOSXMinorVersion() == LION_MINOR_VERSION;
578 }
579
580 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_7)
581 bool IsOSLionOrLater() {
582 return MacOSXMinorVersion() >= LION_MINOR_VERSION;
583 }
584 #endif
585
586 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7)
587 bool IsOSLaterThanLion() {
588 return MacOSXMinorVersion() > LION_MINOR_VERSION;
589 }
590 #endif
591
466 } // namespace mac 592 } // namespace mac
467 } // namespace base 593 } // namespace base
OLDNEW
« no previous file with comments | « base/mac/mac_util.h ('k') | base/mac/mac_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698