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

Unified Diff: base/task_scheduler/task_traits.h

Issue 2873453002: Add base::TaskTraits::Override(). (Closed)
Patch Set: CR-gab 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/task_scheduler/task.cc ('k') | base/task_scheduler/task_traits_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/task_traits.h
diff --git a/base/task_scheduler/task_traits.h b/base/task_scheduler/task_traits.h
index cd1d7ccf3c674a56ff6fc80a94b1d621f2b94ad5..a403a961d47c7d91c268c4774f669281776d72af 100644
--- a/base/task_scheduler/task_traits.h
+++ b/base/task_scheduler/task_traits.h
@@ -157,6 +157,9 @@ class BASE_EXPORT TaskTraits {
internal::EnumArgGetter<base::TaskPriority,
base::TaskPriority::USER_VISIBLE>(),
args...)),
+ shutdown_behavior_set_explicitly_(
+ internal::HasArgOfType<base::TaskShutdownBehavior,
+ ArgTypes...>::value),
shutdown_behavior_(internal::GetValueFromArgList(
internal::EnumArgGetter<
base::TaskShutdownBehavior,
@@ -172,6 +175,14 @@ class BASE_EXPORT TaskTraits {
constexpr TaskTraits(const TaskTraits& other) = default;
TaskTraits& operator=(const TaskTraits& other) = default;
+ // Returns TaskTraits constructed by combining |left| and |right|. If a trait
+ // is specified in both |left| and |right|, the returned TaskTraits will have
+ // the value from |right|.
+ static constexpr TaskTraits Override(const TaskTraits& left,
+ const TaskTraits& right) {
+ return TaskTraits(left, right);
+ }
+
// Deprecated. Prefer constexpr construction to builder paradigm as
// documented above.
// TODO(fdoray): Remove these methods. https://crbug.com/713683
@@ -188,6 +199,11 @@ class BASE_EXPORT TaskTraits {
// Returns the priority of tasks with these traits.
constexpr TaskPriority priority() const { return priority_; }
+ // Returns true if the shutdown behavior was set explicitly.
+ constexpr bool shutdown_behavior_set_explicitly() const {
+ return shutdown_behavior_set_explicitly_;
+ }
+
// Returns the shutdown behavior of tasks with these traits.
constexpr TaskShutdownBehavior shutdown_behavior() const {
return shutdown_behavior_;
@@ -202,10 +218,26 @@ class BASE_EXPORT TaskTraits {
}
private:
+ constexpr TaskTraits(const TaskTraits& left, const TaskTraits& right)
+ : priority_set_explicitly_(left.priority_set_explicitly_ ||
+ right.priority_set_explicitly_),
+ priority_(right.priority_set_explicitly_ ? right.priority_
+ : left.priority_),
+ shutdown_behavior_set_explicitly_(
+ left.shutdown_behavior_set_explicitly_ ||
+ right.shutdown_behavior_set_explicitly_),
+ shutdown_behavior_(right.shutdown_behavior_set_explicitly_
+ ? right.shutdown_behavior_
+ : left.shutdown_behavior_),
+ may_block_(left.may_block_ || right.may_block_),
+ with_base_sync_primitives_(left.with_base_sync_primitives_ ||
+ right.with_base_sync_primitives_) {}
+
// TODO(fdoray): Make these const after refactoring away deprecated builder
// pattern.
bool priority_set_explicitly_;
TaskPriority priority_;
+ bool shutdown_behavior_set_explicitly_;
TaskShutdownBehavior shutdown_behavior_;
bool may_block_;
bool with_base_sync_primitives_;
« no previous file with comments | « base/task_scheduler/task.cc ('k') | base/task_scheduler/task_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698