OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_SINGLE_THREAD_IDLE_TASK_RUNNER_H_ |
| 6 #define CONTENT_RENDERER_SCHEDULER_SINGLE_THREAD_IDLE_TASK_RUNNER_H_ |
| 7 |
| 8 #include "base/bind.h" |
| 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/time/time.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class IdleTaskDeadlineSupplier; |
| 18 |
| 19 // A SingleThreadIdleTaskRunner is a task runner for running idle tasks. Idle |
| 20 // tasks have an unbound argument which is bound to a deadline |
| 21 // (in base::TimeTicks) when they are run. The idle task is expected to |
| 22 // complete by this deadline. |
| 23 class SingleThreadIdleTaskRunner |
| 24 : public base::RefCountedThreadSafe<SingleThreadIdleTaskRunner> { |
| 25 public: |
| 26 typedef base::Callback<void(base::TimeTicks)> IdleTask; |
| 27 |
| 28 SingleThreadIdleTaskRunner( |
| 29 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 30 base::WeakPtr<IdleTaskDeadlineSupplier> deadline_supplier); |
| 31 |
| 32 virtual void PostIdleTask(const tracked_objects::Location& from_here, |
| 33 const IdleTask& idle_task); |
| 34 |
| 35 bool RunsTasksOnCurrentThread() const; |
| 36 |
| 37 protected: |
| 38 virtual ~SingleThreadIdleTaskRunner(); |
| 39 |
| 40 private: |
| 41 friend class base::RefCountedThreadSafe<SingleThreadIdleTaskRunner>; |
| 42 |
| 43 void RunTask(IdleTask idle_task); |
| 44 |
| 45 scoped_refptr<base::TaskRunner> task_runner_; |
| 46 base::WeakPtr<IdleTaskDeadlineSupplier> deadline_supplier_; |
| 47 }; |
| 48 |
| 49 class IdleTaskDeadlineSupplier { |
| 50 public: |
| 51 // Returns the deadline by which an idle task should finish by. |
| 52 virtual base::TimeTicks CurrentIdleTaskDeadline() const = 0; |
| 53 |
| 54 protected: |
| 55 virtual ~IdleTaskDeadlineSupplier(); |
| 56 }; |
| 57 |
| 58 } // namespace content |
| 59 |
| 60 #endif // CONTENT_RENDERER_SCHEDULER_SINGLE_THREAD_IDLE_TASK_RUNNER_H_ |
OLD | NEW |