Upload upstream chromium 94.0.4606.31
[platform/framework/web/chromium-efl.git] / base / pending_task.h
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.
4
5 #ifndef BASE_PENDING_TASK_H_
6 #define BASE_PENDING_TASK_H_
7
8 #include <array>
9
10 #include "base/base_export.h"
11 #include "base/callback.h"
12 #include "base/location.h"
13 #include "base/time/time.h"
14
15 namespace base {
16
17 enum class Nestable : uint8_t {
18   kNonNestable,
19   kNestable,
20 };
21
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 {
25   PendingTask();
26   PendingTask(const Location& posted_from, OnceClosure task);
27   PendingTask(const Location& posted_from,
28               OnceClosure task,
29               TimeTicks queue_time,
30               TimeTicks delayed_run_time);
31   PendingTask(PendingTask&& other);
32   ~PendingTask();
33
34   PendingTask& operator=(PendingTask&& other);
35
36   // Used to support sorting.
37   bool operator<(const PendingTask& other) const;
38
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;
42
43   // The task to run.
44   OnceClosure task;
45
46   // The site this PendingTask was posted from.
47   Location posted_from;
48
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.
55   TimeTicks queue_time;
56
57   // The time when the task should be run. This is null for an immediate task.
58   base::TimeTicks delayed_run_time;
59
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 = {};
63
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;
73
74   // Secondary sort key for run time.
75   int sequence_num = 0;
76
77   bool task_backtrace_overflow = false;
78 };
79
80 }  // namespace base
81
82 #endif  // BASE_PENDING_TASK_H_