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/task_runner.h" | 14 #include "base/task_runner.h" |
15 #include "base/task_scheduler/task_traits.h" | 15 #include "base/task_scheduler/task_traits.h" |
16 | 16 |
17 namespace tracked_objects { | 17 namespace tracked_objects { |
18 class Location; | 18 class Location; |
19 } | 19 } |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 | 22 |
| 23 class HistogramBase; |
23 class SchedulerWorkerPoolParams; | 24 class SchedulerWorkerPoolParams; |
24 | 25 |
25 // Interface for a task scheduler and static methods to manage the instance used | 26 // Interface for a task scheduler and static methods to manage the instance used |
26 // by the post_task.h API. Note: all base/task_scheduler users should go through | 27 // by the post_task.h API. Note: all base/task_scheduler users should go through |
27 // post_task.h instead of TaskScheduler except for the one callsite per process | 28 // post_task.h instead of TaskScheduler except for the one callsite per process |
28 // which manages the process' instance. | 29 // which manages the process' instance. |
29 class BASE_EXPORT TaskScheduler { | 30 class BASE_EXPORT TaskScheduler { |
30 public: | 31 public: |
31 // Returns the index of the worker pool in which a task with |traits| should | 32 // Returns the index of the worker pool in which a task with |traits| should |
32 // run. This should be coded in a future-proof way: new traits should | 33 // run. This should be coded in a future-proof way: new traits should |
33 // gracefully map to a default pool. | 34 // gracefully map to a default pool. |
34 using WorkerPoolIndexForTraitsCallback = | 35 using WorkerPoolIndexForTraitsCallback = |
35 Callback<size_t(const TaskTraits& traits)>; | 36 Callback<size_t(const TaskTraits& traits)>; |
36 | 37 |
37 virtual ~TaskScheduler() = default; | 38 virtual ~TaskScheduler() = default; |
38 | 39 |
39 // Posts |task| with specific |traits|. | 40 // Posts |task| with specific |traits|. |
40 // For one off tasks that don't require a TaskRunner. | 41 // For one off tasks that don't require a TaskRunner. |
41 virtual void PostTaskWithTraits(const tracked_objects::Location& from_here, | 42 virtual void PostTaskWithTraits(const tracked_objects::Location& from_here, |
42 const TaskTraits& traits, | 43 const TaskTraits& traits, |
43 const Closure& task) = 0; | 44 const Closure& task) = 0; |
44 | 45 |
45 // Returns a TaskRunner whose PostTask invocations will result in scheduling | 46 // Returns a TaskRunner whose PostTask invocations will result in scheduling |
46 // Tasks with |traits| which will be executed according to |execution_mode|. | 47 // Tasks with |traits| which will be executed according to |execution_mode|. |
47 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 48 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
48 const TaskTraits& traits, | 49 const TaskTraits& traits, |
49 ExecutionMode execution_mode) = 0; | 50 ExecutionMode execution_mode) = 0; |
50 | 51 |
| 52 // Returns a vector of all histograms available in this task scheduler. |
| 53 virtual std::vector<const HistogramBase*> GetHistograms() const = 0; |
| 54 |
51 // Synchronously shuts down the scheduler. Once this is called, only tasks | 55 // Synchronously shuts down the scheduler. Once this is called, only tasks |
52 // posted with the BLOCK_SHUTDOWN behavior will be run. When this returns: | 56 // posted with the BLOCK_SHUTDOWN behavior will be run. When this returns: |
53 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their | 57 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their |
54 // execution. | 58 // execution. |
55 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. | 59 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. |
56 // - CONTINUE_ON_SHUTDOWN tasks might still be running. | 60 // - CONTINUE_ON_SHUTDOWN tasks might still be running. |
57 // Note that an implementation can keep threads and other resources alive to | 61 // Note that an implementation can keep threads and other resources alive to |
58 // support running CONTINUE_ON_SHUTDOWN after this returns. This can only be | 62 // support running CONTINUE_ON_SHUTDOWN after this returns. This can only be |
59 // called once. | 63 // called once. |
60 virtual void Shutdown() = 0; | 64 virtual void Shutdown() = 0; |
(...skipping 28 matching lines...) Expand all Loading... |
89 | 93 |
90 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or | 94 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or |
91 // SetInstance(). This should be used very rarely; most users of TaskScheduler | 95 // SetInstance(). This should be used very rarely; most users of TaskScheduler |
92 // should use the post_task.h API. | 96 // should use the post_task.h API. |
93 static TaskScheduler* GetInstance(); | 97 static TaskScheduler* GetInstance(); |
94 }; | 98 }; |
95 | 99 |
96 } // namespace base | 100 } // namespace base |
97 | 101 |
98 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 102 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
OLD | NEW |