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/timer.h" | 5 #include "base/timer/timer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_)), | 156 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_)), |
157 delay); | 157 delay); |
158 scheduled_run_time_ = desired_run_time_ = TimeTicks::Now() + delay; | 158 scheduled_run_time_ = desired_run_time_ = TimeTicks::Now() + delay; |
159 } else { | 159 } else { |
160 GetTaskRunner()->PostTask(posted_from_, | 160 GetTaskRunner()->PostTask(posted_from_, |
161 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_))); | 161 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_))); |
162 scheduled_run_time_ = desired_run_time_ = TimeTicks(); | 162 scheduled_run_time_ = desired_run_time_ = TimeTicks(); |
163 } | 163 } |
164 // Remember the thread ID that posts the first task -- this will be verified | 164 // Remember the thread ID that posts the first task -- this will be verified |
165 // later when the task is abandoned to detect misuse from multiple threads. | 165 // later when the task is abandoned to detect misuse from multiple threads. |
166 if (!thread_id_) | 166 if (!thread_id_) { |
| 167 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
167 thread_id_ = static_cast<int>(PlatformThread::CurrentId()); | 168 thread_id_ = static_cast<int>(PlatformThread::CurrentId()); |
| 169 } |
168 } | 170 } |
169 | 171 |
170 scoped_refptr<SingleThreadTaskRunner> Timer::GetTaskRunner() { | 172 scoped_refptr<SingleThreadTaskRunner> Timer::GetTaskRunner() { |
171 return task_runner_.get() ? task_runner_ : ThreadTaskRunnerHandle::Get(); | 173 return task_runner_.get() ? task_runner_ : ThreadTaskRunnerHandle::Get(); |
172 } | 174 } |
173 | 175 |
174 void Timer::AbandonScheduledTask() { | 176 void Timer::AbandonScheduledTask() { |
175 DCHECK(thread_id_ == 0 || | 177 DCHECK(thread_id_ == 0 || |
176 thread_id_ == static_cast<int>(PlatformThread::CurrentId())); | 178 thread_id_ == static_cast<int>(PlatformThread::CurrentId())); |
177 if (scheduled_task_) { | 179 if (scheduled_task_) { |
(...skipping 29 matching lines...) Expand all Loading... |
207 PostNewScheduledTask(delay_); | 209 PostNewScheduledTask(delay_); |
208 else | 210 else |
209 Stop(); | 211 Stop(); |
210 | 212 |
211 task.Run(); | 213 task.Run(); |
212 | 214 |
213 // No more member accesses here: *this could be deleted at this point. | 215 // No more member accesses here: *this could be deleted at this point. |
214 } | 216 } |
215 | 217 |
216 } // namespace base | 218 } // namespace base |
OLD | NEW |