Index: content/renderer/scheduler/deadline_task_runner.cc |
diff --git a/content/renderer/scheduler/deadline_task_runner.cc b/content/renderer/scheduler/deadline_task_runner.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bdb32c4c71783da92cdd54f7e04dc190e053b75b |
--- /dev/null |
+++ b/content/renderer/scheduler/deadline_task_runner.cc |
@@ -0,0 +1,40 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/renderer/scheduler/deadline_task_runner.h" |
+ |
+#include "base/bind.h" |
+ |
+namespace content { |
+ |
+DeadlineTaskRunner::DeadlineTaskRunner( |
+ const base::Closure& callback, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
+ : callback_(callback), task_runner_(task_runner) { |
+ cancelable_run_internal_.Reset(base::Bind( |
+ &DeadlineTaskRunner::RunInternal, base::Unretained(this))); |
+} |
+ |
+DeadlineTaskRunner::~DeadlineTaskRunner() { |
+} |
Sami
2015/03/12 18:15:22
We don't need to cancel the callback here, right?
alex clarke (OOO till 29th)
2015/03/12 18:24:07
No that's done implicitly. There is a test for th
|
+ |
+void DeadlineTaskRunner::SetDeadline(const tracked_objects::Location& from_here, |
+ base::TimeDelta delay, |
+ base::TimeTicks now) { |
+ DCHECK(delay > base::TimeDelta()); |
+ base::TimeTicks deadline = now + delay; |
+ if (deadline_ == base::TimeTicks() || deadline < deadline_) { |
Sami
2015/03/12 18:15:22
nit: deadline_.is_null()
alex clarke (OOO till 29th)
2015/03/12 18:24:07
Done.
|
+ deadline_ = deadline; |
+ cancelable_run_internal_.Cancel(); |
+ task_runner_->PostDelayedTask( |
+ from_here, cancelable_run_internal_.callback(), delay); |
+ } |
+} |
+ |
+void DeadlineTaskRunner::RunInternal() { |
+ deadline_ = base::TimeTicks(); |
+ callback_.Run(); |
+} |
+ |
+} // namespace content |