| Index: base/idle_timer.cc
|
| ===================================================================
|
| --- base/idle_timer.cc (revision 3254)
|
| +++ base/idle_timer.cc (working copy)
|
| @@ -4,15 +4,48 @@
|
|
|
| #include "base/idle_timer.h"
|
|
|
| +#if defined(OS_MACOSX)
|
| +#include <ApplicationServices/ApplicationServices.h>
|
| +#endif
|
| +
|
| #include "base/message_loop.h"
|
| #include "base/time.h"
|
|
|
| namespace base {
|
|
|
| +#if defined(OS_WIN)
|
| +bool OSIdleTimeSource(int32 *milliseconds_interval_since_last_event) {
|
| + LASTINPUTINFO lastInputInfo;
|
| + lastInputInfo.cbSize = sizeof(lastInputInfo);
|
| + if (GetLastInputInfo(&lastInputInfo) == 0) {
|
| + return false;
|
| + }
|
| + int32 last_input_time = lastInputInfo.dwTime;
|
| +
|
| + // Note: On Windows GetLastInputInfo returns a 32bit value which rolls over
|
| + // ~49days.
|
| + int32 current_time = GetTickCount();
|
| + int32 delta = current_time - last_input_time;
|
| + // delta will go negative if we've been idle for 2GB of ticks.
|
| + if (delta < 0)
|
| + delta = -delta;
|
| + *milliseconds_interval_since_last_event = delta;
|
| + return true;
|
| +}
|
| +#elif defined(OS_MACOSX)
|
| +bool OSIdleTimeSource(int32 *milliseconds_interval_since_last_event) {
|
| + *milliseconds_interval_since_last_event =
|
| + CGEventSourceSecondsSinceLastEventType(
|
| + kCGEventSourceStateCombinedSessionState,
|
| + kCGAnyInputEventType) * 1000.0;
|
| + return true;
|
| +}
|
| +#endif
|
| +
|
| IdleTimer::IdleTimer(TimeDelta idle_time, bool repeat)
|
| : idle_interval_(idle_time),
|
| repeat_(repeat),
|
| - get_last_input_info_fn_(GetLastInputInfo) {
|
| + idle_time_source_(OSIdleTimeSource) {
|
| DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()) <<
|
| "Requires a thread that processes Windows UI events";
|
| }
|
| @@ -48,17 +81,8 @@
|
| }
|
|
|
| TimeDelta IdleTimer::CurrentIdleTime() {
|
| - // TODO(mbelshe): This is windows-specific code.
|
| - LASTINPUTINFO info;
|
| - info.cbSize = sizeof(info);
|
| - if (get_last_input_info_fn_(&info)) {
|
| - // Note: GetLastInputInfo returns a 32bit value which rolls over ~49days.
|
| - int32 last_input_time = info.dwTime;
|
| - int32 current_time = GetTickCount();
|
| - int32 interval = current_time - last_input_time;
|
| - // Interval will go negative if we've been idle for 2GB of ticks.
|
| - if (interval < 0)
|
| - interval = -interval;
|
| + int32 interval = 0;
|
| + if (idle_time_source_(&interval)) {
|
| return TimeDelta::FromMilliseconds(interval);
|
| }
|
| NOTREACHED();
|
|
|