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

Side by Side Diff: base/idle_timer.cc

Issue 10610: Remove an unnecessary pointer layer in idle timer. (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 | « no previous file | 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 // We may not want to port idle_timer to Linux, but we have implemented it 7 // We may not want to port idle_timer to Linux, but we have implemented it
8 // anyway. Define this to 1 to enable the Linux idle timer and then add the 8 // anyway. Define this to 1 to enable the Linux idle timer and then add the
9 // libs that need to be linked (Xss). 9 // libs that need to be linked (Xss).
10 #define ENABLE_XSS_SUPPORT 0 10 #define ENABLE_XSS_SUPPORT 0
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return true; 55 return true;
56 } 56 }
57 #elif defined(OS_LINUX) && ENABLE_XSS_SUPPORT 57 #elif defined(OS_LINUX) && ENABLE_XSS_SUPPORT
58 class IdleState { 58 class IdleState {
59 public: 59 public:
60 IdleState() { 60 IdleState() {
61 int event_base, error_base; 61 int event_base, error_base;
62 have_idle_info_ = XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, 62 have_idle_info_ = XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base,
63 &error_base); 63 &error_base);
64 if (have_idle_info_) 64 if (have_idle_info_)
65 *idle_info_.Get() = XScreenSaverAllocInfo(); 65 idle_info_.Set(XScreenSaverAllocInfo());
66 } 66 }
67 67
68 ~IdleState() { 68 ~IdleState() {
69 if (*idle_info_.Get()) { 69 if (idle_info_.Get()) {
70 XFree(*idle_info_.Get()); 70 XFree(idle_info_.Get());
71 idle_info_.~ThreadLocalPointer(); 71 idle_info_.~ThreadLocalPointer();
72 } 72 }
73 } 73 }
74 74
75 int32 IdleTime() { 75 int32 IdleTime() {
76 if (have_idle_info_ && idle_info_.Get()) { 76 if (have_idle_info_ && idle_info_.Get()) {
77 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), 77 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
78 *idle_info_.Get()); 78 idle_info_.Get());
79 return (*idle_info_.Get())->idle; 79 return idle_info_.Get()->idle;
80 } 80 }
81 return -1; 81 return -1;
82 } 82 }
83 83
84 private: 84 private:
85 bool have_idle_info_; 85 bool have_idle_info_;
86 ThreadLocalPointer<XScreenSaverInfo*> idle_info_; 86 ThreadLocalPointer<XScreenSaverInfo> idle_info_;
87 87
88 DISALLOW_COPY_AND_ASSIGN(IdleState); 88 DISALLOW_COPY_AND_ASSIGN(IdleState);
89 }; 89 };
90 90
91 bool OSIdleTimeSource(int32* milliseconds_interval_since_last_event) { 91 bool OSIdleTimeSource(int32* milliseconds_interval_since_last_event) {
92 static LazyInstance<IdleState> state_instance(base::LINKER_INITIALIZED); 92 static LazyInstance<IdleState> state_instance(base::LINKER_INITIALIZED);
93 IdleState* state = state_instance.Pointer(); 93 IdleState* state = state_instance.Pointer();
94 int32 idle_time = state->IdleTime(); 94 int32 idle_time = state->IdleTime();
95 if (0 < idle_time) { 95 if (0 < idle_time) {
96 *milliseconds_interval_since_last_event = idle_time; 96 *milliseconds_interval_since_last_event = idle_time;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 TimeDelta current_idle_time = CurrentIdleTime(); 152 TimeDelta current_idle_time = CurrentIdleTime();
153 if (current_idle_time > time_since_last_fire) { 153 if (current_idle_time > time_since_last_fire) {
154 if (repeat_) 154 if (repeat_)
155 return idle_interval_ - time_since_last_fire; 155 return idle_interval_ - time_since_last_fire;
156 return idle_interval_; 156 return idle_interval_;
157 } 157 }
158 return idle_interval_ - current_idle_time; 158 return idle_interval_ - current_idle_time;
159 } 159 }
160 160
161 } // namespace base 161 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698