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 #include "base/bind.h" |
| 8 |
| 9 MockableOneShotTimer::MockableOneShotTimer() {} |
| 10 MockableOneShotTimer::~MockableOneShotTimer() {} |
| 11 |
| 12 void MockableOneShotTimer::Fired() { |
| 13 // Store the task in a temporary across Run() to prevent its closure (and |
| 14 // hence maybe arguments to the callback function or similar) from going out |
| 15 // of scope while Run() is still executing if Run() calls Start(). |
| 16 base::Closure temp_task = task_; |
| 17 task_.Reset(); |
| 18 temp_task.Run(); |
| 19 } |
| 20 |
| 21 void MockableOneShotTimer::Start( |
| 22 const tracked_objects::Location& posted_from, base::TimeDelta delay, |
| 23 const base::Closure& task) { |
| 24 DCHECK(!task.is_null()); |
| 25 task_ = task; |
| 26 timer_.Start(posted_from, delay, |
| 27 base::Bind(&MockableOneShotTimer::Fired, base::Unretained(this))); |
| 28 } |
| 29 |
| 30 void MockableOneShotTimer::Stop() { |
| 31 timer_.Stop(); |
| 32 } |
| 33 |
| 34 bool MockableOneShotTimer::IsRunning() const { |
| 35 return timer_.IsRunning(); |
| 36 } |
OLD | NEW |