| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // OneShotTimer and RepeatingTimer provide a simple timer API. As the names | 5 // OneShotTimer and RepeatingTimer provide a simple timer API. As the names |
| 6 // suggest, OneShotTimer calls you back once after a time delay expires. | 6 // suggest, OneShotTimer calls you back once after a time delay expires. |
| 7 // RepeatingTimer on the other hand calls you back periodically with the | 7 // RepeatingTimer on the other hand calls you back periodically with the |
| 8 // prescribed time interval. | 8 // prescribed time interval. |
| 9 // | 9 // |
| 10 // OneShotTimer and RepeatingTimer both cancel the timer when they go out of | 10 // OneShotTimer and RepeatingTimer both cancel the timer when they go out of |
| 11 // scope, which makes it easy to ensure that you do not get called when your | 11 // scope, which makes it easy to ensure that you do not get called when your |
| 12 // object has gone out of scope. Just instantiate a OneShotTimer or | 12 // object has gone out of scope. Just instantiate a OneShotTimer or |
| 13 // RepeatingTimer as a member variable of the class for which you wish to | 13 // RepeatingTimer as a member variable of the class for which you wish to |
| 14 // receive timer events. | 14 // receive timer events. |
| 15 // | 15 // |
| 16 // Sample RepeatingTimer usage: | 16 // Sample RepeatingTimer usage: |
| 17 // | 17 // |
| 18 // class MyClass { | 18 // class MyClass { |
| 19 // public: | 19 // public: |
| 20 // void StartDoingStuff() { | 20 // void StartDoingStuff() { |
| 21 // timer_.Start(TimeDelta::FromSeconds(1), this, &MyClass::DoStuff); | 21 // timer_.Start(FROM_HERE, TimeDelta::FromSeconds(1), |
| 22 // this, &MyClass::DoStuff); |
| 22 // } | 23 // } |
| 23 // void StopDoingStuff() { | 24 // void StopDoingStuff() { |
| 24 // timer_.Stop(); | 25 // timer_.Stop(); |
| 25 // } | 26 // } |
| 26 // private: | 27 // private: |
| 27 // void DoStuff() { | 28 // void DoStuff() { |
| 28 // // This method is called every second to do stuff. | 29 // // This method is called every second to do stuff. |
| 29 // ... | 30 // ... |
| 30 // } | 31 // } |
| 31 // base::RepeatingTimer<MyClass> timer_; | 32 // base::RepeatingTimer<MyClass> timer_; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 const ReceiverMethod method_; | 281 const ReceiverMethod method_; |
| 281 const TimeDelta delay_; | 282 const TimeDelta delay_; |
| 282 | 283 |
| 283 OneShotTimer<DelayTimer<Receiver> > timer_; | 284 OneShotTimer<DelayTimer<Receiver> > timer_; |
| 284 TimeTicks trigger_time_; | 285 TimeTicks trigger_time_; |
| 285 }; | 286 }; |
| 286 | 287 |
| 287 } // namespace base | 288 } // namespace base |
| 288 | 289 |
| 289 #endif // BASE_TIMER_H_ | 290 #endif // BASE_TIMER_H_ |
| OLD | NEW |