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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/idle_timer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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/idle_timer.h" 5 #include "base/idle_timer.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 9
10 namespace base { 10 namespace base {
11 11
12 #if defined(OS_LINUX)
13 struct IdleTimer::XssInfoLazyInstanceTraits {
14 static void New(void* instance) {
15 XssInfo* xss_info = static_cast<XssInfo>(instance);
16 int event_base, error_base;
17 xss_info->have_xss = XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base,
18 &error_base);
19 if (xss_info->have_xss)
20 xss_info->xss_info.Get() = XScreenSaverAllocInfo();
21 }
22 static void Delete(void* instance) {
23 if (xss_info->xss_info.Get()) {
24 XFree(xss_info->xss_info.Get());
25 xss_info->xss_info.~ThreadLocalPointer();
26 }
27 }
28 };
29 #endif
30
31 // static
32 bool IdleTimer::DefaultIdleTimeFunction(int32* milliseconds)
33 {
34 #if defined(OS_WIN)
35 LASTINPUTINFO info;
36 info.cbSize = sizeof(info);
37 if (GetLastInputInfo(&info)) {
38 int32 last_input_time = info.dwTime;
39 int32 current_time = GetTickCount();
40 int32 interval = current_time - last_input_time;
41 // Interval will go negative if we've been idle for 2GB of ticks.
42 if (interval < 0)
43 interval = -interval;
44 *milliseconds = interval;
45 return true;
46 }
47 return false;
48 #elif defined(OS_LINUX)
49 static LazyInstance<XssInfo, XssInfoLazyInstanceTraits> xss;
50 XssInfo* xss_info = xss.Pointer();
51 if (xss_info->have_xss && xss_info->xss_info.Get()) {
52 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
53 xss_info->xss_info.Get());
54 *milliseconds = xss_info->xss_info.Get()->idle;
55 return true;
56 }
57 return false;
58 #endif
59 }
60
12 IdleTimer::IdleTimer(TimeDelta idle_time, bool repeat) 61 IdleTimer::IdleTimer(TimeDelta idle_time, bool repeat)
13 : idle_interval_(idle_time), 62 : idle_interval_(idle_time),
14 repeat_(repeat), 63 repeat_(repeat),
15 get_last_input_info_fn_(GetLastInputInfo) { 64 get_idle_time_fn_(GetLastInputInfo) {
16 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()) << 65 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()) <<
17 "Requires a thread that processes Windows UI events"; 66 "Requires a thread that processes Windows UI events";
18 } 67 }
19 68
20 IdleTimer::~IdleTimer() { 69 IdleTimer::~IdleTimer() {
21 Stop(); 70 Stop();
22 } 71 }
23 72
24 void IdleTimer::Start() { 73 void IdleTimer::Start() {
25 StartTimer(); 74 StartTimer();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 TimeDelta current_idle_time = CurrentIdleTime(); 119 TimeDelta current_idle_time = CurrentIdleTime();
71 if (current_idle_time > time_since_last_fire) { 120 if (current_idle_time > time_since_last_fire) {
72 if (repeat_) 121 if (repeat_)
73 return idle_interval_ - time_since_last_fire; 122 return idle_interval_ - time_since_last_fire;
74 return idle_interval_; 123 return idle_interval_;
75 } 124 }
76 return idle_interval_ - current_idle_time; 125 return idle_interval_ - current_idle_time;
77 } 126 }
78 127
79 } // namespace base 128 } // namespace base
OLDNEW
« 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