OLD | NEW |
---|---|
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" |
14 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
17 #include "base/string_number_conversions.h" | |
Avi (use Gerrit)
2011/06/13 22:45:22
alphabetize
Mark Mentovai
2011/06/14 00:18:26
Avi wrote:
| |
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}; |
24 | 27 |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 (!uname_info.sysname || 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. Don't call this, it's an implementation detail and the result is | |
516 // 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 DLOG_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. | |
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 bool IsOSLeopardOrEarlier() { | |
555 return MacOSXMinorVersion() <= LEOPARD_MINOR_VERSION; | |
556 } | |
557 | |
558 bool IsOSSnowLeopard() { | |
559 return MacOSXMinorVersion() == SNOW_LEOPARD_MINOR_VERSION; | |
560 } | |
561 | |
562 bool IsOSSnowLeopardOrEarlier() { | |
563 return MacOSXMinorVersion() <= SNOW_LEOPARD_MINOR_VERSION; | |
564 } | |
565 | |
566 bool IsOSSnowLeopardOrLater() { | |
567 return MacOSXMinorVersion() >= SNOW_LEOPARD_MINOR_VERSION; | |
568 } | |
569 | |
570 bool IsOSLion() { | |
571 return MacOSXMinorVersion() == LION_MINOR_VERSION; | |
572 } | |
573 | |
574 bool IsOSLionOrLater() { | |
575 return MacOSXMinorVersion() >= LION_MINOR_VERSION; | |
576 } | |
577 | |
578 bool IsOSLaterThanLion() { | |
579 return MacOSXMinorVersion() > LION_MINOR_VERSION; | |
580 } | |
581 | |
466 } // namespace mac | 582 } // namespace mac |
467 } // namespace base | 583 } // namespace base |
OLD | NEW |