| 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" |
| 15 #include "base/single_thread_task_runner.h" |
| 14 #include "base/task_runner.h" | 16 #include "base/task_runner.h" |
| 15 #include "base/task_scheduler/task_traits.h" | 17 #include "base/task_scheduler/task_traits.h" |
| 16 | 18 |
| 17 namespace tracked_objects { | 19 namespace tracked_objects { |
| 18 class Location; | 20 class Location; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace base { | 23 namespace base { |
| 22 | 24 |
| 23 class HistogramBase; | 25 class HistogramBase; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 36 Callback<size_t(const TaskTraits& traits)>; | 38 Callback<size_t(const TaskTraits& traits)>; |
| 37 | 39 |
| 38 virtual ~TaskScheduler() = default; | 40 virtual ~TaskScheduler() = default; |
| 39 | 41 |
| 40 // Posts |task| with specific |traits|. | 42 // Posts |task| with specific |traits|. |
| 41 // For one off tasks that don't require a TaskRunner. | 43 // For one off tasks that don't require a TaskRunner. |
| 42 virtual void PostTaskWithTraits(const tracked_objects::Location& from_here, | 44 virtual void PostTaskWithTraits(const tracked_objects::Location& from_here, |
| 43 const TaskTraits& traits, | 45 const TaskTraits& traits, |
| 44 const Closure& task) = 0; | 46 const Closure& task) = 0; |
| 45 | 47 |
| 46 // Returns a TaskRunner whose PostTask invocations will result in scheduling | 48 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks |
| 47 // Tasks with |traits| which will be executed according to |execution_mode|. | 49 // using |traits|. Tasks may run in any order and in parallel. |
| 48 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 50 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 49 const TaskTraits& traits, | 51 const TaskTraits& traits) = 0; |
| 50 ExecutionMode execution_mode) = 0; | 52 |
| 53 // Returns a SequencedTaskRunner whose PostTask invocations result in |
| 54 // scheduling tasks using |traits|. Tasks run one at a time in posting order. |
| 55 virtual scoped_refptr<SequencedTaskRunner> |
| 56 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits) = 0; |
| 57 |
| 58 // Returns a SingleThreadTaskRunner whose PostTask invocations result in |
| 59 // scheduling tasks using |traits|. Tasks run on a single thread in posting |
| 60 // order. |
| 61 virtual scoped_refptr<SingleThreadTaskRunner> |
| 62 CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits) = 0; |
| 51 | 63 |
| 52 // Returns a vector of all histograms available in this task scheduler. | 64 // Returns a vector of all histograms available in this task scheduler. |
| 53 virtual std::vector<const HistogramBase*> GetHistograms() const = 0; | 65 virtual std::vector<const HistogramBase*> GetHistograms() const = 0; |
| 54 | 66 |
| 55 // Synchronously shuts down the scheduler. Once this is called, only tasks | 67 // Synchronously shuts down the scheduler. Once this is called, only tasks |
| 56 // posted with the BLOCK_SHUTDOWN behavior will be run. When this returns: | 68 // posted with the BLOCK_SHUTDOWN behavior will be run. When this returns: |
| 57 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their | 69 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their |
| 58 // execution. | 70 // execution. |
| 59 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. | 71 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. |
| 60 // - CONTINUE_ON_SHUTDOWN tasks might still be running. | 72 // - CONTINUE_ON_SHUTDOWN tasks might still be running. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 105 |
| 94 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or | 106 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or |
| 95 // SetInstance(). This should be used very rarely; most users of TaskScheduler | 107 // SetInstance(). This should be used very rarely; most users of TaskScheduler |
| 96 // should use the post_task.h API. | 108 // should use the post_task.h API. |
| 97 static TaskScheduler* GetInstance(); | 109 static TaskScheduler* GetInstance(); |
| 98 }; | 110 }; |
| 99 | 111 |
| 100 } // namespace base | 112 } // namespace base |
| 101 | 113 |
| 102 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 114 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
| OLD | NEW |