summaryrefslogtreecommitdiffstats
path: root/base/idle_timer.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-13 23:03:36 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-13 23:03:36 +0000
commit806ca33bec1bf4d618d5ae6814f297ea027e72da (patch)
treecd1e89acc52d42984711c7410e9b7181cff9f5e6 /base/idle_timer.cc
parent75b537e299ea0c8993d08230719799bba05380e0 (diff)
downloadchromium_src-806ca33bec1bf4d618d5ae6814f297ea027e72da.zip
chromium_src-806ca33bec1bf4d618d5ae6814f297ea027e72da.tar.gz
chromium_src-806ca33bec1bf4d618d5ae6814f297ea027e72da.tar.bz2
Bring up idletimer unittest on Mac port.
Review URL: http://codereview.chromium.org/7243 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3328 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/idle_timer.cc')
-rw-r--r--base/idle_timer.cc48
1 files changed, 36 insertions, 12 deletions
diff --git a/base/idle_timer.cc b/base/idle_timer.cc
index ad29b2c..5d9670d 100644
--- a/base/idle_timer.cc
+++ b/base/idle_timer.cc
@@ -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 @@ void IdleTimer::StartTimer() {
}
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();