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

Unified Diff: base/task_scheduler/task.cc

Issue 2383193002: TaskScheduler: Adjust shutdown behavior of delayed tasks. (Closed)
Patch Set: Created 4 years, 3 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
Index: base/task_scheduler/task.cc
diff --git a/base/task_scheduler/task.cc b/base/task_scheduler/task.cc
index 8a589a202186dc2b3404c234e104a856ca57d8dd..812a48fcea468b8932ca966c941484ea03004428 100644
--- a/base/task_scheduler/task.cc
+++ b/base/task_scheduler/task.cc
@@ -7,15 +7,30 @@
namespace base {
namespace internal {
+namespace {
+
+// Changes the shutdown behavior in |traits| to SKIP_ON_SHUTDOWN if |delay| is
+// non-zero and the existing shutdown behavior is BLOCK_SHUTDOWN. This prevents
+// delayed tasks from blocking shutdown before they are scheduled.
+TaskTraits AdjustShutdownBehavior(TaskTraits traits, TimeDelta delay) {
+ return (traits.shutdown_behavior() == TaskShutdownBehavior::BLOCK_SHUTDOWN &&
+ !delay.is_zero())
+ ? traits.WithShutdownBehavior(
+ TaskShutdownBehavior::SKIP_ON_SHUTDOWN)
+ : traits;
+}
+
+} // namespace
+
Task::Task(const tracked_objects::Location& posted_from,
const Closure& task,
const TaskTraits& traits,
- const TimeDelta& delay)
+ TimeDelta delay)
robliao 2016/09/30 18:57:20 This should remain a const ref. AdjustShutdownBeh
fdoray 2016/09/30 19:10:11 No. https://cs.chromium.org/chromium/src/base/time
: PendingTask(posted_from,
task,
delay.is_zero() ? TimeTicks() : TimeTicks::Now() + delay,
false), // Not nestable.
- traits(traits) {}
+ traits(AdjustShutdownBehavior(traits, delay)) {}
gab 2016/09/30 19:01:26 So this potentially results in 3 copies (one to pa
fdoray 2016/09/30 19:10:11 I'll make a new CL that changes TaskTracker instea
Task::~Task() = default;

Powered by Google App Engine
This is Rietveld 408576698