blob: dc68e26c5b477d5504246f2de992e285a8bd71f4 [file] [log] [blame]
[email protected]dd1f9fe2011-11-15 23:36:301// 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
danakj0a448602015-03-10 00:31:165#ifndef BASE_PENDING_TASK_H_
6#define BASE_PENDING_TASK_H_
[email protected]dd1f9fe2011-11-15 23:36:307
ajwong4f13f742017-02-09 23:52:408#include <array>
[email protected]dd1f9fe2011-11-15 23:36:309
[email protected]c360bae72011-11-18 06:08:0210#include "base/base_export.h"
[email protected]dd1f9fe2011-11-15 23:36:3011#include "base/callback.h"
[email protected]dd1f9fe2011-11-15 23:36:3012#include "base/location.h"
Erik Chena95335192018-07-30 17:48:2213#include "base/optional.h"
[email protected]8f9a3a52013-06-28 15:14:1814#include "base/time/time.h"
[email protected]dd1f9fe2011-11-15 23:36:3015
16namespace base {
17
Alex Clarke1ac1f982019-03-29 08:48:3718enum class Nestable : uint8_t {
Hajime Hoshi64853ef2017-10-11 12:56:0719 kNonNestable,
20 kNestable,
21};
22
[email protected]dd1f9fe2011-11-15 23:36:3023// Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue
24// for use by classes that queue and execute tasks.
Brett Wilsonb57e3dd2017-09-08 00:47:4925struct BASE_EXPORT PendingTask {
Jesse McKenna9cf11372018-11-01 19:38:3826 PendingTask();
Brett Wilson8e88b312017-09-12 05:22:1627 PendingTask(const Location& posted_from,
tzik739ffe32016-10-14 14:34:5828 OnceClosure task,
Hajime Hoshi64853ef2017-10-11 12:56:0729 TimeTicks delayed_run_time = TimeTicks(),
30 Nestable nestable = Nestable::kNestable);
tzikb6769d52016-07-07 20:20:0631 PendingTask(PendingTask&& other);
[email protected]dd1f9fe2011-11-15 23:36:3032 ~PendingTask();
33
tzikb6769d52016-07-07 20:20:0634 PendingTask& operator=(PendingTask&& other);
35
[email protected]dd1f9fe2011-11-15 23:36:3036 // Used to support sorting.
37 bool operator<(const PendingTask& other) const;
38
39 // The task to run.
tzik739ffe32016-10-14 14:34:5840 OnceClosure task;
[email protected]dd1f9fe2011-11-15 23:36:3041
42 // The site this PendingTask was posted from.
Brett Wilson8e88b312017-09-12 05:22:1643 Location posted_from;
[email protected]dd1f9fe2011-11-15 23:36:3044
Francois Doray118223f42019-12-04 17:00:2845 // The time when the task should be run. This is null for an immediate task.
Brett Wilsonb57e3dd2017-09-08 00:47:4946 base::TimeTicks delayed_run_time;
47
Etienne Pierre-doray2d079032019-02-07 15:18:2348 // The time at which the task was queued. For SequenceManager tasks and
Gabriel Charette499ef40d2020-11-25 18:03:5949 // ThreadPool non-delayed tasks, this happens at post time. For ThreadPool
50 // delayed tasks, this happens some time after the task's delay has expired.
51 // For deferred non-nestable tasks, this is reset when the nested loop exits
52 // and the deferred tasks are pushed back at the front of the queue. This is
53 // not set for SequenceManager tasks if SetAddQueueTimeToTasks(true) wasn't
54 // called. This defaults to a null TimeTicks if the task hasn't been inserted
55 // in a sequence yet.
Karolina Soltysfe88c9e2018-11-06 15:27:0156 TimeTicks queue_time;
Erik Chena95335192018-07-30 17:48:2257
Alan Cutter9b0e1ab2019-03-21 04:22:1658 // Chain of symbols of the parent tasks which led to this one being posted.
59 static constexpr size_t kTaskBacktraceLength = 4;
60 std::array<const void*, kTaskBacktraceLength> task_backtrace = {};
ajwong4f13f742017-02-09 23:52:4061
Chris Hamilton60dcc26b2019-04-24 16:59:5162 // The context of the IPC message that was being handled when this task was
Chris Hamilton888085312019-05-30 00:53:3063 // posted. This is a hash of the IPC message name that is set within the scope
64 // of an IPC handler and when symbolized uniquely identifies the message being
Harkiran Bolaria875dd0d2020-09-15 18:10:4665 // processed. This property is not propagated from one PendingTask to the
Chris Hamilton60dcc26b2019-04-24 16:59:5166 // next. For example, if pending task A was posted while handling an IPC,
67 // and pending task B was posted from within pending task A, then pending task
Harkiran Bolaria875dd0d2020-09-15 18:10:4668 // B will not inherit the |ipc_hash| of pending task A.
Chris Hamilton888085312019-05-30 00:53:3069 uint32_t ipc_hash = 0;
Harkiran Bolaria875dd0d2020-09-15 18:10:4670 const char* ipc_interface_name = nullptr;
Chris Hamilton60dcc26b2019-04-24 16:59:5171
[email protected]dd1f9fe2011-11-15 23:36:3072 // Secondary sort key for run time.
Gabriel Charetteae4f9ce2018-04-05 19:00:0173 int sequence_num = 0;
[email protected]dd1f9fe2011-11-15 23:36:3074
Alex Clarke1ac1f982019-03-29 08:48:3775 bool task_backtrace_overflow = false;
76
[email protected]dd1f9fe2011-11-15 23:36:3077 // OK to dispatch from a nested loop.
Hajime Hoshi64853ef2017-10-11 12:56:0778 Nestable nestable;
cpuee8907952014-08-28 23:25:3779
80 // Needs high resolution timers.
Gabriel Charetteae4f9ce2018-04-05 19:00:0181 bool is_high_res = false;
[email protected]dd1f9fe2011-11-15 23:36:3082};
83
[email protected]dd1f9fe2011-11-15 23:36:3084} // namespace base
85
danakj0a448602015-03-10 00:31:1686#endif // BASE_PENDING_TASK_H_