| OLD | NEW |
| 1 // Copyright (c) 2012 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // allows you to easily defer the timer event until the timer delay passes once | 36 // allows you to easily defer the timer event until the timer delay passes once |
| 37 // again. So, in the above example, if 0.5 seconds have already passed, | 37 // again. So, in the above example, if 0.5 seconds have already passed, |
| 38 // calling Reset on timer_ would postpone DoStuff by another 1 second. In | 38 // calling Reset on timer_ would postpone DoStuff by another 1 second. In |
| 39 // other words, Reset is shorthand for calling Stop and then Start again with | 39 // other words, Reset is shorthand for calling Stop and then Start again with |
| 40 // the same arguments. | 40 // the same arguments. |
| 41 // | 41 // |
| 42 // NOTE: These APIs are not thread safe. Always call from the same thread. | 42 // NOTE: These APIs are not thread safe. Always call from the same thread. |
| 43 | 43 |
| 44 #ifndef BASE_TIMER_H_ | 44 #ifndef BASE_TIMER_H_ |
| 45 #define BASE_TIMER_H_ | 45 #define BASE_TIMER_H_ |
| 46 #pragma once | |
| 47 | 46 |
| 48 // IMPORTANT: If you change timer code, make sure that all tests (including | 47 // IMPORTANT: If you change timer code, make sure that all tests (including |
| 49 // disabled ones) from timer_unittests.cc pass locally. Some are disabled | 48 // disabled ones) from timer_unittests.cc pass locally. Some are disabled |
| 50 // because they're flaky on the buildbot, but when you run them locally you | 49 // because they're flaky on the buildbot, but when you run them locally you |
| 51 // should be able to tell the difference. | 50 // should be able to tell the difference. |
| 52 | 51 |
| 53 #include "base/base_export.h" | 52 #include "base/base_export.h" |
| 54 #include "base/bind.h" | 53 #include "base/bind.h" |
| 55 #include "base/bind_helpers.h" | 54 #include "base/bind_helpers.h" |
| 56 #include "base/callback.h" | 55 #include "base/callback.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 : Timer(posted_from, delay, | 231 : Timer(posted_from, delay, |
| 233 base::Bind(method, base::Unretained(receiver)), | 232 base::Bind(method, base::Unretained(receiver)), |
| 234 false) {} | 233 false) {} |
| 235 | 234 |
| 236 void Reset() { Timer::Reset(); } | 235 void Reset() { Timer::Reset(); } |
| 237 }; | 236 }; |
| 238 | 237 |
| 239 } // namespace base | 238 } // namespace base |
| 240 | 239 |
| 241 #endif // BASE_TIMER_H_ | 240 #endif // BASE_TIMER_H_ |
| OLD | NEW |