Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / scheduler / renderer / deadline_task_runner.cc
blobfd6859f3208765c29b49dd528b31ab93b6cef8af
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.
5 #include "components/scheduler/renderer/deadline_task_runner.h"
7 #include "base/bind.h"
9 namespace scheduler {
11 DeadlineTaskRunner::DeadlineTaskRunner(
12 const base::Closure& callback,
13 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
14 : callback_(callback), task_runner_(task_runner) {
15 cancelable_run_internal_.Reset(
16 base::Bind(&DeadlineTaskRunner::RunInternal, base::Unretained(this)));
19 DeadlineTaskRunner::~DeadlineTaskRunner() {
22 void DeadlineTaskRunner::SetDeadline(const tracked_objects::Location& from_here,
23 base::TimeDelta delay,
24 base::TimeTicks now) {
25 DCHECK(delay > base::TimeDelta());
26 base::TimeTicks deadline = now + delay;
27 if (deadline_.is_null() || deadline < deadline_) {
28 deadline_ = deadline;
29 cancelable_run_internal_.Cancel();
30 task_runner_->PostDelayedTask(from_here,
31 cancelable_run_internal_.callback(), delay);
35 void DeadlineTaskRunner::RunInternal() {
36 deadline_ = base::TimeTicks();
37 callback_.Run();
40 } // namespace scheduler