| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PENDING_TASK_H_ | 5 #ifndef PENDING_TASK_H_ |
| 6 #define PENDING_TASK_H_ | 6 #define PENDING_TASK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 | 10 |
| 11 #include "base/base_export.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/location.h" | 13 #include "base/location.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "base/tracking_info.h" | 15 #include "base/tracking_info.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 | 18 |
| 18 // Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue | 19 // Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue |
| 19 // for use by classes that queue and execute tasks. | 20 // for use by classes that queue and execute tasks. |
| 20 struct PendingTask : public TrackingInfo { | 21 struct BASE_EXPORT PendingTask : public TrackingInfo { |
| 21 PendingTask(const tracked_objects::Location& posted_from, | 22 PendingTask(const tracked_objects::Location& posted_from, |
| 22 const Closure& task); | 23 const Closure& task); |
| 23 PendingTask(const tracked_objects::Location& posted_from, | 24 PendingTask(const tracked_objects::Location& posted_from, |
| 24 const Closure& task, | 25 const Closure& task, |
| 25 TimeTicks delayed_run_time, | 26 TimeTicks delayed_run_time, |
| 26 bool nestable); | 27 bool nestable); |
| 27 ~PendingTask(); | 28 ~PendingTask(); |
| 28 | 29 |
| 29 // Used to support sorting. | 30 // Used to support sorting. |
| 30 bool operator<(const PendingTask& other) const; | 31 bool operator<(const PendingTask& other) const; |
| 31 | 32 |
| 32 // The task to run. | 33 // The task to run. |
| 33 Closure task; | 34 Closure task; |
| 34 | 35 |
| 35 // The site this PendingTask was posted from. | 36 // The site this PendingTask was posted from. |
| 36 tracked_objects::Location posted_from; | 37 tracked_objects::Location posted_from; |
| 37 | 38 |
| 38 // Secondary sort key for run time. | 39 // Secondary sort key for run time. |
| 39 int sequence_num; | 40 int sequence_num; |
| 40 | 41 |
| 41 // OK to dispatch from a nested loop. | 42 // OK to dispatch from a nested loop. |
| 42 bool nestable; | 43 bool nestable; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 // Wrapper around std::queue specialized for PendingTask which adds a Swap | 46 // Wrapper around std::queue specialized for PendingTask which adds a Swap |
| 46 // helper method. | 47 // helper method. |
| 47 class TaskQueue : public std::queue<PendingTask> { | 48 class BASE_EXPORT TaskQueue : public std::queue<PendingTask> { |
| 48 public: | 49 public: |
| 49 void Swap(TaskQueue* queue); | 50 void Swap(TaskQueue* queue); |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 // PendingTasks are sorted by their |delayed_run_time| property. | 53 // PendingTasks are sorted by their |delayed_run_time| property. |
| 53 typedef std::priority_queue<base::PendingTask> DelayedTaskQueue; | 54 typedef std::priority_queue<base::PendingTask> DelayedTaskQueue; |
| 54 | 55 |
| 55 } // namespace base | 56 } // namespace base |
| 56 | 57 |
| 57 #endif // PENDING_TASK_H_ | 58 #endif // PENDING_TASK_H_ |
| OLD | NEW |