Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 "content/renderer/scheduler/deadline_task_runner.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 DeadlineTaskRunner::DeadlineTaskRunner( | |
| 12 const base::Closure& callback, | |
| 13 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | |
| 14 : callback_(callback), task_runner_(task_runner), weak_factory_(this) { | |
| 15 InitializeRunInternal(); | |
| 16 } | |
| 17 | |
| 18 DeadlineTaskRunner::~DeadlineTaskRunner() { | |
| 19 } | |
| 20 | |
| 21 void DeadlineTaskRunner::SetDeadline(const tracked_objects::Location& from_here, | |
| 22 base::TimeTicks deadline, | |
| 23 base::TimeTicks now) { | |
| 24 DCHECK(deadline > now); | |
| 25 if (deadline_ != base::TimeTicks()) { | |
| 26 if (deadline >= deadline_) | |
| 27 return; | |
|
rmcilroy
2015/03/12 15:45:30
This might be clearer with a non-nested early out
alex clarke (OOO till 29th)
2015/03/12 17:01:49
Unfortunately that will always early out if we use
| |
| 28 | |
| 29 Cancel(); | |
| 30 } | |
| 31 deadline_ = deadline; | |
| 32 task_runner_->PostDelayedTask(from_here, run_internal_, deadline - now); | |
| 33 } | |
| 34 | |
| 35 void DeadlineTaskRunner::RunInternal() { | |
| 36 deadline_ = base::TimeTicks(); | |
| 37 callback_.Run(); | |
| 38 } | |
| 39 | |
| 40 void DeadlineTaskRunner::Cancel() { | |
| 41 weak_factory_.InvalidateWeakPtrs(); | |
| 42 InitializeRunInternal(); | |
| 43 } | |
| 44 | |
| 45 void DeadlineTaskRunner::InitializeRunInternal() { | |
| 46 run_internal_ = | |
| 47 base::Bind(&DeadlineTaskRunner::RunInternal, weak_factory_.GetWeakPtr()); | |
|
rmcilroy
2015/03/12 15:45:30
Just use a CancelableClosureHolder for the interna
alex clarke (OOO till 29th)
2015/03/12 17:01:49
I thought about doing it that way but I think we'd
| |
| 48 } | |
| 49 | |
| 50 } // namespace content | |
| OLD | NEW |