| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 #include "base/message_pump_mac.h" | 5 #include "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 #include <IOKit/IOMessage.h> | 9 #include <IOKit/IOMessage.h> |
| 10 #include <IOKit/pwr_mgt/IOPMLib.h> | 10 #include <IOKit/pwr_mgt/IOPMLib.h> |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 218 } |
| 219 | 219 |
| 220 // May be called on any thread. | 220 // May be called on any thread. |
| 221 void MessagePumpCFRunLoopBase::ScheduleWork() { | 221 void MessagePumpCFRunLoopBase::ScheduleWork() { |
| 222 CFRunLoopSourceSignal(work_source_); | 222 CFRunLoopSourceSignal(work_source_); |
| 223 CFRunLoopWakeUp(run_loop_); | 223 CFRunLoopWakeUp(run_loop_); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Must be called on the run loop thread. | 226 // Must be called on the run loop thread. |
| 227 void MessagePumpCFRunLoopBase::ScheduleDelayedWork( | 227 void MessagePumpCFRunLoopBase::ScheduleDelayedWork( |
| 228 const Time& delayed_work_time) { | 228 const TimeTicks& delayed_work_time) { |
| 229 // TODO(jar): We may need a more efficient way to go between these times, but |
| 230 // the difference will change not only when we sleep/wake, it will also change |
| 231 // when the user changes the wall clock time :-/. |
| 232 Time absolute_work_time = |
| 233 (delayed_work_time - TimeTicks::Now()) + Time::Now(); |
| 234 |
| 229 Time::Exploded exploded; | 235 Time::Exploded exploded; |
| 230 delayed_work_time.UTCExplode(&exploded); | 236 absolute_work_time.UTCExplode(&exploded); |
| 231 double seconds = exploded.second + | 237 double seconds = exploded.second + |
| 232 (static_cast<double>((delayed_work_time.ToInternalValue()) % | 238 (static_cast<double>((absolute_work_time.ToInternalValue()) % |
| 233 Time::kMicrosecondsPerSecond) / | 239 Time::kMicrosecondsPerSecond) / |
| 234 Time::kMicrosecondsPerSecond); | 240 Time::kMicrosecondsPerSecond); |
| 235 CFGregorianDate gregorian = { | 241 CFGregorianDate gregorian = { |
| 236 exploded.year, | 242 exploded.year, |
| 237 exploded.month, | 243 exploded.month, |
| 238 exploded.day_of_month, | 244 exploded.day_of_month, |
| 239 exploded.hour, | 245 exploded.hour, |
| 240 exploded.minute, | 246 exploded.minute, |
| 241 seconds | 247 seconds |
| 242 }; | 248 }; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 return false; | 319 return false; |
| 314 } | 320 } |
| 315 | 321 |
| 316 // The NSApplication-based run loop only drains the autorelease pool at each | 322 // The NSApplication-based run loop only drains the autorelease pool at each |
| 317 // UI event (NSEvent). The autorelease pool is not drained for each | 323 // UI event (NSEvent). The autorelease pool is not drained for each |
| 318 // CFRunLoopSource target that's run. Use a local pool for any autoreleased | 324 // CFRunLoopSource target that's run. Use a local pool for any autoreleased |
| 319 // objects if the app is not currently handling a UI event to ensure they're | 325 // objects if the app is not currently handling a UI event to ensure they're |
| 320 // released promptly even in the absence of UI events. | 326 // released promptly even in the absence of UI events. |
| 321 MessagePumpScopedAutoreleasePool autorelease_pool(this); | 327 MessagePumpScopedAutoreleasePool autorelease_pool(this); |
| 322 | 328 |
| 323 Time next_time; | 329 TimeTicks next_time; |
| 324 delegate_->DoDelayedWork(&next_time); | 330 delegate_->DoDelayedWork(&next_time); |
| 325 | 331 |
| 326 bool more_work = !next_time.is_null(); | 332 bool more_work = !next_time.is_null(); |
| 327 if (more_work) { | 333 if (more_work) { |
| 328 TimeDelta delay = next_time - Time::Now(); | 334 TimeDelta delay = next_time - TimeTicks::Now(); |
| 329 if (delay > TimeDelta()) { | 335 if (delay > TimeDelta()) { |
| 330 // There's more delayed work to be done in the future. | 336 // There's more delayed work to be done in the future. |
| 331 ScheduleDelayedWork(next_time); | 337 ScheduleDelayedWork(next_time); |
| 332 } else { | 338 } else { |
| 333 // There's more delayed work to be done, and its time is in the past. | 339 // There's more delayed work to be done, and its time is in the past. |
| 334 // Arrange to come back here directly as long as the loop is still | 340 // Arrange to come back here directly as long as the loop is still |
| 335 // running. | 341 // running. |
| 336 CFRunLoopSourceSignal(delayed_work_source_); | 342 CFRunLoopSourceSignal(delayed_work_source_); |
| 337 } | 343 } |
| 338 } | 344 } |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 // static | 763 // static |
| 758 MessagePump* MessagePumpMac::Create() { | 764 MessagePump* MessagePumpMac::Create() { |
| 759 if ([NSThread isMainThread]) { | 765 if ([NSThread isMainThread]) { |
| 760 return new MessagePumpNSApplication; | 766 return new MessagePumpNSApplication; |
| 761 } | 767 } |
| 762 | 768 |
| 763 return new MessagePumpNSRunLoop; | 769 return new MessagePumpNSRunLoop; |
| 764 } | 770 } |
| 765 | 771 |
| 766 } // namespace base | 772 } // namespace base |
| OLD | NEW |