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 // Runs a posted task at latest by a given deadline, but possibly sooner. | |
| 18 class DeadlineTaskRunner { | |
|
rmcilroy
2015/03/12 22:11:30
looks like you will need to add CONTENT_EXPORT for
alex clarke (OOO till 29th)
2015/03/13 09:53:03
Done.
| |
| 19 public: | |
| 20 DeadlineTaskRunner(const base::Closure& callback, | |
| 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 22 | |
| 23 ~DeadlineTaskRunner(); | |
| 24 | |
| 25 // If there is no outstanding task then a task is posted to run after |delay|. | |
| 26 // If there is an outstanding task which is scheduled to run: | |
| 27 // a) sooner - then this is a NOP. | |
| 28 // b) later - then the outstanding task is cancelled and a new task is | |
| 29 // posted to run after |delay|. | |
| 30 // | |
| 31 // Once the deadline task has run, we reset. | |
| 32 void SetDeadline(const tracked_objects::Location& from_here, | |
| 33 base::TimeDelta delay, | |
| 34 base::TimeTicks now); | |
| 35 | |
| 36 private: | |
| 37 void RunInternal(); | |
| 38 | |
| 39 CancelableClosureHolder cancelable_run_internal_; | |
| 40 base::Closure callback_; | |
| 41 base::TimeTicks deadline_; | |
| 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 43 | |
| 44 DISALLOW_COPY_AND_ASSIGN(DeadlineTaskRunner); | |
| 45 }; | |
| 46 | |
| 47 } // namespace content | |
| 48 | |
| 49 #endif // CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_ | |
| OLD | NEW |