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