Chromium Code Reviews| 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 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
| 14 #include "base/task_scheduler/task_traits.h" | 14 #include "base/task_scheduler/task_traits.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 | 17 |
| 18 // Interface for a task scheduler and static methods to manage the instance used | 18 // Interface for a task scheduler and static methods to manage the instance used |
| 19 // by the post_task.h API. | 19 // by the post_task.h API. |
| 20 class BASE_EXPORT TaskScheduler { | 20 class BASE_EXPORT TaskScheduler { |
| 21 public: | 21 public: |
| 22 TaskScheduler() = default; | |
|
gab
2016/04/27 19:15:28
Move to previous CL introducing this file?
fdoray
2016/04/28 18:36:32
No longer needed without the DISALLOW_COPY_AND_ASS
| |
| 22 virtual ~TaskScheduler() = default; | 23 virtual ~TaskScheduler() = default; |
| 23 | 24 |
| 24 // Returns a TaskRunner whose PostTask invocations will result in scheduling | 25 // Returns a TaskRunner whose PostTask invocations will result in scheduling |
| 25 // Tasks with |traits| which will be executed according to |execution_mode|. | 26 // Tasks with |traits| which will be executed according to |execution_mode|. |
| 26 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 27 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 27 const TaskTraits& traits, | 28 const TaskTraits& traits, |
| 28 ExecutionMode execution_mode) = 0; | 29 ExecutionMode execution_mode) = 0; |
| 29 | 30 |
| 30 // Synchronously shuts down the scheduler. Once this is called, only tasks | 31 // Synchronously shuts down the scheduler. Once this is called, only tasks |
| 31 // posted with the BLOCK_SHUTDOWN behavior will be run. Returns when: | 32 // posted with the BLOCK_SHUTDOWN behavior will be run. Returns when: |
| 32 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their | 33 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their |
| 33 // execution. | 34 // execution. |
| 34 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. | 35 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. |
| 35 // When this returns, CONTINUE_ON_SHUTDOWN tasks might still be running and | 36 // When this returns, CONTINUE_ON_SHUTDOWN tasks might still be running and |
| 36 // resources owned by the TaskScheduler might not have been released. This | 37 // resources owned by the TaskScheduler might not have been released. This |
| 37 // must only be called once. | 38 // must only be called once. |
| 38 virtual void Shutdown() = 0; | 39 virtual void Shutdown() = 0; |
| 39 | 40 |
| 40 // Registers |task_scheduler| to handle tasks posted through the post_task.h | 41 // Registers |task_scheduler| to handle tasks posted through the post_task.h |
| 41 // API for this process. |task_scheduler| will only be deleted when a new | 42 // API for this process. |task_scheduler| will only be deleted when a new |
| 42 // TaskScheduler is registered. Must be called from the main thread when no | 43 // TaskScheduler is registered. Must be called from the main thread when no |
| 43 // other thread is using the post_task.h API and after all TaskRunners | 44 // other thread is using the post_task.h API and after all TaskRunners |
| 44 // returned by the previous TaskScheduler have been deleted. | 45 // returned by the previous TaskScheduler have been deleted. |
| 45 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); | 46 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); |
| 46 | 47 |
| 47 // Retrieve the TaskScheduler set via SetInstance(). This should be used very | 48 // Retrieve the TaskScheduler set via SetInstance(). This should be used very |
| 48 // rarely; most users of TaskScheduler should use the post_task.h API. | 49 // rarely; most users of TaskScheduler should use the post_task.h API. |
| 49 static TaskScheduler* GetInstance(); | 50 static TaskScheduler* GetInstance(); |
| 50 | 51 |
|
gab
2016/04/27 19:15:28
When you rebase on latest version of this interfac
fdoray
2016/04/28 18:36:32
Done.
| |
| 51 private: | 52 private: |
| 52 DISALLOW_COPY_AND_ASSIGN(TaskScheduler); | 53 DISALLOW_COPY_AND_ASSIGN(TaskScheduler); |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 } // namespace base | 56 } // namespace base |
| 56 | 57 |
| 57 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 58 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
| OLD | NEW |