Chromium Code Reviews| 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" | |
| 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. |delayed_run_time| is the time | 26 // to run. |traits| is metadata about the task. |delayed_run_time| is the time |
| 23 // at which the task should be run (null TimeTicks if the task can run | 27 // at which the task should be run (null TimeTicks if the task can run |
| 24 // immediately). | 28 // immediately). |
| 25 Task(const tracked_objects::Location& posted_from, | 29 Task(const tracked_objects::Location& posted_from, |
| 26 const Closure& task, | 30 const Closure& task, |
| 27 const TaskTraits& traits, | 31 const TaskTraits& traits, |
| 28 const TimeTicks& delayed_run_time); | 32 const TimeTicks& delayed_run_time); |
| 29 ~Task(); | 33 ~Task(); |
| 30 | 34 |
| 31 // The TaskTraits of this task. | 35 // The TaskTraits of this task. |
| 32 const TaskTraits traits; | 36 const TaskTraits traits; |
| 33 | 37 |
| 34 // 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 |
| 35 // 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 |
| 36 // 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 |
| 37 // in a sequence yet, this defaults to a null TimeTicks. | 41 // in a sequence yet, this defaults to a null TimeTicks. |
| 38 TimeTicks sequenced_time; | 42 TimeTicks sequenced_time; |
| 43 | |
| 44 // A reference to the SequencedTaskRunner or SingleThreadedTaskRunner that | |
| 45 // posted this task, if any. Used to set ThreadTaskRunnerHandle and/or | |
| 46 // SequencedTaskRunnerHandle while the task is running. | |
| 47 scoped_refptr<SequencedTaskRunner> sequenced_task_runner_ref; | |
| 48 scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner_ref; | |
|
fdoray
2016/04/22 14:43:12
Should we comment about the ownership cycle that t
gab
2016/04/25 18:31:52
Done, this cycle is okay (and in fact required) as
fdoray
2016/04/25 18:53:27
We could easily make a change that creates a memor
gab
2016/04/26 11:54:57
Ah I see, shall we add a DCHECK(IsEmpty()) in Sequ
gab
2016/04/26 21:20:20
ping to keep this question on our mind, WDYT?
fdoray
2016/04/27 18:11:20
It's a good idea, but it doesn't solve the problem
gab
2016/04/27 20:21:40
Ah right, that's not such a great idea actually si
| |
| 49 | |
| 50 private: | |
| 51 // Disallow copies to make sure no unecessary ref-bumps are incurred. Making | |
| 52 // it move-only would be an option, but isn't necessary for now. | |
| 53 DISALLOW_COPY_AND_ASSIGN(Task); | |
| 39 }; | 54 }; |
| 40 | 55 |
| 41 } // namespace internal | 56 } // namespace internal |
| 42 } // namespace base | 57 } // namespace base |
| 43 | 58 |
| 44 #endif // BASE_TASK_SCHEDULER_TASK_H_ | 59 #endif // BASE_TASK_SCHEDULER_TASK_H_ |
| OLD | NEW |