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 #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, kMessageLoopExclusiveRunLoopMode, | |
|
Mark Mentovai
2017/05/10 14:00:18
I guess I’m not supposed to complain if clang-form
Robert Sesek
2017/05/10 14:02:49
I complain all the time about this because clang-f
tapted
2017/05/11 00:24:06
I added a comment,
// Mode that only sees Chrome
Robert Sesek
2017/05/11 16:12:36
I was wondering the same thing. The Exclusive mode
| |
| 36 | |
| 37 // Process work when NSMenus are fading out. | |
| 38 CFSTR("com.apple.hitoolbox.windows.windowfadingmode"), | |
| 39 | |
| 40 // Process work when AppKit is highlighting an item on the main menubar. | |
| 41 CFSTR("NSUnhighlightMenuRunLoopMode"), | |
| 42 }; | |
| 43 | |
| 28 void CFRunLoopAddSourceToAllModes(CFRunLoopRef rl, CFRunLoopSourceRef source) { | 44 void CFRunLoopAddSourceToAllModes(CFRunLoopRef rl, CFRunLoopSourceRef source) { |
|
Robert Sesek
2017/05/10 13:37:27
One last thought: it would be nice if we could lim
tapted
2017/05/11 00:24:05
We could pass a std::vector of scoped_cftyperef<CF
Robert Sesek
2017/05/11 16:12:36
I don't think it's critical since the mode should
| |
| 29 CFRunLoopAddSource(rl, source, kCFRunLoopCommonModes); | 45 for (const CFStringRef& mode : kAllModes) |
| 30 CFRunLoopAddSource(rl, source, kMessageLoopExclusiveRunLoopMode); | 46 CFRunLoopAddSource(rl, source, mode); |
| 31 } | 47 } |
| 32 | 48 |
| 33 void CFRunLoopRemoveSourceFromAllModes(CFRunLoopRef rl, | 49 void CFRunLoopRemoveSourceFromAllModes(CFRunLoopRef rl, |
| 34 CFRunLoopSourceRef source) { | 50 CFRunLoopSourceRef source) { |
| 35 CFRunLoopRemoveSource(rl, source, kCFRunLoopCommonModes); | 51 for (const CFStringRef& mode : kAllModes) |
| 36 CFRunLoopRemoveSource(rl, source, kMessageLoopExclusiveRunLoopMode); | 52 CFRunLoopRemoveSource(rl, source, mode); |
| 37 } | 53 } |
| 38 | 54 |
| 39 void CFRunLoopAddTimerToAllModes(CFRunLoopRef rl, CFRunLoopTimerRef timer) { | 55 void CFRunLoopAddTimerToAllModes(CFRunLoopRef rl, CFRunLoopTimerRef timer) { |
| 40 CFRunLoopAddTimer(rl, timer, kCFRunLoopCommonModes); | 56 for (const CFStringRef& mode : kAllModes) |
| 41 CFRunLoopAddTimer(rl, timer, kMessageLoopExclusiveRunLoopMode); | 57 CFRunLoopAddTimer(rl, timer, mode); |
| 42 } | 58 } |
| 43 | 59 |
| 44 void CFRunLoopRemoveTimerFromAllModes(CFRunLoopRef rl, | 60 void CFRunLoopRemoveTimerFromAllModes(CFRunLoopRef rl, |
| 45 CFRunLoopTimerRef timer) { | 61 CFRunLoopTimerRef timer) { |
| 46 CFRunLoopRemoveTimer(rl, timer, kCFRunLoopCommonModes); | 62 for (const CFStringRef& mode : kAllModes) |
| 47 CFRunLoopRemoveTimer(rl, timer, kMessageLoopExclusiveRunLoopMode); | 63 CFRunLoopRemoveTimer(rl, timer, mode); |
| 48 } | 64 } |
| 49 | 65 |
| 50 void CFRunLoopAddObserverToAllModes(CFRunLoopRef rl, | 66 void CFRunLoopAddObserverToAllModes(CFRunLoopRef rl, |
| 51 CFRunLoopObserverRef observer) { | 67 CFRunLoopObserverRef observer) { |
| 52 CFRunLoopAddObserver(rl, observer, kCFRunLoopCommonModes); | 68 for (const CFStringRef& mode : kAllModes) |
| 53 CFRunLoopAddObserver(rl, observer, kMessageLoopExclusiveRunLoopMode); | 69 CFRunLoopAddObserver(rl, observer, mode); |
| 54 } | 70 } |
| 55 | 71 |
| 56 void CFRunLoopRemoveObserverFromAllModes(CFRunLoopRef rl, | 72 void CFRunLoopRemoveObserverFromAllModes(CFRunLoopRef rl, |
| 57 CFRunLoopObserverRef observer) { | 73 CFRunLoopObserverRef observer) { |
| 58 CFRunLoopRemoveObserver(rl, observer, kCFRunLoopCommonModes); | 74 for (const CFStringRef& mode : kAllModes) |
| 59 CFRunLoopRemoveObserver(rl, observer, kMessageLoopExclusiveRunLoopMode); | 75 CFRunLoopRemoveObserver(rl, observer, mode); |
| 60 } | 76 } |
| 61 | 77 |
| 62 void NoOp(void* info) { | 78 void NoOp(void* info) { |
| 63 } | 79 } |
| 64 | 80 |
| 65 const CFTimeInterval kCFTimeIntervalMax = | 81 const CFTimeInterval kCFTimeIntervalMax = |
| 66 std::numeric_limits<CFTimeInterval>::max(); | 82 std::numeric_limits<CFTimeInterval>::max(); |
| 67 | 83 |
| 68 #if !defined(OS_IOS) | 84 #if !defined(OS_IOS) |
| 69 // Set to true if MessagePumpMac::Create() is called before NSApp is | 85 // 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]; | 890 [NSApplication sharedApplication]; |
| 875 g_not_using_cr_app = true; | 891 g_not_using_cr_app = true; |
| 876 return new MessagePumpNSApplication; | 892 return new MessagePumpNSApplication; |
| 877 #endif | 893 #endif |
| 878 } | 894 } |
| 879 | 895 |
| 880 return new MessagePumpNSRunLoop; | 896 return new MessagePumpNSRunLoop; |
| 881 } | 897 } |
| 882 | 898 |
| 883 } // namespace base | 899 } // namespace base |
| OLD | NEW |