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

Unified Diff: base/task_scheduler/task.h

Issue 1911023002: TaskScheduler: Add TaskRunnerHandle support to TaskScheduler tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@c1_1876363004_STTR
Patch Set: review:fdoray#17 Created 4 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 side-by-side diff with in-line comments
Download patch
Index: base/task_scheduler/task.h
diff --git a/base/task_scheduler/task.h b/base/task_scheduler/task.h
index 010b29d830adcacfad4408798c72abb61f2f6205..2b53c690fddffc752ce63ec98b900a0b34f06674 100644
--- a/base/task_scheduler/task.h
+++ b/base/task_scheduler/task.h
@@ -8,7 +8,11 @@
#include "base/base_export.h"
#include "base/callback_forward.h"
#include "base/location.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
#include "base/pending_task.h"
+#include "base/sequenced_task_runner.h"
+#include "base/single_thread_task_runner.h"
#include "base/task_scheduler/task_traits.h"
#include "base/time/time.h"
@@ -35,6 +39,23 @@ struct BASE_EXPORT Task : public PendingTask {
// time after the task's delay has expired. If the task hasn't been inserted
// in a sequence yet, this defaults to a null TimeTicks.
TimeTicks sequenced_time;
+
+ // A reference to the SequencedTaskRunner or SingleThreadTaskRunner that
+ // posted this task, if any. Used to set ThreadTaskRunnerHandle and/or
+ // SequencedTaskRunnerHandle while the task is running.
+ // Note: this creates an ownership cycle
+ // Sequence -> Task -> TaskRunner -> Sequence -> ...
+ // but that's okay as it's broken when the Task is popped from its Sequence
+ // after being executed which means this cycle forces the TaskRunner to stick
+ // around until all its tasks have been executed which is a requirement to
+ // support TaskRunnerHandles.
+ scoped_refptr<SequencedTaskRunner> sequenced_task_runner_ref;
+ scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner_ref;
+
+ private:
+ // Disallow copies to make sure no unnecessary ref-bumps are incurred. Making
+ // it move-only would be an option, but isn't necessary for now.
+ DISALLOW_COPY_AND_ASSIGN(Task);
};
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698