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

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

Issue 2873453002: Add base::TaskTraits::Override(). (Closed)
Patch Set: self-review Created 3 years, 7 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_TRAITS_H_ 5 #ifndef BASE_TASK_SCHEDULER_TASK_TRAITS_H_
6 #define BASE_TASK_SCHEDULER_TASK_TRAITS_H_ 6 #define BASE_TASK_SCHEDULER_TASK_TRAITS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <iosfwd> 10 #include <iosfwd>
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 template <class... ArgTypes, 150 template <class... ArgTypes,
151 class CheckArgumentsAreValid = internal::InitTypes< 151 class CheckArgumentsAreValid = internal::InitTypes<
152 decltype(ValidTrait(std::declval<ArgTypes>()))...>> 152 decltype(ValidTrait(std::declval<ArgTypes>()))...>>
153 constexpr TaskTraits(ArgTypes... args) 153 constexpr TaskTraits(ArgTypes... args)
154 : priority_set_explicitly_( 154 : priority_set_explicitly_(
155 internal::HasArgOfType<base::TaskPriority, ArgTypes...>::value), 155 internal::HasArgOfType<base::TaskPriority, ArgTypes...>::value),
156 priority_(internal::GetValueFromArgList( 156 priority_(internal::GetValueFromArgList(
157 internal::EnumArgGetter<base::TaskPriority, 157 internal::EnumArgGetter<base::TaskPriority,
158 base::TaskPriority::USER_VISIBLE>(), 158 base::TaskPriority::USER_VISIBLE>(),
159 args...)), 159 args...)),
160 shutdown_behavior_set_explicitly_(
161 internal::HasArgOfType<base::TaskShutdownBehavior,
162 ArgTypes...>::value),
160 shutdown_behavior_(internal::GetValueFromArgList( 163 shutdown_behavior_(internal::GetValueFromArgList(
161 internal::EnumArgGetter< 164 internal::EnumArgGetter<
162 base::TaskShutdownBehavior, 165 base::TaskShutdownBehavior,
163 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN>(), 166 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN>(),
164 args...)), 167 args...)),
165 may_block_(internal::GetValueFromArgList( 168 may_block_(internal::GetValueFromArgList(
166 internal::BooleanArgGetter<base::MayBlock>(), 169 internal::BooleanArgGetter<base::MayBlock>(),
167 args...)), 170 args...)),
168 with_base_sync_primitives_(internal::GetValueFromArgList( 171 with_base_sync_primitives_(internal::GetValueFromArgList(
169 internal::BooleanArgGetter<base::WithBaseSyncPrimitives>(), 172 internal::BooleanArgGetter<base::WithBaseSyncPrimitives>(),
170 args...)) {} 173 args...)) {}
171 174
172 constexpr TaskTraits(const TaskTraits& other) = default; 175 constexpr TaskTraits(const TaskTraits& other) = default;
173 TaskTraits& operator=(const TaskTraits& other) = default; 176 TaskTraits& operator=(const TaskTraits& other) = default;
174 177
178 // Returns TaskTraits constructed by merging |left| and |right|. If a trait is
179 // specified in both |left| and |right|, the returned TaskTraits will have the
180 // value from |right|.
181 static constexpr TaskTraits Merge(const TaskTraits& left,
gab 2017/05/09 14:32:31 s/Merge/Override/ as discussed.
fdoray 2017/05/09 14:58:33 Done.
182 const TaskTraits& right) {
183 return TaskTraits(left, right);
184 }
185
175 // Deprecated. Prefer constexpr construction to builder paradigm as 186 // Deprecated. Prefer constexpr construction to builder paradigm as
176 // documented above. 187 // documented above.
177 // TODO(fdoray): Remove these methods. https://crbug.com/713683 188 // TODO(fdoray): Remove these methods. https://crbug.com/713683
178 TaskTraits& WithPriority(TaskPriority priority); 189 TaskTraits& WithPriority(TaskPriority priority);
179 TaskTraits& WithShutdownBehavior(TaskShutdownBehavior shutdown_behavior); 190 TaskTraits& WithShutdownBehavior(TaskShutdownBehavior shutdown_behavior);
180 TaskTraits& MayBlock(); 191 TaskTraits& MayBlock();
181 TaskTraits& WithBaseSyncPrimitives(); 192 TaskTraits& WithBaseSyncPrimitives();
182 193
183 // Returns true if the priority was set explicitly. 194 // Returns true if the priority was set explicitly.
184 constexpr bool priority_set_explicitly() const { 195 constexpr bool priority_set_explicitly() const {
(...skipping 10 matching lines...) Expand all
195 206
196 // Returns true if tasks with these traits may block. 207 // Returns true if tasks with these traits may block.
197 constexpr bool may_block() const { return may_block_; } 208 constexpr bool may_block() const { return may_block_; }
198 209
199 // Returns true if tasks with these traits may use base/ sync primitives. 210 // Returns true if tasks with these traits may use base/ sync primitives.
200 constexpr bool with_base_sync_primitives() const { 211 constexpr bool with_base_sync_primitives() const {
201 return with_base_sync_primitives_; 212 return with_base_sync_primitives_;
202 } 213 }
203 214
204 private: 215 private:
216 constexpr TaskTraits(const TaskTraits& left, const TaskTraits& right)
217 : priority_set_explicitly_(left.priority_set_explicitly_ ||
218 right.priority_set_explicitly_),
219 priority_(right.priority_set_explicitly_ ? right.priority_
220 : left.priority_),
221 shutdown_behavior_set_explicitly_(
222 left.shutdown_behavior_set_explicitly_ ||
223 right.shutdown_behavior_set_explicitly_),
224 shutdown_behavior_(right.shutdown_behavior_set_explicitly_
225 ? right.shutdown_behavior_
226 : left.shutdown_behavior_),
227 may_block_(left.may_block_ || right.may_block_),
228 with_base_sync_primitives_(left.with_base_sync_primitives_ ||
229 right.with_base_sync_primitives_) {}
230
205 // TODO(fdoray): Make these const after refactoring away deprecated builder 231 // TODO(fdoray): Make these const after refactoring away deprecated builder
206 // pattern. 232 // pattern.
gab 2017/05/09 14:32:31 drive-by thought: Actually, this TODO will not be
fdoray 2017/05/09 14:58:33 Acknowledged. TODO removed by upcoming CL.
207 bool priority_set_explicitly_; 233 bool priority_set_explicitly_;
208 TaskPriority priority_; 234 TaskPriority priority_;
235 bool shutdown_behavior_set_explicitly_;
209 TaskShutdownBehavior shutdown_behavior_; 236 TaskShutdownBehavior shutdown_behavior_;
210 bool may_block_; 237 bool may_block_;
211 bool with_base_sync_primitives_; 238 bool with_base_sync_primitives_;
212 }; 239 };
213 240
214 // Returns string literals for the enums defined in this file. These methods 241 // Returns string literals for the enums defined in this file. These methods
215 // should only be used for tracing and debugging. 242 // should only be used for tracing and debugging.
216 BASE_EXPORT const char* TaskPriorityToString(TaskPriority task_priority); 243 BASE_EXPORT const char* TaskPriorityToString(TaskPriority task_priority);
217 BASE_EXPORT const char* TaskShutdownBehaviorToString( 244 BASE_EXPORT const char* TaskShutdownBehaviorToString(
218 TaskShutdownBehavior task_priority); 245 TaskShutdownBehavior task_priority);
219 246
220 // Stream operators so that the enums defined in this file can be used in 247 // Stream operators so that the enums defined in this file can be used in
221 // DCHECK and EXPECT statements. 248 // DCHECK and EXPECT statements.
222 BASE_EXPORT std::ostream& operator<<(std::ostream& os, 249 BASE_EXPORT std::ostream& operator<<(std::ostream& os,
223 const TaskPriority& shutdown_behavior); 250 const TaskPriority& shutdown_behavior);
224 BASE_EXPORT std::ostream& operator<<( 251 BASE_EXPORT std::ostream& operator<<(
225 std::ostream& os, 252 std::ostream& os,
226 const TaskShutdownBehavior& shutdown_behavior); 253 const TaskShutdownBehavior& shutdown_behavior);
227 254
228 } // namespace base 255 } // namespace base
229 256
230 #endif // BASE_TASK_SCHEDULER_TASK_TRAITS_H_ 257 #endif // BASE_TASK_SCHEDULER_TASK_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698