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 23 matching lines...) Expand all Loading... |
34 // | 34 // |
35 // Both OneShotTimer and RepeatingTimer also support a Reset method, which | 35 // Both OneShotTimer and RepeatingTimer also support a Reset method, which |
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_TIMER_H_ |
45 #define BASE_TIMER_H_ | 45 #define BASE_TIMER_TIMER_H_ |
46 | 46 |
47 // 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 |
48 // disabled ones) from timer_unittests.cc pass locally. Some are disabled | 48 // disabled ones) from timer_unittests.cc pass locally. Some are disabled |
49 // 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 |
50 // should be able to tell the difference. | 50 // should be able to tell the difference. |
51 | 51 |
52 #include "base/base_export.h" | 52 #include "base/base_export.h" |
53 #include "base/bind.h" | 53 #include "base/bind.h" |
54 #include "base/bind_helpers.h" | 54 #include "base/bind_helpers.h" |
55 #include "base/callback.h" | 55 #include "base/callback.h" |
56 #include "base/location.h" | 56 #include "base/location.h" |
57 #include "base/time.h" | 57 #include "base/time/time.h" |
58 | 58 |
59 namespace base { | 59 namespace base { |
60 | 60 |
61 class BaseTimerTaskInternal; | 61 class BaseTimerTaskInternal; |
62 class MessageLoop; | 62 class MessageLoop; |
63 | 63 |
64 //----------------------------------------------------------------------------- | 64 //----------------------------------------------------------------------------- |
65 // This class wraps MessageLoop::PostDelayedTask to manage delayed and repeating | 65 // This class wraps MessageLoop::PostDelayedTask to manage delayed and repeating |
66 // tasks. It must be destructed on the same thread that starts tasks. There are | 66 // tasks. It must be destructed on the same thread that starts tasks. There are |
67 // DCHECKs in place to verify this. | 67 // DCHECKs in place to verify this. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 ReceiverMethod method) | 236 ReceiverMethod method) |
237 : Timer(posted_from, delay, | 237 : Timer(posted_from, delay, |
238 base::Bind(method, base::Unretained(receiver)), | 238 base::Bind(method, base::Unretained(receiver)), |
239 false) {} | 239 false) {} |
240 | 240 |
241 void Reset() { Timer::Reset(); } | 241 void Reset() { Timer::Reset(); } |
242 }; | 242 }; |
243 | 243 |
244 } // namespace base | 244 } // namespace base |
245 | 245 |
246 #endif // BASE_TIMER_H_ | 246 #endif // BASE_TIMER_TIMER_H_ |
OLD | NEW |