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

Side by Side Diff: base/idle_timer.h

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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/base.xcodeproj/project.pbxproj ('k') | base/idle_timer.cc » ('j') | 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 // IdleTimer is a recurring Timer which runs only when the system is idle. 5 // IdleTimer is a recurring Timer which runs only when the system is idle.
6 // System Idle time is defined as not having any user keyboard or mouse 6 // System Idle time is defined as not having any user keyboard or mouse
7 // activity for some period of time. Because the timer is user dependant, it 7 // activity for some period of time. Because the timer is user dependant, it
8 // is possible for the timer to never fire. 8 // is possible for the timer to never fire.
9 // 9 //
10 // Usage should be for low-priority work, and may look like this: 10 // Usage should be for low-priority work, and may look like this:
(...skipping 10 matching lines...) Expand all
21 // 21 //
22 // // As with all Timers, the caller must dispose the object. 22 // // As with all Timers, the caller must dispose the object.
23 // delete timer; // Will Stop the timer and cleanup. 23 // delete timer; // Will Stop the timer and cleanup.
24 // 24 //
25 // NOTE: An IdleTimer can only be used on a thread that processes UI events. 25 // NOTE: An IdleTimer can only be used on a thread that processes UI events.
26 // Such a thread should be running a MessageLoopForUI. 26 // Such a thread should be running a MessageLoopForUI.
27 27
28 #ifndef BASE_IDLE_TIMER_H_ 28 #ifndef BASE_IDLE_TIMER_H_
29 #define BASE_IDLE_TIMER_H_ 29 #define BASE_IDLE_TIMER_H_
30 30
31 #if defined(OS_WIN)
31 #include <windows.h> 32 #include <windows.h>
33 #endif
32 34
33 #include "base/basictypes.h" 35 #include "base/basictypes.h"
34 #include "base/task.h" 36 #include "base/task.h"
35 #include "base/timer.h" 37 #include "base/timer.h"
36 38
37 namespace base { 39 namespace base {
38 40
39 // Function prototype for GetLastInputInfo. 41 // Function prototype - Get the number of milliseconds that the user has been
40 typedef BOOL (__stdcall *GetLastInputInfoFunction)(PLASTINPUTINFO plii); 42 // idle.
43 typedef bool (*IdleTimeSource)(int32 *milliseconds_interval_since_last_event);
41 44
42 class IdleTimer { 45 class IdleTimer {
43 public: 46 public:
44 // Create an IdleTimer. 47 // Create an IdleTimer.
45 // idle_time: idle time required before this timer can run. 48 // idle_time: idle time required before this timer can run.
46 // repeat: true if the timer should fire multiple times per idle, 49 // repeat: true if the timer should fire multiple times per idle,
47 // false to fire once per idle. 50 // false to fire once per idle.
48 IdleTimer(TimeDelta idle_time, bool repeat); 51 IdleTimer(TimeDelta idle_time, bool repeat);
49 52
50 // On destruction, the IdleTimer will Stop itself. 53 // On destruction, the IdleTimer will Stop itself.
51 virtual ~IdleTimer(); 54 virtual ~IdleTimer();
52 55
53 // Start the IdleTimer. 56 // Start the IdleTimer.
54 void Start(); 57 void Start();
55 58
56 // Stop the IdleTimer. 59 // Stop the IdleTimer.
57 void Stop(); 60 void Stop();
58 61
59 // The method to run when the timer elapses. 62 // The method to run when the timer elapses.
60 virtual void OnIdle() = 0; 63 virtual void OnIdle() = 0;
61 64
62 protected: 65 protected:
63 // Override the GetLastInputInfo function. 66 // Override the IdleTimeSource.
64 void set_last_input_info_fn(GetLastInputInfoFunction function) { 67 void set_idle_time_source(IdleTimeSource idle_time_source) {
65 get_last_input_info_fn_ = function; 68 idle_time_source_ = idle_time_source;
66 } 69 }
67 70
68 private: 71 private:
69 // Called when timer_ expires. 72 // Called when timer_ expires.
70 void Run(); 73 void Run();
71 74
72 // Start the timer. 75 // Start the timer.
73 void StartTimer(); 76 void StartTimer();
74 77
75 // Gets the number of milliseconds since the last input event. 78 // Gets the number of milliseconds since the last input event.
76 TimeDelta CurrentIdleTime(); 79 TimeDelta CurrentIdleTime();
77 80
78 // Compute time until idle. Returns 0 if we are now idle. 81 // Compute time until idle. Returns 0 if we are now idle.
79 TimeDelta TimeUntilIdle(); 82 TimeDelta TimeUntilIdle();
80 83
81 TimeDelta idle_interval_; 84 TimeDelta idle_interval_;
82 bool repeat_; 85 bool repeat_;
83 Time last_time_fired_; // The last time the idle timer fired. 86 Time last_time_fired_; // The last time the idle timer fired.
84 // will be 0 until the timer fires the first time. 87 // will be 0 until the timer fires the first time.
85 OneShotTimer<IdleTimer> timer_; 88 OneShotTimer<IdleTimer> timer_;
86 89
87 GetLastInputInfoFunction get_last_input_info_fn_; 90 IdleTimeSource idle_time_source_;
88 91
89 DISALLOW_COPY_AND_ASSIGN(IdleTimer); 92 DISALLOW_COPY_AND_ASSIGN(IdleTimer);
90 }; 93 };
91 94
92 } // namespace base 95 } // namespace base
93 96
94 #endif // BASE_IDLE_TIMER_H_ 97 #endif // BASE_IDLE_TIMER_H_
OLDNEW
« no previous file with comments | « base/base.xcodeproj/project.pbxproj ('k') | base/idle_timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698