| 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/child/scheduler/cancelable_closure_holder.h" | |
| 14 #include "content/common/content_export.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 // Runs a posted task at latest by a given deadline, but possibly sooner. | |
| 19 class CONTENT_EXPORT DeadlineTaskRunner { | |
| 20 public: | |
| 21 DeadlineTaskRunner(const base::Closure& callback, | |
| 22 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 23 | |
| 24 ~DeadlineTaskRunner(); | |
| 25 | |
| 26 // If there is no outstanding task then a task is posted to run after |delay|. | |
| 27 // If there is an outstanding task which is scheduled to run: | |
| 28 // a) sooner - then this is a NOP. | |
| 29 // b) later - then the outstanding task is cancelled and a new task is | |
| 30 // posted to run after |delay|. | |
| 31 // | |
| 32 // Once the deadline task has run, we reset. | |
| 33 void SetDeadline(const tracked_objects::Location& from_here, | |
| 34 base::TimeDelta delay, | |
| 35 base::TimeTicks now); | |
| 36 | |
| 37 private: | |
| 38 void RunInternal(); | |
| 39 | |
| 40 CancelableClosureHolder cancelable_run_internal_; | |
| 41 base::Closure callback_; | |
| 42 base::TimeTicks deadline_; | |
| 43 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 44 | |
| 45 DISALLOW_COPY_AND_ASSIGN(DeadlineTaskRunner); | |
| 46 }; | |
| 47 | |
| 48 } // namespace content | |
| 49 | |
| 50 #endif // CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_ | |
| OLD | NEW |