| 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 <string> | |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 12 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 13 #include "base/callback.h" | 12 #include "base/callback.h" |
| 14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 15 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 16 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_piece.h" |
| 17 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
| 18 #include "base/task_scheduler/scheduler_worker_pool_params.h" | 18 #include "base/task_scheduler/scheduler_worker_pool_params.h" |
| 19 #include "base/task_scheduler/task_traits.h" | 19 #include "base/task_scheduler/task_traits.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 | 22 |
| 23 namespace gin { | 23 namespace gin { |
| 24 class V8Platform; | 24 class V8Platform; |
| 25 } | 25 } |
| 26 | 26 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // The methods must not be called when TaskRunners created by the previous | 130 // The methods must not be called when TaskRunners created by the previous |
| 131 // TaskScheduler are still alive. The methods are not thread-safe; proper | 131 // TaskScheduler are still alive. The methods are not thread-safe; proper |
| 132 // synchronization is required to use the post_task.h API after registering a | 132 // synchronization is required to use the post_task.h API after registering a |
| 133 // new TaskScheduler. | 133 // new TaskScheduler. |
| 134 | 134 |
| 135 #if !defined(OS_NACL) | 135 #if !defined(OS_NACL) |
| 136 // Creates and sets a task scheduler using default params. |name| is used to | 136 // Creates and sets a task scheduler using default params. |name| is used to |
| 137 // label threads and histograms. It should identify the component that calls | 137 // label threads and histograms. It should identify the component that calls |
| 138 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler | 138 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler |
| 139 // (ensures isolation). | 139 // (ensures isolation). |
| 140 static void CreateAndSetSimpleTaskScheduler(const std::string& name); | 140 static void CreateAndSetSimpleTaskScheduler(StringPiece name); |
| 141 #endif // !defined(OS_NACL) | 141 #endif // !defined(OS_NACL) |
| 142 | 142 |
| 143 // Creates and sets a task scheduler using custom params. |name| is used to | 143 // Creates and sets a task scheduler using custom params. |name| is used to |
| 144 // label threads and histograms. It should identify the component that creates | 144 // label threads and histograms. It should identify the component that creates |
| 145 // the TaskScheduler. |init_params| is used to initialize the worker pools. | 145 // the TaskScheduler. |init_params| is used to initialize the worker pools. |
| 146 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler | 146 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler |
| 147 // (ensures isolation). | 147 // (ensures isolation). |
| 148 // | 148 // |
| 149 // Note: The names and priority hints in |init_params| are ignored (ref. TODO | 149 // Note: The names and priority hints in |init_params| are ignored (ref. TODO |
| 150 // to remove them). | 150 // to remove them). |
| 151 static void CreateAndSetDefaultTaskScheduler(const std::string& name, | 151 static void CreateAndSetDefaultTaskScheduler(StringPiece name, |
| 152 const InitParams& init_params); | 152 const InitParams& init_params); |
| 153 | 153 |
| 154 // Registers |task_scheduler| to handle tasks posted through the post_task.h | 154 // Registers |task_scheduler| to handle tasks posted through the post_task.h |
| 155 // API for this process. For tests, prefer base::test::ScopedTaskScheduler | 155 // API for this process. For tests, prefer base::test::ScopedTaskScheduler |
| 156 // (ensures isolation). | 156 // (ensures isolation). |
| 157 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); | 157 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); |
| 158 | 158 |
| 159 // Retrieve the TaskScheduler set via SetInstance() or | 159 // Retrieve the TaskScheduler set via SetInstance() or |
| 160 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very | 160 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very |
| 161 // rarely; most users of TaskScheduler should use the post_task.h API. In | 161 // rarely; most users of TaskScheduler should use the post_task.h API. In |
| (...skipping 18 matching lines...) Expand all Loading... |
| 180 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. | 180 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. |
| 181 // | 181 // |
| 182 // TODO(fdoray): Remove this method. https://crbug.com/687264 | 182 // TODO(fdoray): Remove this method. https://crbug.com/687264 |
| 183 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( | 183 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( |
| 184 const TaskTraits& traits) const = 0; | 184 const TaskTraits& traits) const = 0; |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 } // namespace base | 187 } // namespace base |
| 188 | 188 |
| 189 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 189 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
| OLD | NEW |