blob: a2edc6947d09f9227ebc0b4ada81a7b6cd1c3551 [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
5#ifndef PENDING_TASK_H_
6#define PENDING_TASK_H_
[email protected]dd1f9fe2011-11-15 23:36:307
8#include <queue>
9
[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"
12#include "base/location.h"
[email protected]8f9a3a52013-06-28 15:14:1813#include "base/time/time.h"
[email protected]dd1f9fe2011-11-15 23:36:3014#include "base/tracking_info.h"
15
16namespace 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]c360bae72011-11-18 06:08:0220struct BASE_EXPORT PendingTask : public TrackingInfo {
[email protected]dd1f9fe2011-11-15 23:36:3021 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);
27 ~PendingTask();
28
29 // Used to support sorting.
30 bool operator<(const PendingTask& other) const;
31
32 // The task to run.
33 Closure task;
34
35 // The site this PendingTask was posted from.
36 tracked_objects::Location posted_from;
37
38 // Secondary sort key for run time.
39 int sequence_num;
40
41 // OK to dispatch from a nested loop.
42 bool nestable;
cpuee8907952014-08-28 23:25:3743
44 // Needs high resolution timers.
45 bool is_high_res;
[email protected]dd1f9fe2011-11-15 23:36:3046};
47
48// Wrapper around std::queue specialized for PendingTask which adds a Swap
49// helper method.
[email protected]c360bae72011-11-18 06:08:0250class BASE_EXPORT TaskQueue : public std::queue<PendingTask> {
[email protected]dd1f9fe2011-11-15 23:36:3051 public:
52 void Swap(TaskQueue* queue);
53};
54
[email protected]262060ff2011-11-17 23:26:5355// PendingTasks are sorted by their |delayed_run_time| property.
56typedef std::priority_queue<base::PendingTask> DelayedTaskQueue;
57
[email protected]dd1f9fe2011-11-15 23:36:3058} // namespace base
59
60#endif // PENDING_TASK_H_