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 <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 // May be called on any thread. | 186 // May be called on any thread. |
187 void MessagePumpCFRunLoopBase::ScheduleWork() { | 187 void MessagePumpCFRunLoopBase::ScheduleWork() { |
188 CFRunLoopSourceSignal(work_source_); | 188 CFRunLoopSourceSignal(work_source_); |
189 CFRunLoopWakeUp(run_loop_); | 189 CFRunLoopWakeUp(run_loop_); |
190 } | 190 } |
191 | 191 |
192 // Must be called on the run loop thread. | 192 // Must be called on the run loop thread. |
193 void MessagePumpCFRunLoopBase::ScheduleDelayedWork( | 193 void MessagePumpCFRunLoopBase::ScheduleDelayedWork( |
194 const TimeTicks& delayed_work_time) { | 194 const TimeTicks& delayed_work_time) { |
195 // TODO(jar): We may need a more efficient way to go between these times, but | 195 TimeDelta delta = delayed_work_time - TimeTicks::Now(); |
196 // the difference will change not only when we sleep/wake, it will also change | 196 delayed_work_fire_time_ = CFAbsoluteTimeGetCurrent() + delta.InSecondsF(); |
197 // when the user changes the wall clock time :-/. | |
198 Time absolute_work_time = | |
199 (delayed_work_time - TimeTicks::Now()) + Time::Now(); | |
200 | |
201 Time::Exploded exploded; | |
202 absolute_work_time.UTCExplode(&exploded); | |
203 double seconds = exploded.second + | |
204 (static_cast<double>((absolute_work_time.ToInternalValue()) % | |
205 Time::kMicrosecondsPerSecond) / | |
206 Time::kMicrosecondsPerSecond); | |
207 CFGregorianDate gregorian = { | |
208 exploded.year, | |
209 exploded.month, | |
210 exploded.day_of_month, | |
211 exploded.hour, | |
212 exploded.minute, | |
213 seconds | |
214 }; | |
215 delayed_work_fire_time_ = CFGregorianDateGetAbsoluteTime(gregorian, NULL); | |
216 | |
217 CFRunLoopTimerSetNextFireDate(delayed_work_timer_, delayed_work_fire_time_); | 197 CFRunLoopTimerSetNextFireDate(delayed_work_timer_, delayed_work_fire_time_); |
218 } | 198 } |
219 | 199 |
220 // Called from the run loop. | 200 // Called from the run loop. |
221 // static | 201 // static |
222 void MessagePumpCFRunLoopBase::RunDelayedWorkTimer(CFRunLoopTimerRef timer, | 202 void MessagePumpCFRunLoopBase::RunDelayedWorkTimer(CFRunLoopTimerRef timer, |
223 void* info) { | 203 void* info) { |
224 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); | 204 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); |
225 | 205 |
226 // The timer won't fire again until it's reset. | 206 // The timer won't fire again until it's reset. |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 } | 653 } |
674 | 654 |
675 // static | 655 // static |
676 bool MessagePumpMac::IsHandlingSendEvent() { | 656 bool MessagePumpMac::IsHandlingSendEvent() { |
677 DCHECK([NSApp conformsToProtocol:@protocol(CrAppProtocol)]); | 657 DCHECK([NSApp conformsToProtocol:@protocol(CrAppProtocol)]); |
678 NSObject<CrAppProtocol>* app = static_cast<NSObject<CrAppProtocol>*>(NSApp); | 658 NSObject<CrAppProtocol>* app = static_cast<NSObject<CrAppProtocol>*>(NSApp); |
679 return [app isHandlingSendEvent]; | 659 return [app isHandlingSendEvent]; |
680 } | 660 } |
681 | 661 |
682 } // namespace base | 662 } // namespace base |
OLD | NEW |