Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/net/mockable_one_shot_timer.h" | |
| 6 | |
| 7 MockableOneShotTimer::MockableOneShotTimer() {} | |
| 8 MockableOneShotTimer::~MockableOneShotTimer() {} | |
| 9 | |
| 10 void MockableOneShotTimer::Fired() { | |
| 11 // Store the task in a temporary across Run() to prevent its closure (and | |
| 12 // hence maybe arguments to the callback function or similar) from going out | |
| 13 // of scope while Run() is still executing if Run() calls Start(). | |
| 14 base::Closure temp_task = task_; | |
| 15 task_.Reset(); | |
| 16 task_.Run(); | |
|
mmenke
2014/03/07 15:46:17
temp_task.Run();
There were no unit tests to chec
Elly Fong-Jones
2014/03/10 19:46:51
Fixed.
I don't see how one could write a unit tes
mmenke
2014/03/10 19:49:57
See base/timer/timer_unittest.cc
Elly Fong-Jones
2014/03/11 17:06:17
Done.
| |
| 17 } | |
| 18 | |
| 19 void MockableOneShotTimer::Start( | |
| 20 const tracked_objects::Location& posted_from, base::TimeDelta delay, | |
| 21 const base::Closure& task) { | |
| 22 DCHECK(!task.is_null()); | |
| 23 task_ = task; | |
| 24 timer_.Start(posted_from, delay, | |
| 25 base::Bind(&MockableOneShotTimer::Fired, base::Unretained(this))); | |
| 26 } | |
| 27 | |
| 28 void MockableOneShotTimer::Stop() { | |
| 29 timer_.Stop(); | |
| 30 } | |
| 31 | |
| 32 bool MockableOneShotTimer::IsRunning() const { | |
| 33 return timer_.IsRunning(); | |
| 34 } | |
| OLD | NEW |