1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_PENDING_TASK_H_
6 #define BASE_PENDING_TASK_H_
10 #include "base/base_export.h"
11 #include "base/callback.h"
12 #include "base/location.h"
13 #include "base/time/time.h"
17 enum class Nestable : uint8_t {
22 // Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue
23 // for use by classes that queue and execute tasks.
24 struct BASE_EXPORT PendingTask {
26 PendingTask(const Location& posted_from, OnceClosure task);
27 PendingTask(const Location& posted_from,
30 TimeTicks delayed_run_time);
31 PendingTask(PendingTask&& other);
34 PendingTask& operator=(PendingTask&& other);
36 // Used to support sorting.
37 bool operator<(const PendingTask& other) const;
39 // Returns the time at which this task should run. This is |delayed_run_time|
40 // for a delayed task, |queue_time| otherwise.
41 base::TimeTicks GetDesiredExecutionTime() const;
46 // The site this PendingTask was posted from.
49 // The time at which the task was queued, which happens at post time. For
50 // deferred non-nestable tasks, this is reset when the nested loop exits and
51 // the deferred tasks are pushed back at the front of the queue. This is not
52 // set for immediate SequenceManager tasks unless SetAddQueueTimeToTasks(true)
53 // was called. This defaults to a null TimeTicks if the task hasn't been
54 // inserted in a sequence yet.
57 // The time when the task should be run. This is null for an immediate task.
58 base::TimeTicks delayed_run_time;
60 // Chain of symbols of the parent tasks which led to this one being posted.
61 static constexpr size_t kTaskBacktraceLength = 4;
62 std::array<const void*, kTaskBacktraceLength> task_backtrace = {};
64 // The context of the IPC message that was being handled when this task was
65 // posted. This is a hash of the IPC message name that is set within the scope
66 // of an IPC handler and when symbolized uniquely identifies the message being
67 // processed. This property is not propagated from one PendingTask to the
68 // next. For example, if pending task A was posted while handling an IPC,
69 // and pending task B was posted from within pending task A, then pending task
70 // B will not inherit the |ipc_hash| of pending task A.
71 uint32_t ipc_hash = 0;
72 const char* ipc_interface_name = nullptr;
74 // Secondary sort key for run time.
77 bool task_backtrace_overflow = false;
82 #endif // BASE_PENDING_TASK_H_