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 #import "base/message_pump_mac.h" | 5 #import "base/message_pump_mac.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 | 14 |
15 #if !defined(OS_IOS) | 15 #if !defined(OS_IOS) |
16 #import <AppKit/AppKit.h> | 16 #import <AppKit/AppKit.h> |
17 #endif // !defined(OS_IOS) | 17 #endif // !defined(OS_IOS) |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 void NoOp(void* info) { | 21 void NoOp(void* info) { |
22 } | 22 } |
23 | 23 |
24 const CFTimeInterval kCFTimeIntervalMax = | 24 const CFTimeInterval kCFTimeIntervalMax = |
25 std::numeric_limits<CFTimeInterval>::max(); | 25 std::numeric_limits<CFTimeInterval>::max(); |
26 | 26 |
27 #if !defined(OS_IOS) | |
27 // Set to true if MessagePumpMac::Create() is called before NSApp is | 28 // Set to true if MessagePumpMac::Create() is called before NSApp is |
28 // initialized. Only accessed from the main thread. | 29 // initialized. Only accessed from the main thread. |
29 bool not_using_crapp = false; | 30 bool g_not_using_cr_app = false; |
Robert Sesek
2013/01/08 18:24:55
I think we deliberately like this as crapp ;).
In
justincohen
2013/01/08 18:27:25
crapp: Heh, I do as I'm told!
The newer clang com
| |
31 #endif | |
30 | 32 |
31 } // namespace | 33 } // namespace |
32 | 34 |
33 namespace base { | 35 namespace base { |
34 | 36 |
35 // A scoper for autorelease pools created from message pump run loops. | 37 // A scoper for autorelease pools created from message pump run loops. |
36 // Avoids dirtying up the ScopedNSAutoreleasePool interface for the rare | 38 // Avoids dirtying up the ScopedNSAutoreleasePool interface for the rare |
37 // case where an autorelease pool needs to be passed in. | 39 // case where an autorelease pool needs to be passed in. |
38 class MessagePumpScopedAutoreleasePool { | 40 class MessagePumpScopedAutoreleasePool { |
39 public: | 41 public: |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 | 655 |
654 // static | 656 // static |
655 bool MessagePumpMac::UsingCrApp() { | 657 bool MessagePumpMac::UsingCrApp() { |
656 DCHECK([NSThread isMainThread]); | 658 DCHECK([NSThread isMainThread]); |
657 | 659 |
658 // If NSApp is still not initialized, then the subclass used cannot | 660 // If NSApp is still not initialized, then the subclass used cannot |
659 // be determined. | 661 // be determined. |
660 DCHECK(NSApp); | 662 DCHECK(NSApp); |
661 | 663 |
662 // The pump was created using MessagePumpNSApplication. | 664 // The pump was created using MessagePumpNSApplication. |
663 if (not_using_crapp) | 665 if (g_not_using_cr_app) |
664 return false; | 666 return false; |
665 | 667 |
666 return [NSApp conformsToProtocol:@protocol(CrAppProtocol)]; | 668 return [NSApp conformsToProtocol:@protocol(CrAppProtocol)]; |
667 } | 669 } |
668 | 670 |
669 // static | 671 // static |
670 bool MessagePumpMac::IsHandlingSendEvent() { | 672 bool MessagePumpMac::IsHandlingSendEvent() { |
671 DCHECK([NSApp conformsToProtocol:@protocol(CrAppProtocol)]); | 673 DCHECK([NSApp conformsToProtocol:@protocol(CrAppProtocol)]); |
672 NSObject<CrAppProtocol>* app = static_cast<NSObject<CrAppProtocol>*>(NSApp); | 674 NSObject<CrAppProtocol>* app = static_cast<NSObject<CrAppProtocol>*>(NSApp); |
673 return [app isHandlingSendEvent]; | 675 return [app isHandlingSendEvent]; |
674 } | 676 } |
675 #endif // !defined(OS_IOS) | 677 #endif // !defined(OS_IOS) |
676 | 678 |
677 // static | 679 // static |
678 MessagePump* MessagePumpMac::Create() { | 680 MessagePump* MessagePumpMac::Create() { |
679 if ([NSThread isMainThread]) { | 681 if ([NSThread isMainThread]) { |
680 #if defined(OS_IOS) | 682 #if defined(OS_IOS) |
681 return new MessagePumpUIApplication; | 683 return new MessagePumpUIApplication; |
682 #else | 684 #else |
683 if ([NSApp conformsToProtocol:@protocol(CrAppProtocol)]) | 685 if ([NSApp conformsToProtocol:@protocol(CrAppProtocol)]) |
684 return new MessagePumpCrApplication; | 686 return new MessagePumpCrApplication; |
685 | 687 |
686 // The main-thread MessagePump implementations REQUIRE an NSApp. | 688 // The main-thread MessagePump implementations REQUIRE an NSApp. |
687 // Executables which have specific requirements for their | 689 // Executables which have specific requirements for their |
688 // NSApplication subclass should initialize appropriately before | 690 // NSApplication subclass should initialize appropriately before |
689 // creating an event loop. | 691 // creating an event loop. |
690 [NSApplication sharedApplication]; | 692 [NSApplication sharedApplication]; |
691 not_using_crapp = true; | 693 g_not_using_cr_app = true; |
692 return new MessagePumpNSApplication; | 694 return new MessagePumpNSApplication; |
693 #endif | 695 #endif |
694 } | 696 } |
695 | 697 |
696 return new MessagePumpNSRunLoop; | 698 return new MessagePumpNSRunLoop; |
697 } | 699 } |
698 | 700 |
699 } // namespace base | 701 } // namespace base |
OLD | NEW |