[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 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 | |||||
danakj | 0a44860 | 2015-03-10 00:31:16 | [diff] [blame] | 5 | #ifndef BASE_PENDING_TASK_H_ |
6 | #define BASE_PENDING_TASK_H_ | ||||
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 7 | |
8 | #include <queue> | ||||
9 | |||||
[email protected] | c360bae7 | 2011-11-18 06:08:02 | [diff] [blame] | 10 | #include "base/base_export.h" |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 11 | #include "base/callback.h" |
12 | #include "base/location.h" | ||||
[email protected] | 8f9a3a5 | 2013-06-28 15:14:18 | [diff] [blame] | 13 | #include "base/time/time.h" |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 14 | #include "base/tracking_info.h" |
15 | |||||
16 | namespace base { | ||||
17 | |||||
18 | // Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue | ||||
19 | // for use by classes that queue and execute tasks. | ||||
[email protected] | c360bae7 | 2011-11-18 06:08:02 | [diff] [blame] | 20 | struct BASE_EXPORT PendingTask : public TrackingInfo { |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 21 | PendingTask(const tracked_objects::Location& posted_from, |
22 | const Closure& task); | ||||
23 | PendingTask(const tracked_objects::Location& posted_from, | ||||
24 | const Closure& task, | ||||
25 | TimeTicks delayed_run_time, | ||||
26 | bool nestable); | ||||
vmpstr | 7c787706 | 2016-02-18 22:12:24 | [diff] [blame] | 27 | PendingTask(const PendingTask& other); |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 28 | ~PendingTask(); |
29 | |||||
30 | // Used to support sorting. | ||||
31 | bool operator<(const PendingTask& other) const; | ||||
32 | |||||
33 | // The task to run. | ||||
34 | Closure task; | ||||
35 | |||||
36 | // The site this PendingTask was posted from. | ||||
37 | tracked_objects::Location posted_from; | ||||
38 | |||||
39 | // Secondary sort key for run time. | ||||
40 | int sequence_num; | ||||
41 | |||||
42 | // OK to dispatch from a nested loop. | ||||
43 | bool nestable; | ||||
cpu | ee890795 | 2014-08-28 23:25:37 | [diff] [blame] | 44 | |
45 | // Needs high resolution timers. | ||||
46 | bool is_high_res; | ||||
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 47 | }; |
48 | |||||
danakj | 5d79215 | 2016-06-15 20:47:47 | [diff] [blame^] | 49 | using TaskQueue = std::queue<PendingTask>; |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 50 | |
[email protected] | 262060ff | 2011-11-17 23:26:53 | [diff] [blame] | 51 | // PendingTasks are sorted by their |delayed_run_time| property. |
danakj | 5d79215 | 2016-06-15 20:47:47 | [diff] [blame^] | 52 | using DelayedTaskQueue = std::priority_queue<base::PendingTask>; |
[email protected] | 262060ff | 2011-11-17 23:26:53 | [diff] [blame] | 53 | |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 54 | } // namespace base |
55 | |||||
danakj | 0a44860 | 2015-03-10 00:31:16 | [diff] [blame] | 56 | #endif // BASE_PENDING_TASK_H_ |