blob: 4e98db7ca3d58de043e2b17001df738783768303 [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"
Brett Wilson3d88e7762017-08-14 19:54:3812#include "base/containers/queue.h"
[email protected]dd1f9fe2011-11-15 23:36:3013#include "base/location.h"
Erik Chena95335192018-07-30 17:48:2214#include "base/optional.h"
[email protected]8f9a3a52013-06-28 15:14:1815#include "base/time/time.h"
[email protected]dd1f9fe2011-11-15 23:36:3016
17namespace base {
18
Hajime Hoshi64853ef2017-10-11 12:56:0719enum class Nestable {
20 kNonNestable,
21 kNestable,
22};
23
[email protected]dd1f9fe2011-11-15 23:36:3024// Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue
25// for use by classes that queue and execute tasks.
Brett Wilsonb57e3dd2017-09-08 00:47:4926struct BASE_EXPORT PendingTask {
Jesse McKenna9cf11372018-11-01 19:38:3827 PendingTask();
Brett Wilson8e88b312017-09-12 05:22:1628 PendingTask(const Location& posted_from,
tzik739ffe32016-10-14 14:34:5829 OnceClosure task,
Hajime Hoshi64853ef2017-10-11 12:56:0730 TimeTicks delayed_run_time = TimeTicks(),
31 Nestable nestable = Nestable::kNestable);
tzikb6769d52016-07-07 20:20:0632 PendingTask(PendingTask&& other);
[email protected]dd1f9fe2011-11-15 23:36:3033 ~PendingTask();
34
tzikb6769d52016-07-07 20:20:0635 PendingTask& operator=(PendingTask&& other);
36
[email protected]dd1f9fe2011-11-15 23:36:3037 // Used to support sorting.
38 bool operator<(const PendingTask& other) const;
39
40 // The task to run.
tzik739ffe32016-10-14 14:34:5841 OnceClosure task;
[email protected]dd1f9fe2011-11-15 23:36:3042
43 // The site this PendingTask was posted from.
Brett Wilson8e88b312017-09-12 05:22:1644 Location posted_from;
[email protected]dd1f9fe2011-11-15 23:36:3045
Brett Wilsonb57e3dd2017-09-08 00:47:4946 // The time when the task should be run.
47 base::TimeTicks delayed_run_time;
48
Erik Chena95335192018-07-30 17:48:2249 // The time at which the task was queued. Only set if the task was posted to a
50 // MessageLoop with SetAddQueueTimeToTasks(true).
51 Optional<TimeTicks> queue_time;
52
Gabriel Charette4036f822018-07-06 18:16:4553 // Chain of up-to-four symbols of the parent tasks which led to this one being
54 // posted.
55 std::array<const void*, 4> task_backtrace = {};
ajwong4f13f742017-02-09 23:52:4056
[email protected]dd1f9fe2011-11-15 23:36:3057 // Secondary sort key for run time.
Gabriel Charetteae4f9ce2018-04-05 19:00:0158 int sequence_num = 0;
[email protected]dd1f9fe2011-11-15 23:36:3059
60 // OK to dispatch from a nested loop.
Hajime Hoshi64853ef2017-10-11 12:56:0761 Nestable nestable;
cpuee8907952014-08-28 23:25:3762
63 // Needs high resolution timers.
Gabriel Charetteae4f9ce2018-04-05 19:00:0164 bool is_high_res = false;
[email protected]dd1f9fe2011-11-15 23:36:3065};
66
Brett Wilson3d88e7762017-08-14 19:54:3867using TaskQueue = base::queue<PendingTask>;
[email protected]dd1f9fe2011-11-15 23:36:3068
[email protected]262060ff2011-11-17 23:26:5369// PendingTasks are sorted by their |delayed_run_time| property.
danakj5d792152016-06-15 20:47:4770using DelayedTaskQueue = std::priority_queue<base::PendingTask>;
[email protected]262060ff2011-11-17 23:26:5371
[email protected]dd1f9fe2011-11-15 23:36:3072} // namespace base
73
danakj0a448602015-03-10 00:31:1674#endif // BASE_PENDING_TASK_H_