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 #ifndef CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_ | |
| 6 #define CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "base/single_thread_task_runner.h" | |
| 12 #include "base/time/time.h" | |
| 13 #include "content/renderer/scheduler/cancelable_closure_holder.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 class DeadlineTaskRunner { | |
|
Sami
2015/03/12 18:15:22
Maybe add a short comment here describing what thi
alex clarke (OOO till 29th)
2015/03/12 18:30:01
Done.
| |
| 18 public: | |
| 19 DeadlineTaskRunner(const base::Closure& callback, | |
| 20 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 21 | |
| 22 ~DeadlineTaskRunner(); | |
| 23 | |
| 24 // If there is no outstanding task then a task is posted to run after |delay|. | |
| 25 // If there is an outstanding task which is scheduled to run: | |
| 26 // a) sooner - then this is a NOP. | |
| 27 // b) later - then the outstanding task is cancelled and a new task is | |
| 28 // posted to run after |delay|. | |
| 29 // | |
| 30 // Once the deadline task has run, we reset. | |
| 31 void SetDeadline(const tracked_objects::Location& from_here, | |
| 32 base::TimeDelta delay, | |
| 33 base::TimeTicks now); | |
| 34 | |
| 35 private: | |
| 36 void RunInternal(); | |
| 37 | |
| 38 CancelableClosureHolder cancelable_run_internal_; | |
| 39 base::Closure callback_; | |
| 40 base::TimeTicks deadline_; | |
| 41 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(DeadlineTaskRunner); | |
| 44 }; | |
| 45 | |
| 46 } // namespace content | |
| 47 | |
| 48 #endif // CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_ | |
| OLD | NEW |