Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: base/task_scheduler/task_scheduler.h

Issue 2809163003: Always use TaskScheduler::InitParams to initialize a TaskScheduler. (Closed)
Patch Set: fix-build-error Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 const SchedulerWorkerPoolParams& 47 const SchedulerWorkerPoolParams&
48 foreground_blocking_worker_pool_params_in); 48 foreground_blocking_worker_pool_params_in);
49 ~InitParams(); 49 ~InitParams();
50 50
51 const SchedulerWorkerPoolParams background_worker_pool_params; 51 const SchedulerWorkerPoolParams background_worker_pool_params;
52 const SchedulerWorkerPoolParams background_blocking_worker_pool_params; 52 const SchedulerWorkerPoolParams background_blocking_worker_pool_params;
53 const SchedulerWorkerPoolParams foreground_worker_pool_params; 53 const SchedulerWorkerPoolParams foreground_worker_pool_params;
54 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params; 54 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params;
55 }; 55 };
56 56
57 // Returns the index of the worker pool in which a task with |traits| should
58 // run. This should be coded in a future-proof way: new traits should
59 // gracefully map to a default pool.
60 using WorkerPoolIndexForTraitsCallback =
61 Callback<size_t(const TaskTraits& traits)>;
62
63 // Destroying a TaskScheduler is not allowed in production; it is always 57 // Destroying a TaskScheduler is not allowed in production; it is always
64 // leaked. In tests, it should only be destroyed after JoinForTesting() has 58 // leaked. In tests, it should only be destroyed after JoinForTesting() has
65 // returned. 59 // returned.
66 virtual ~TaskScheduler() = default; 60 virtual ~TaskScheduler() = default;
67 61
68 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero. 62 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero.
69 // For one off tasks that don't require a TaskRunner. 63 // For one off tasks that don't require a TaskRunner.
70 virtual void PostDelayedTaskWithTraits( 64 virtual void PostDelayedTaskWithTraits(
71 const tracked_objects::Location& from_here, 65 const tracked_objects::Location& from_here,
72 const TaskTraits& traits, 66 const TaskTraits& traits,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // new TaskScheduler. 133 // new TaskScheduler.
140 134
141 #if !defined(OS_NACL) 135 #if !defined(OS_NACL)
142 // 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
143 // label threads and histograms. It should identify the component that calls 137 // label threads and histograms. It should identify the component that calls
144 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler 138 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler
145 // (ensures isolation). 139 // (ensures isolation).
146 static void CreateAndSetSimpleTaskScheduler(const std::string& name); 140 static void CreateAndSetSimpleTaskScheduler(const std::string& name);
147 #endif // !defined(OS_NACL) 141 #endif // !defined(OS_NACL)
148 142
149 // Creates and sets a task scheduler with custom worker pools. CHECKs on
150 // failure. |worker_pool_params_vector| describes the worker pools to create.
151 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools|
152 // of the worker pool in which a task with given traits should run. For tests,
153 // prefer base::test::ScopedTaskScheduler (ensures isolation).
154 //
155 // Deprecated. Use the overload below instead. https://crbug.com/690706
156 static void CreateAndSetDefaultTaskScheduler(
157 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
158 const WorkerPoolIndexForTraitsCallback&
159 worker_pool_index_for_traits_callback);
160
161 // 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
162 // label threads and histograms. It should identify the component that creates 144 // label threads and histograms. It should identify the component that creates
163 // the TaskScheduler. |init_params| is used to initialize the worker pools. 145 // the TaskScheduler. |init_params| is used to initialize the worker pools.
164 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler 146 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler
165 // (ensures isolation). 147 // (ensures isolation).
166 // 148 //
167 // 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
168 // to remove them). 150 // to remove them).
169 static void CreateAndSetDefaultTaskScheduler(const std::string& name, 151 static void CreateAndSetDefaultTaskScheduler(const std::string& name,
170 const InitParams& init_params); 152 const InitParams& init_params);
(...skipping 27 matching lines...) Expand all
198 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 180 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
199 // 181 //
200 // TODO(fdoray): Remove this method. https://crbug.com/687264 182 // TODO(fdoray): Remove this method. https://crbug.com/687264
201 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 183 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
202 const TaskTraits& traits) const = 0; 184 const TaskTraits& traits) const = 0;
203 }; 185 };
204 186
205 } // namespace base 187 } // namespace base
206 188
207 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 189 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_impl.cc ('k') | base/task_scheduler/task_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698