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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 posted_from_ = posted_from; | 163 posted_from_ = posted_from; |
164 delay_ = delay; | 164 delay_ = delay; |
165 user_task_ = user_task; | 165 user_task_ = user_task; |
166 } | 166 } |
167 | 167 |
168 void Timer::PostNewScheduledTask(TimeDelta delay) { | 168 void Timer::PostNewScheduledTask(TimeDelta delay) { |
169 DCHECK(scheduled_task_ == NULL); | 169 DCHECK(scheduled_task_ == NULL); |
170 is_running_ = true; | 170 is_running_ = true; |
171 scheduled_task_ = new BaseTimerTaskInternal(this); | 171 scheduled_task_ = new BaseTimerTaskInternal(this); |
172 if (delay > TimeDelta::FromMicroseconds(0)) { | 172 if (delay > TimeDelta::FromMicroseconds(0)) { |
173 GetTaskRunner()->PostDelayedTask(posted_from_, | 173 GetTaskRunner()->PostDelayedTask( |
174 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_)), | 174 posted_from_, |
| 175 base::BindOnce(&BaseTimerTaskInternal::Run, |
| 176 base::Owned(scheduled_task_)), |
175 delay); | 177 delay); |
176 scheduled_run_time_ = desired_run_time_ = Now() + delay; | 178 scheduled_run_time_ = desired_run_time_ = Now() + delay; |
177 } else { | 179 } else { |
178 GetTaskRunner()->PostTask(posted_from_, | 180 GetTaskRunner()->PostTask(posted_from_, |
179 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_))); | 181 base::BindOnce(&BaseTimerTaskInternal::Run, |
| 182 base::Owned(scheduled_task_))); |
180 scheduled_run_time_ = desired_run_time_ = TimeTicks(); | 183 scheduled_run_time_ = desired_run_time_ = TimeTicks(); |
181 } | 184 } |
182 // Remember the thread ID that posts the first task -- this will be verified | 185 // Remember the thread ID that posts the first task -- this will be verified |
183 // later when the task is abandoned to detect misuse from multiple threads. | 186 // later when the task is abandoned to detect misuse from multiple threads. |
184 if (!thread_id_) | 187 if (!thread_id_) |
185 thread_id_ = static_cast<int>(PlatformThread::CurrentId()); | 188 thread_id_ = static_cast<int>(PlatformThread::CurrentId()); |
186 } | 189 } |
187 | 190 |
188 scoped_refptr<SingleThreadTaskRunner> Timer::GetTaskRunner() { | 191 scoped_refptr<SingleThreadTaskRunner> Timer::GetTaskRunner() { |
189 return task_runner_.get() ? task_runner_ : ThreadTaskRunnerHandle::Get(); | 192 return task_runner_.get() ? task_runner_ : ThreadTaskRunnerHandle::Get(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 PostNewScheduledTask(delay_); | 228 PostNewScheduledTask(delay_); |
226 else | 229 else |
227 Stop(); | 230 Stop(); |
228 | 231 |
229 task.Run(); | 232 task.Run(); |
230 | 233 |
231 // No more member accesses here: *this could be deleted at this point. | 234 // No more member accesses here: *this could be deleted at this point. |
232 } | 235 } |
233 | 236 |
234 } // namespace base | 237 } // namespace base |
OLD | NEW |