Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3527)

Unified Diff: base/idle_timer.cc

Issue 7243: Bring up idletimer unittest on Mac port. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/idle_timer.h ('k') | base/idletimer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « base/idle_timer.h ('k') | base/idletimer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698