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

Side by Side 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, 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_H_ 5 #ifndef BASE_TASK_SCHEDULER_TASK_H_
6 #define BASE_TASK_SCHEDULER_TASK_H_ 6 #define BASE_TASK_SCHEDULER_TASK_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/callback_forward.h" 9 #include "base/callback_forward.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
11 #include "base/pending_task.h" 13 #include "base/pending_task.h"
14 #include "base/sequenced_task_runner.h"
15 #include "base/single_thread_task_runner.h"
12 #include "base/task_scheduler/task_traits.h" 16 #include "base/task_scheduler/task_traits.h"
13 #include "base/time/time.h" 17 #include "base/time/time.h"
14 18
15 namespace base { 19 namespace base {
16 namespace internal { 20 namespace internal {
17 21
18 // A task is a unit of work inside the task scheduler. Support for tracing and 22 // A task is a unit of work inside the task scheduler. Support for tracing and
19 // profiling inherited from PendingTask. 23 // profiling inherited from PendingTask.
20 struct BASE_EXPORT Task : public PendingTask { 24 struct BASE_EXPORT Task : public PendingTask {
21 // |posted_from| is the site the task was posted from. |task| is the closure 25 // |posted_from| is the site the task was posted from. |task| is the closure
22 // to run. |traits| is metadata about the task. |delay| is a delay that must 26 // to run. |traits| is metadata about the task. |delay| is a delay that must
23 // expire before the Task runs. 27 // expire before the Task runs.
24 Task(const tracked_objects::Location& posted_from, 28 Task(const tracked_objects::Location& posted_from,
25 const Closure& task, 29 const Closure& task,
26 const TaskTraits& traits, 30 const TaskTraits& traits,
27 const TimeDelta& delay); 31 const TimeDelta& delay);
28 ~Task(); 32 ~Task();
29 33
30 // The TaskTraits of this task. 34 // The TaskTraits of this task.
31 const TaskTraits traits; 35 const TaskTraits traits;
32 36
33 // The time at which the task was inserted in its sequence. For an undelayed 37 // The time at which the task was inserted in its sequence. For an undelayed
34 // task, this happens at post time. For a delayed task, this happens some 38 // task, this happens at post time. For a delayed task, this happens some
35 // time after the task's delay has expired. If the task hasn't been inserted 39 // time after the task's delay has expired. If the task hasn't been inserted
36 // in a sequence yet, this defaults to a null TimeTicks. 40 // in a sequence yet, this defaults to a null TimeTicks.
37 TimeTicks sequenced_time; 41 TimeTicks sequenced_time;
42
43 // A reference to the SequencedTaskRunner or SingleThreadTaskRunner that
44 // posted this task, if any. Used to set ThreadTaskRunnerHandle and/or
45 // SequencedTaskRunnerHandle while the task is running.
46 // Note: this creates an ownership cycle
47 // Sequence -> Task -> TaskRunner -> Sequence -> ...
48 // but that's okay as it's broken when the Task is popped from its Sequence
49 // after being executed which means this cycle forces the TaskRunner to stick
50 // around until all its tasks have been executed which is a requirement to
51 // support TaskRunnerHandles.
52 scoped_refptr<SequencedTaskRunner> sequenced_task_runner_ref;
53 scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner_ref;
54
55 private:
56 // Disallow copies to make sure no unnecessary ref-bumps are incurred. Making
57 // it move-only would be an option, but isn't necessary for now.
58 DISALLOW_COPY_AND_ASSIGN(Task);
38 }; 59 };
39 60
40 } // namespace internal 61 } // namespace internal
41 } // namespace base 62 } // namespace base
42 63
43 #endif // BASE_TASK_SCHEDULER_TASK_H_ 64 #endif // BASE_TASK_SCHEDULER_TASK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698