Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: base/timer/timer.cc

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/threading/worker_pool_unittest.cc ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/threading/worker_pool_unittest.cc ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698