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

Unified Diff: base/idle_timer.cc

Issue 2806: This is just an idea for how to implement idle_timer which isn't yet feasible... Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 12 years, 3 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') | no next file » | 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 2086)
+++ base/idle_timer.cc (working copy)
@@ -9,10 +9,59 @@
namespace base {
+#if defined(OS_LINUX)
+struct IdleTimer::XssInfoLazyInstanceTraits {
+ static void New(void* instance) {
+ XssInfo* xss_info = static_cast<XssInfo>(instance);
+ int event_base, error_base;
+ xss_info->have_xss = XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base,
+ &error_base);
+ if (xss_info->have_xss)
+ xss_info->xss_info.Get() = XScreenSaverAllocInfo();
+ }
+ static void Delete(void* instance) {
+ if (xss_info->xss_info.Get()) {
+ XFree(xss_info->xss_info.Get());
+ xss_info->xss_info.~ThreadLocalPointer();
+ }
+ }
+};
+#endif
+
+// static
+bool IdleTimer::DefaultIdleTimeFunction(int32* milliseconds)
+{
+#if defined(OS_WIN)
+ LASTINPUTINFO info;
+ info.cbSize = sizeof(info);
+ if (GetLastInputInfo(&info)) {
+ 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;
+ *milliseconds = interval;
+ return true;
+ }
+ return false;
+#elif defined(OS_LINUX)
+ static LazyInstance<XssInfo, XssInfoLazyInstanceTraits> xss;
+ XssInfo* xss_info = xss.Pointer();
+ if (xss_info->have_xss && xss_info->xss_info.Get()) {
+ XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
+ xss_info->xss_info.Get());
+ *milliseconds = xss_info->xss_info.Get()->idle;
+ return true;
+ }
+ return false;
+#endif
+}
+
IdleTimer::IdleTimer(TimeDelta idle_time, bool repeat)
: idle_interval_(idle_time),
repeat_(repeat),
- get_last_input_info_fn_(GetLastInputInfo) {
+ get_idle_time_fn_(GetLastInputInfo) {
DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()) <<
"Requires a thread that processes Windows UI events";
}
« no previous file with comments | « base/idle_timer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698