OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/task_runner.h" | 16 #include "base/task_runner.h" |
17 #include "base/task_scheduler/task_traits.h" | 17 #include "base/task_scheduler/task_traits.h" |
| 18 #include "base/time/time.h" |
18 | 19 |
19 namespace tracked_objects { | 20 namespace tracked_objects { |
20 class Location; | 21 class Location; |
21 } | 22 } |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 | 25 |
25 class HistogramBase; | 26 class HistogramBase; |
26 class SchedulerWorkerPoolParams; | 27 class SchedulerWorkerPoolParams; |
27 | 28 |
28 // Interface for a task scheduler and static methods to manage the instance used | 29 // Interface for a task scheduler and static methods to manage the instance used |
29 // by the post_task.h API. Note: all base/task_scheduler users should go through | 30 // by the post_task.h API. Note: all base/task_scheduler users should go through |
30 // post_task.h instead of TaskScheduler except for the one callsite per process | 31 // post_task.h instead of TaskScheduler except for the one callsite per process |
31 // which manages the process' instance. | 32 // which manages the process' instance. |
32 class BASE_EXPORT TaskScheduler { | 33 class BASE_EXPORT TaskScheduler { |
33 public: | 34 public: |
34 // Returns the index of the worker pool in which a task with |traits| should | 35 // Returns the index of the worker pool in which a task with |traits| should |
35 // run. This should be coded in a future-proof way: new traits should | 36 // run. This should be coded in a future-proof way: new traits should |
36 // gracefully map to a default pool. | 37 // gracefully map to a default pool. |
37 using WorkerPoolIndexForTraitsCallback = | 38 using WorkerPoolIndexForTraitsCallback = |
38 Callback<size_t(const TaskTraits& traits)>; | 39 Callback<size_t(const TaskTraits& traits)>; |
39 | 40 |
40 virtual ~TaskScheduler() = default; | 41 virtual ~TaskScheduler() = default; |
41 | 42 |
42 // Posts |task| with specific |traits|. | 43 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero. |
43 // For one off tasks that don't require a TaskRunner. | 44 // For one off tasks that don't require a TaskRunner. |
44 virtual void PostTaskWithTraits(const tracked_objects::Location& from_here, | 45 virtual void PostDelayedTaskWithTraits( |
45 const TaskTraits& traits, | 46 const tracked_objects::Location& from_here, |
46 const Closure& task) = 0; | 47 const TaskTraits& traits, |
| 48 const Closure& task, |
| 49 TimeDelta delay) = 0; |
47 | 50 |
48 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks | 51 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks |
49 // using |traits|. Tasks may run in any order and in parallel. | 52 // using |traits|. Tasks may run in any order and in parallel. |
50 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 53 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
51 const TaskTraits& traits) = 0; | 54 const TaskTraits& traits) = 0; |
52 | 55 |
53 // Returns a SequencedTaskRunner whose PostTask invocations result in | 56 // Returns a SequencedTaskRunner whose PostTask invocations result in |
54 // scheduling tasks using |traits|. Tasks run one at a time in posting order. | 57 // scheduling tasks using |traits|. Tasks run one at a time in posting order. |
55 virtual scoped_refptr<SequencedTaskRunner> | 58 virtual scoped_refptr<SequencedTaskRunner> |
56 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits) = 0; | 59 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits) = 0; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 113 |
111 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or | 114 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or |
112 // SetInstance(). This should be used very rarely; most users of TaskScheduler | 115 // SetInstance(). This should be used very rarely; most users of TaskScheduler |
113 // should use the post_task.h API. | 116 // should use the post_task.h API. |
114 static TaskScheduler* GetInstance(); | 117 static TaskScheduler* GetInstance(); |
115 }; | 118 }; |
116 | 119 |
117 } // namespace base | 120 } // namespace base |
118 | 121 |
119 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 122 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
OLD | NEW |