[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 | |||||
5 | #ifndef PENDING_TASK_H_ | ||||
6 | #define 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] | 1f8bf57 | 2012-10-09 09:37:41 | [diff] [blame] | 21 | #if _MSC_VER >= 1700 |
[email protected] | c297932f | 2012-10-08 22:58:33 | [diff] [blame] | 22 | PendingTask(); |
[email protected] | 1f8bf57 | 2012-10-09 09:37:41 | [diff] [blame] | 23 | #endif |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 24 | PendingTask(const tracked_objects::Location& posted_from, |
25 | const Closure& task); | ||||
26 | PendingTask(const tracked_objects::Location& posted_from, | ||||
27 | const Closure& task, | ||||
28 | TimeTicks delayed_run_time, | ||||
29 | bool nestable); | ||||
30 | ~PendingTask(); | ||||
31 | |||||
32 | // Used to support sorting. | ||||
33 | bool operator<(const PendingTask& other) const; | ||||
34 | |||||
35 | // The task to run. | ||||
36 | Closure task; | ||||
37 | |||||
38 | // The site this PendingTask was posted from. | ||||
39 | tracked_objects::Location posted_from; | ||||
40 | |||||
41 | // Secondary sort key for run time. | ||||
42 | int sequence_num; | ||||
43 | |||||
44 | // OK to dispatch from a nested loop. | ||||
45 | bool nestable; | ||||
46 | }; | ||||
47 | |||||
48 | // Wrapper around std::queue specialized for PendingTask which adds a Swap | ||||
49 | // helper method. | ||||
[email protected] | c360bae7 | 2011-11-18 06:08:02 | [diff] [blame] | 50 | class BASE_EXPORT TaskQueue : public std::queue<PendingTask> { |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 51 | public: |
52 | void Swap(TaskQueue* queue); | ||||
53 | }; | ||||
54 | |||||
[email protected] | 262060ff | 2011-11-17 23:26:53 | [diff] [blame] | 55 | // PendingTasks are sorted by their |delayed_run_time| property. |
56 | typedef std::priority_queue<base::PendingTask> DelayedTaskQueue; | ||||
57 | |||||
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 58 | } // namespace base |
59 | |||||
60 | #endif // PENDING_TASK_H_ |