1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TASK_THREAD_POOL_TASK_H_ 6 #define BASE_TASK_THREAD_POOL_TASK_H_ 7 8 #include "base/base_export.h" 9 #include "base/containers/intrusive_heap.h" 10 #include "base/functional/callback.h" 11 #include "base/location.h" 12 #include "base/pending_task.h" 13 #include "base/task/sequenced_task_runner.h" 14 #include "base/task/single_thread_task_runner.h" 15 #include "base/time/time.h" 16 17 namespace base { 18 namespace internal { 19 20 // A task is a unit of work inside the thread pool. Support for tracing and 21 // profiling inherited from PendingTask. 22 // TODO(etiennep): This class is now equivalent to PendingTask, remove it. 23 struct BASE_EXPORT Task : public PendingTask { 24 Task() = default; 25 26 // |posted_from| is the site the task was posted from. |task| is the closure 27 // to run. |delay| is a delay that must expire before the Task runs. 28 Task(const Location& posted_from, 29 OnceClosure task, 30 TimeTicks queue_time, 31 TimeDelta delay, 32 TimeDelta leeway = TimeDelta(), 33 int sequence_num = 0); 34 // |delayed_run_time| is the time when the task should be run. 35 Task( 36 const Location& posted_from, 37 OnceClosure task, 38 TimeTicks queue_time, 39 TimeTicks delayed_run_time, 40 TimeDelta leeway = TimeDelta(), 41 subtle::DelayPolicy delay_policy = subtle::DelayPolicy::kFlexibleNoSooner, 42 int sequence_num = 0); 43 Task(const TaskMetadata& metadata, OnceClosure task); 44 45 // Task is move-only to avoid mistakes that cause reference counts to be 46 // accidentally bumped. 47 Task(Task&& other) noexcept; 48 49 Task(const Task&) = delete; 50 Task& operator=(const Task&) = delete; 51 52 ~Task() = default; 53 54 Task& operator=(Task&& other); 55 56 // Required by IntrusiveHeap. SetHeapHandleTask57 void SetHeapHandle(const HeapHandle& handle) {} 58 59 // Required by IntrusiveHeap. ClearHeapHandleTask60 void ClearHeapHandle() {} 61 62 // Required by IntrusiveHeap. GetHeapHandleTask63 HeapHandle GetHeapHandle() const { return HeapHandle::Invalid(); } 64 }; 65 66 } // namespace internal 67 } // namespace base 68 69 #endif // BASE_TASK_THREAD_POOL_TASK_H_ 70