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

Side by Side Diff: base/idle_timer.cc

Issue 8806: Iplement the idle timer for Linux using libxss. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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/base_unittests.scons ('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 #if defined(OS_MACOSX) 7 #if defined(OS_MACOSX)
8 #include <ApplicationServices/ApplicationServices.h> 8 #include <ApplicationServices/ApplicationServices.h>
9 #endif 9 #endif
10 10
11 #if defined(OS_LINUX) && 0
Evan Martin 2008/11/06 20:28:19 Perhaps rather than the 0, just make up a define l
12 // We may not want to port idle_timer to Linux, but we have implemented it
13 // anyway. Remove the 0 above if we want it.
14 #include <gdk/gdkx.h>
15 #include <X11/extensions/scrnsaver.h>
16 #include "base/lazy_instance.h"
17 #include "base/thread_local.h"
18 #endif
19
11 #include "base/message_loop.h" 20 #include "base/message_loop.h"
12 #include "base/time.h" 21 #include "base/time.h"
13 22
14 namespace base { 23 namespace base {
15 24
16 #if defined(OS_WIN) 25 #if defined(OS_WIN)
17 bool OSIdleTimeSource(int32 *milliseconds_interval_since_last_event) { 26 bool OSIdleTimeSource(int32 *milliseconds_interval_since_last_event) {
18 LASTINPUTINFO lastInputInfo; 27 LASTINPUTINFO lastInputInfo;
19 lastInputInfo.cbSize = sizeof(lastInputInfo); 28 lastInputInfo.cbSize = sizeof(lastInputInfo);
20 if (GetLastInputInfo(&lastInputInfo) == 0) { 29 if (GetLastInputInfo(&lastInputInfo) == 0) {
(...skipping 12 matching lines...) Expand all
33 return true; 42 return true;
34 } 43 }
35 #elif defined(OS_MACOSX) 44 #elif defined(OS_MACOSX)
36 bool OSIdleTimeSource(int32 *milliseconds_interval_since_last_event) { 45 bool OSIdleTimeSource(int32 *milliseconds_interval_since_last_event) {
37 *milliseconds_interval_since_last_event = 46 *milliseconds_interval_since_last_event =
38 CGEventSourceSecondsSinceLastEventType( 47 CGEventSourceSecondsSinceLastEventType(
39 kCGEventSourceStateCombinedSessionState, 48 kCGEventSourceStateCombinedSessionState,
40 kCGAnyInputEventType) * 1000.0; 49 kCGAnyInputEventType) * 1000.0;
41 return true; 50 return true;
42 } 51 }
52 #elif defined(OS_LINUX) && 0
53 // We may not want to port idle_timer to Linux, but we have implemented it
54 // anyway. Remove the 0 above if we want it.
55
56 struct IdleState {
57 bool have_screen_saver;
58 ThreadLocalPointer<XScreenSaverInfo*> screen_saver_info;
59 };
60
61 struct IdleStateLazyInstanceTraits {
62 static void New(void* instance) {
Dean McNamee 2008/11/06 08:57:05 This code is not technically correct. You never c
63 IdleState* state = static_cast<IdleState*>(instance);
64 int event_base, error_base;
65 state->have_screen_saver = XScreenSaverQueryExtension(
66 GDK_DISPLAY(), &event_base, &error_base);
67 if (state->have_screen_saver)
68 *state->screen_saver_info.Get() = XScreenSaverAllocInfo();
69 }
70 static void Delete(void* instance) {
71 IdleState* state = static_cast<IdleState*>(instance);
72 if (*state->screen_saver_info.Get()) {
73 XFree(*state->screen_saver_info.Get());
74 state->screen_saver_info.~ThreadLocalPointer();
75 }
76 }
77 };
78
79 bool OSIdleTimeSource(int32* milliseconds_interval_since_last_event) {
80 static LazyInstance<IdleState, IdleStateLazyInstanceTraits> state_instance(
81 base::LINKER_INITIALIZED);
82 IdleState* state = state_instance.Pointer();
83 if (state->have_screen_saver && state->screen_saver_info.Get()) {
84 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
85 *state->screen_saver_info.Get());
86 *milliseconds_interval_since_last_event =
87 (*state->screen_saver_info.Get())->idle;
88 return true;
89 }
90 return false;
91 }
43 #endif 92 #endif
44 93
45 IdleTimer::IdleTimer(TimeDelta idle_time, bool repeat) 94 IdleTimer::IdleTimer(TimeDelta idle_time, bool repeat)
46 : idle_interval_(idle_time), 95 : idle_interval_(idle_time),
47 repeat_(repeat), 96 repeat_(repeat),
48 idle_time_source_(OSIdleTimeSource) { 97 idle_time_source_(OSIdleTimeSource) {
49 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()) << 98 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()) <<
50 "Requires a thread that processes Windows UI events"; 99 "Requires a thread that processes Windows UI events";
51 } 100 }
52 101
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 TimeDelta current_idle_time = CurrentIdleTime(); 143 TimeDelta current_idle_time = CurrentIdleTime();
95 if (current_idle_time > time_since_last_fire) { 144 if (current_idle_time > time_since_last_fire) {
96 if (repeat_) 145 if (repeat_)
97 return idle_interval_ - time_since_last_fire; 146 return idle_interval_ - time_since_last_fire;
98 return idle_interval_; 147 return idle_interval_;
99 } 148 }
100 return idle_interval_ - current_idle_time; 149 return idle_interval_ - current_idle_time;
101 } 150 }
102 151
103 } // namespace base 152 } // namespace base
OLDNEW
« no previous file with comments | « base/base_unittests.scons ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698