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

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

Issue 2514293004: Modernize TimerTests prior to https://codereview.chromium.org/2491613004 (Closed)
Patch Set: review:danakj Created 4 years 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 | « no previous file | base/timer/timer_unittest.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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_)), 174 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_)),
175 delay); 175 delay);
176 scheduled_run_time_ = desired_run_time_ = Now() + delay; 176 scheduled_run_time_ = desired_run_time_ = Now() + delay;
177 } else { 177 } else {
178 GetTaskRunner()->PostTask(posted_from_, 178 GetTaskRunner()->PostTask(posted_from_,
179 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_))); 179 base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_)));
180 scheduled_run_time_ = desired_run_time_ = TimeTicks(); 180 scheduled_run_time_ = desired_run_time_ = TimeTicks();
181 } 181 }
182 // Remember the thread ID that posts the first task -- this will be verified 182 // 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. 183 // later when the task is abandoned to detect misuse from multiple threads.
184 if (!thread_id_) { 184 if (!thread_id_)
185 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
186 thread_id_ = static_cast<int>(PlatformThread::CurrentId()); 185 thread_id_ = static_cast<int>(PlatformThread::CurrentId());
187 }
188 } 186 }
189 187
190 scoped_refptr<SingleThreadTaskRunner> Timer::GetTaskRunner() { 188 scoped_refptr<SingleThreadTaskRunner> Timer::GetTaskRunner() {
191 return task_runner_.get() ? task_runner_ : ThreadTaskRunnerHandle::Get(); 189 return task_runner_.get() ? task_runner_ : ThreadTaskRunnerHandle::Get();
192 } 190 }
193 191
194 void Timer::AbandonScheduledTask() { 192 void Timer::AbandonScheduledTask() {
195 DCHECK(thread_id_ == 0 || 193 DCHECK(thread_id_ == 0 ||
196 thread_id_ == static_cast<int>(PlatformThread::CurrentId())); 194 thread_id_ == static_cast<int>(PlatformThread::CurrentId()));
197 if (scheduled_task_) { 195 if (scheduled_task_) {
(...skipping 29 matching lines...) Expand all
227 PostNewScheduledTask(delay_); 225 PostNewScheduledTask(delay_);
228 else 226 else
229 Stop(); 227 Stop();
230 228
231 task.Run(); 229 task.Run();
232 230
233 // No more member accesses here: *this could be deleted at this point. 231 // No more member accesses here: *this could be deleted at this point.
234 } 232 }
235 233
236 } // namespace base 234 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/timer/timer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698