| 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_loop/message_pump_mac.h" | 5 #import "base/message_loop/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/mac/call_with_eh_frame.h" | 12 #include "base/mac/call_with_eh_frame.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/timer_slack.h" | 15 #include "base/message_loop/timer_slack.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 | 19 |
| 20 #if !defined(OS_IOS) | 20 #if !defined(OS_IOS) |
| 21 #import <AppKit/AppKit.h> | 21 #import <AppKit/AppKit.h> |
| 22 #endif // !defined(OS_IOS) | 22 #endif // !defined(OS_IOS) |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // AppKit RunLoop modes observed to potentially run tasks posted to Chrome's |
| 29 // main thread task runner. Some are internal to AppKit but must be observed to |
| 30 // keep Chrome's UI responsive. Others that may be interesting, but are not |
| 31 // watched: |
| 32 // - com.apple.hitoolbox.windows.transitionmode |
| 33 // - com.apple.hitoolbox.windows.flushmode |
| 34 const CFStringRef kAllModes[] = { |
| 35 kCFRunLoopCommonModes, |
| 36 |
| 37 // Mode that only sees Chrome work sources. |
| 38 kMessageLoopExclusiveRunLoopMode, |
| 39 |
| 40 // Process work when NSMenus are fading out. |
| 41 CFSTR("com.apple.hitoolbox.windows.windowfadingmode"), |
| 42 |
| 43 // Process work when AppKit is highlighting an item on the main menubar. |
| 44 CFSTR("NSUnhighlightMenuRunLoopMode"), |
| 45 }; |
| 46 |
| 28 void CFRunLoopAddSourceToAllModes(CFRunLoopRef rl, CFRunLoopSourceRef source) { | 47 void CFRunLoopAddSourceToAllModes(CFRunLoopRef rl, CFRunLoopSourceRef source) { |
| 29 CFRunLoopAddSource(rl, source, kCFRunLoopCommonModes); | 48 for (const CFStringRef& mode : kAllModes) |
| 30 CFRunLoopAddSource(rl, source, kMessageLoopExclusiveRunLoopMode); | 49 CFRunLoopAddSource(rl, source, mode); |
| 31 } | 50 } |
| 32 | 51 |
| 33 void CFRunLoopRemoveSourceFromAllModes(CFRunLoopRef rl, | 52 void CFRunLoopRemoveSourceFromAllModes(CFRunLoopRef rl, |
| 34 CFRunLoopSourceRef source) { | 53 CFRunLoopSourceRef source) { |
| 35 CFRunLoopRemoveSource(rl, source, kCFRunLoopCommonModes); | 54 for (const CFStringRef& mode : kAllModes) |
| 36 CFRunLoopRemoveSource(rl, source, kMessageLoopExclusiveRunLoopMode); | 55 CFRunLoopRemoveSource(rl, source, mode); |
| 37 } | 56 } |
| 38 | 57 |
| 39 void CFRunLoopAddTimerToAllModes(CFRunLoopRef rl, CFRunLoopTimerRef timer) { | 58 void CFRunLoopAddTimerToAllModes(CFRunLoopRef rl, CFRunLoopTimerRef timer) { |
| 40 CFRunLoopAddTimer(rl, timer, kCFRunLoopCommonModes); | 59 for (const CFStringRef& mode : kAllModes) |
| 41 CFRunLoopAddTimer(rl, timer, kMessageLoopExclusiveRunLoopMode); | 60 CFRunLoopAddTimer(rl, timer, mode); |
| 42 } | 61 } |
| 43 | 62 |
| 44 void CFRunLoopRemoveTimerFromAllModes(CFRunLoopRef rl, | 63 void CFRunLoopRemoveTimerFromAllModes(CFRunLoopRef rl, |
| 45 CFRunLoopTimerRef timer) { | 64 CFRunLoopTimerRef timer) { |
| 46 CFRunLoopRemoveTimer(rl, timer, kCFRunLoopCommonModes); | 65 for (const CFStringRef& mode : kAllModes) |
| 47 CFRunLoopRemoveTimer(rl, timer, kMessageLoopExclusiveRunLoopMode); | 66 CFRunLoopRemoveTimer(rl, timer, mode); |
| 48 } | 67 } |
| 49 | 68 |
| 50 void CFRunLoopAddObserverToAllModes(CFRunLoopRef rl, | 69 void CFRunLoopAddObserverToAllModes(CFRunLoopRef rl, |
| 51 CFRunLoopObserverRef observer) { | 70 CFRunLoopObserverRef observer) { |
| 52 CFRunLoopAddObserver(rl, observer, kCFRunLoopCommonModes); | 71 for (const CFStringRef& mode : kAllModes) |
| 53 CFRunLoopAddObserver(rl, observer, kMessageLoopExclusiveRunLoopMode); | 72 CFRunLoopAddObserver(rl, observer, mode); |
| 54 } | 73 } |
| 55 | 74 |
| 56 void CFRunLoopRemoveObserverFromAllModes(CFRunLoopRef rl, | 75 void CFRunLoopRemoveObserverFromAllModes(CFRunLoopRef rl, |
| 57 CFRunLoopObserverRef observer) { | 76 CFRunLoopObserverRef observer) { |
| 58 CFRunLoopRemoveObserver(rl, observer, kCFRunLoopCommonModes); | 77 for (const CFStringRef& mode : kAllModes) |
| 59 CFRunLoopRemoveObserver(rl, observer, kMessageLoopExclusiveRunLoopMode); | 78 CFRunLoopRemoveObserver(rl, observer, mode); |
| 60 } | 79 } |
| 61 | 80 |
| 62 void NoOp(void* info) { | 81 void NoOp(void* info) { |
| 63 } | 82 } |
| 64 | 83 |
| 65 const CFTimeInterval kCFTimeIntervalMax = | 84 const CFTimeInterval kCFTimeIntervalMax = |
| 66 std::numeric_limits<CFTimeInterval>::max(); | 85 std::numeric_limits<CFTimeInterval>::max(); |
| 67 | 86 |
| 68 #if !defined(OS_IOS) | 87 #if !defined(OS_IOS) |
| 69 // Set to true if MessagePumpMac::Create() is called before NSApp is | 88 // Set to true if MessagePumpMac::Create() is called before NSApp is |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 [NSApplication sharedApplication]; | 893 [NSApplication sharedApplication]; |
| 875 g_not_using_cr_app = true; | 894 g_not_using_cr_app = true; |
| 876 return new MessagePumpNSApplication; | 895 return new MessagePumpNSApplication; |
| 877 #endif | 896 #endif |
| 878 } | 897 } |
| 879 | 898 |
| 880 return new MessagePumpNSRunLoop; | 899 return new MessagePumpNSRunLoop; |
| 881 } | 900 } |
| 882 | 901 |
| 883 } // namespace base | 902 } // namespace base |
| OLD | NEW |