| 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 |
| 14 namespace content { |
| 15 |
| 16 class DeadlineTaskRunner { |
| 17 public: |
| 18 DeadlineTaskRunner(const base::Closure& callback, |
| 19 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 20 |
| 21 ~DeadlineTaskRunner(); |
| 22 |
| 23 // If there is no outstanding task then a task is posted to run at |deadline|. |
| 24 // If there is an outstanding task which is: |
| 25 // a) sooner - then this is a NOP. |
| 26 // b) later - then the outstanding task is cancelled and a new task is |
| 27 // posted to run at |deadline|. |
| 28 // |
| 29 // Once the deadline task has run, we reset. |
| 30 void SetDeadline(const tracked_objects::Location& from_here, |
| 31 base::TimeTicks deadline, |
| 32 base::TimeTicks now); |
| 33 |
| 34 private: |
| 35 void Cancel(); |
| 36 void RunInternal(); |
| 37 void InitializeRunInternal(); |
| 38 |
| 39 base::Closure run_internal_; |
| 40 base::Closure callback_; |
| 41 base::TimeTicks deadline_; |
| 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 43 |
| 44 // Used to ensure RunInternal() is not run when this object is destroyed. |
| 45 base::WeakPtrFactory<DeadlineTaskRunner> weak_factory_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(DeadlineTaskRunner); |
| 48 }; |
| 49 |
| 50 } // namespace content |
| 51 |
| 52 #endif // CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_ |
| OLD | NEW |