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 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 #if !defined(OS_IOS) | 66 #if !defined(OS_IOS) |
67 // Set to true if MessagePumpMac::Create() is called before NSApp is | 67 // Set to true if MessagePumpMac::Create() is called before NSApp is |
68 // initialized. Only accessed from the main thread. | 68 // initialized. Only accessed from the main thread. |
69 bool g_not_using_cr_app = false; | 69 bool g_not_using_cr_app = false; |
70 #endif | 70 #endif |
71 | 71 |
72 // Call through to CFRunLoopTimerSetTolerance(), which is only available on | 72 // Call through to CFRunLoopTimerSetTolerance(), which is only available on |
73 // OS X 10.9. | 73 // OS X 10.9. |
74 void SetTimerTolerance(CFRunLoopTimerRef timer, CFTimeInterval tolerance) { | 74 void SetTimerTolerance(CFRunLoopTimerRef timer, CFTimeInterval tolerance) { |
75 // TODO(jeremy): Temporarily disabled in order to gauge net effect of timer | |
76 // coalescing. | |
77 #if 0 | |
78 typedef void (*CFRunLoopTimerSetTolerancePtr)(CFRunLoopTimerRef timer, | 75 typedef void (*CFRunLoopTimerSetTolerancePtr)(CFRunLoopTimerRef timer, |
79 CFTimeInterval tolerance); | 76 CFTimeInterval tolerance); |
80 | 77 |
81 static CFRunLoopTimerSetTolerancePtr settimertolerance_function_ptr; | 78 static CFRunLoopTimerSetTolerancePtr settimertolerance_function_ptr; |
82 | 79 |
83 static dispatch_once_t get_timer_tolerance_function_ptr_once; | 80 static dispatch_once_t get_timer_tolerance_function_ptr_once; |
84 dispatch_once(&get_timer_tolerance_function_ptr_once, ^{ | 81 dispatch_once(&get_timer_tolerance_function_ptr_once, ^{ |
85 NSBundle* bundle =[NSBundle | 82 NSBundle* bundle =[NSBundle |
86 bundleWithPath:@"/System/Library/Frameworks/CoreFoundation.framework"]; | 83 bundleWithPath:@"/System/Library/Frameworks/CoreFoundation.framework"]; |
87 const char* path = [[bundle executablePath] fileSystemRepresentation]; | 84 const char* path = [[bundle executablePath] fileSystemRepresentation]; |
88 CHECK(path); | 85 CHECK(path); |
89 void* library_handle = dlopen(path, RTLD_LAZY | RTLD_LOCAL); | 86 void* library_handle = dlopen(path, RTLD_LAZY | RTLD_LOCAL); |
90 CHECK(library_handle) << dlerror(); | 87 CHECK(library_handle) << dlerror(); |
91 settimertolerance_function_ptr = | 88 settimertolerance_function_ptr = |
92 reinterpret_cast<CFRunLoopTimerSetTolerancePtr>( | 89 reinterpret_cast<CFRunLoopTimerSetTolerancePtr>( |
93 dlsym(library_handle, "CFRunLoopTimerSetTolerance")); | 90 dlsym(library_handle, "CFRunLoopTimerSetTolerance")); |
94 | 91 |
95 dlclose(library_handle); | 92 dlclose(library_handle); |
96 }); | 93 }); |
97 | 94 |
98 if (settimertolerance_function_ptr) | 95 if (settimertolerance_function_ptr) |
99 settimertolerance_function_ptr(timer, tolerance); | 96 settimertolerance_function_ptr(timer, tolerance); |
100 #endif | |
101 } | 97 } |
102 | 98 |
103 } // namespace | 99 } // namespace |
104 | 100 |
105 // static | 101 // static |
106 const CFStringRef kMessageLoopExclusiveRunLoopMode = | 102 const CFStringRef kMessageLoopExclusiveRunLoopMode = |
107 CFSTR("kMessageLoopExclusiveRunLoopMode"); | 103 CFSTR("kMessageLoopExclusiveRunLoopMode"); |
108 | 104 |
109 // A scoper for autorelease pools created from message pump run loops. | 105 // A scoper for autorelease pools created from message pump run loops. |
110 // Avoids dirtying up the ScopedNSAutoreleasePool interface for the rare | 106 // Avoids dirtying up the ScopedNSAutoreleasePool interface for the rare |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 [NSApplication sharedApplication]; | 768 [NSApplication sharedApplication]; |
773 g_not_using_cr_app = true; | 769 g_not_using_cr_app = true; |
774 return new MessagePumpNSApplication; | 770 return new MessagePumpNSApplication; |
775 #endif | 771 #endif |
776 } | 772 } |
777 | 773 |
778 return new MessagePumpNSRunLoop; | 774 return new MessagePumpNSRunLoop; |
779 } | 775 } |
780 | 776 |
781 } // namespace base | 777 } // namespace base |
OLD | NEW |