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 #include "base/timer.h" | 5 #include "base/timer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
14 // BaseTimerTaskInternal is a simple delegate for scheduling a callback to | 14 // BaseTimerTaskInternal is a simple delegate for scheduling a callback to |
15 // Timer in the thread's default task runner. It also handles the following | 15 // Timer in the thread's default task runner. It also handles the following |
16 // edge cases: | 16 // edge cases: |
17 // - deleted by the task runner. | 17 // - deleted by the task runner. |
18 // - abandoned (orphaned) by Timer. | 18 // - abandoned (orphaned) by Timer. |
19 class BaseTimerTaskInternal { | 19 class BaseTimerTaskInternal { |
20 public: | 20 public: |
21 BaseTimerTaskInternal(Timer* timer) | 21 explicit BaseTimerTaskInternal(Timer* timer) |
22 : timer_(timer) { | 22 : timer_(timer) { |
23 } | 23 } |
24 | 24 |
25 ~BaseTimerTaskInternal() { | 25 ~BaseTimerTaskInternal() { |
26 // This task may be getting cleared because the task runner has been | 26 // This task may be getting cleared because the task runner has been |
27 // destructed. If so, don't leave Timer with a dangling pointer | 27 // destructed. If so, don't leave Timer with a dangling pointer |
28 // to this. | 28 // to this. |
29 if (timer_) | 29 if (timer_) |
30 timer_->StopAndAbandon(); | 30 timer_->StopAndAbandon(); |
31 } | 31 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 PostNewScheduledTask(delay_); | 177 PostNewScheduledTask(delay_); |
178 else | 178 else |
179 Stop(); | 179 Stop(); |
180 | 180 |
181 task.Run(); | 181 task.Run(); |
182 | 182 |
183 // No more member accesses here: *this could be deleted at this point. | 183 // No more member accesses here: *this could be deleted at this point. |
184 } | 184 } |
185 | 185 |
186 } // namespace base | 186 } // namespace base |
OLD | NEW |