OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
| 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
| 7 |
| 8 #include "base/base_export.h" |
| 9 #include "base/callback_forward.h" |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/task_runner.h" |
| 14 #include "base/task_scheduler/task_traits.h" |
| 15 |
| 16 namespace tracked_objects { |
| 17 class Location; |
| 18 } |
| 19 |
| 20 namespace base { |
| 21 |
| 22 class BASE_EXPORT TaskScheduler { |
| 23 public: |
| 24 // Posts |task| with specific |traits|. |
| 25 // For one off tasks that don't require a TaskRunner. |
| 26 virtual void PostTaskWithTraits(const tracked_objects::Location& from_here, |
| 27 TaskTraits traits, |
| 28 const Closure& task) = 0; |
| 29 |
| 30 // Returns a TaskRunner whose PostTask invocations will result in scheduling |
| 31 // tasks using |traits| which will be executed according to |execution_mode|. |
| 32 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 33 TaskTraits traits, |
| 34 ExecutionMode execution_mode) = 0; |
| 35 |
| 36 // Performs a synchronous cleanup of threads and state in the TaskScheduler. |
| 37 virtual void Shutdown() = 0; |
| 38 |
| 39 // Registers |task_scheduler| to handle tasks posted through the post_task.h |
| 40 // API for this process. Must be called on the main thread before creating any |
| 41 // other threads. Replacing an existing TaskScheduler is not supported (this |
| 42 // may not be called after InitializeDefaultTaskScheduler() or SetInstance() |
| 43 // was already called in this process). |
| 44 static void SetInstance(scoped_ptr<TaskScheduler> task_scheduler); |
| 45 |
| 46 // Retrieve the TaskScheduler set via SetInstance(). This should be used very |
| 47 // rarely; most users of TaskScheduler should use the post_task.h API. |
| 48 static TaskScheduler* GetInstance(); |
| 49 |
| 50 // Initializes the default task scheduler for this process. Must be called on |
| 51 // the main thread before creating any other threads. Replacing an existing |
| 52 // TaskScheduler is not supported (this may not be called after |
| 53 // InitializeDefaultTaskScheduler() or SetInstance() was already called in |
| 54 // this process). |
| 55 static void InitializeDefaultTaskScheduler(); |
| 56 |
| 57 virtual ~TaskScheduler() = default; |
| 58 }; |
| 59 |
| 60 } // namespace base |
| 61 |
| 62 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
OLD | NEW |