| OLD | NEW |
| 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 30 matching lines...) Expand all Loading... |
| 41 // Function prototype - Get the number of milliseconds that the user has been | 41 // Function prototype - Get the number of milliseconds that the user has been |
| 42 // idle. | 42 // idle. |
| 43 typedef bool (*IdleTimeSource)(int32 *milliseconds_interval_since_last_event); | 43 typedef bool (*IdleTimeSource)(int32 *milliseconds_interval_since_last_event); |
| 44 | 44 |
| 45 class IdleTimer { | 45 class IdleTimer { |
| 46 public: | 46 public: |
| 47 // Create an IdleTimer. | 47 // Create an IdleTimer. |
| 48 // idle_time: idle time required before this timer can run. | 48 // idle_time: idle time required before this timer can run. |
| 49 // repeat: true if the timer should fire multiple times per idle, | 49 // repeat: true if the timer should fire multiple times per idle, |
| 50 // false to fire once per idle. | 50 // false to fire once per idle. |
| 51 IdleTimer(TimeDelta idle_time, bool repeat); | 51 IdleTimer(base::TimeDelta idle_time, bool repeat); |
| 52 | 52 |
| 53 // On destruction, the IdleTimer will Stop itself. | 53 // On destruction, the IdleTimer will Stop itself. |
| 54 virtual ~IdleTimer(); | 54 virtual ~IdleTimer(); |
| 55 | 55 |
| 56 // Start the IdleTimer. | 56 // Start the IdleTimer. |
| 57 void Start(); | 57 void Start(); |
| 58 | 58 |
| 59 // Stop the IdleTimer. | 59 // Stop the IdleTimer. |
| 60 void Stop(); | 60 void Stop(); |
| 61 | 61 |
| 62 // The method to run when the timer elapses. | 62 // The method to run when the timer elapses. |
| 63 virtual void OnIdle() = 0; | 63 virtual void OnIdle() = 0; |
| 64 | 64 |
| 65 protected: | 65 protected: |
| 66 // Override the IdleTimeSource. | 66 // Override the IdleTimeSource. |
| 67 void set_idle_time_source(IdleTimeSource idle_time_source) { | 67 void set_idle_time_source(IdleTimeSource idle_time_source) { |
| 68 idle_time_source_ = idle_time_source; | 68 idle_time_source_ = idle_time_source; |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 // Called when timer_ expires. | 72 // Called when timer_ expires. |
| 73 void Run(); | 73 void Run(); |
| 74 | 74 |
| 75 // Start the timer. | 75 // Start the timer. |
| 76 void StartTimer(); | 76 void StartTimer(); |
| 77 | 77 |
| 78 // Gets the number of milliseconds since the last input event. | 78 // Gets the number of milliseconds since the last input event. |
| 79 TimeDelta CurrentIdleTime(); | 79 base::TimeDelta CurrentIdleTime(); |
| 80 | 80 |
| 81 // Compute time until idle. Returns 0 if we are now idle. | 81 // Compute time until idle. Returns 0 if we are now idle. |
| 82 TimeDelta TimeUntilIdle(); | 82 base::TimeDelta TimeUntilIdle(); |
| 83 | 83 |
| 84 TimeDelta idle_interval_; | 84 base::TimeDelta idle_interval_; |
| 85 bool repeat_; | 85 bool repeat_; |
| 86 Time last_time_fired_; // The last time the idle timer fired. | 86 base::Time last_time_fired_; // The last time the idle timer fired. |
| 87 // will be 0 until the timer fires the first time. | 87 // will be 0 until the timer fires the first time. |
| 88 OneShotTimer<IdleTimer> timer_; | 88 OneShotTimer<IdleTimer> timer_; |
| 89 | 89 |
| 90 IdleTimeSource idle_time_source_; | 90 IdleTimeSource idle_time_source_; |
| 91 | 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(IdleTimer); | 92 DISALLOW_COPY_AND_ASSIGN(IdleTimer); |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 } // namespace base | 95 } // namespace base |
| 96 | 96 |
| 97 #endif // BASE_IDLE_TIMER_H_ | 97 #endif // BASE_IDLE_TIMER_H_ |
| OLD | NEW |