Chromium Code Reviews| 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 BASE_PENDING_TASK_H_ | 5 #ifndef BASE_PENDING_TASK_H_ |
| 6 #define BASE_PENDING_TASK_H_ | 6 #define BASE_PENDING_TASK_H_ |
| 7 | 7 |
| 8 #include <memory> | |
| 8 #include <queue> | 9 #include <queue> |
| 9 | 10 |
| 10 #include "base/base_export.h" | 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" |
| 14 #include "base/macros.h" | |
| 13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/trace_event/trace_event_impl.h" | |
| 14 #include "base/tracking_info.h" | 17 #include "base/tracking_info.h" |
| 15 | 18 |
| 16 namespace base { | 19 namespace base { |
| 17 | 20 |
| 18 // Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue | 21 // Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue |
| 19 // for use by classes that queue and execute tasks. | 22 // for use by classes that queue and execute tasks. |
| 20 struct BASE_EXPORT PendingTask : public TrackingInfo { | 23 struct BASE_EXPORT PendingTask : public TrackingInfo { |
| 24 // A thread-safe copy of a PendingTask's info required by tracing. | |
| 25 class TracingInfo : public trace_event::ConvertableToTraceFormat { | |
|
caseq
2016/09/29 22:46:37
Why does it have to be nested class of PendingTask
gab
2016/10/03 15:18:58
Good point, I'll move it when we achieve overall c
| |
| 26 public: | |
| 27 TracingInfo(const tracked_objects::Location& posted_from); | |
| 28 ~TracingInfo() override; | |
| 29 | |
| 30 // Overridden from trace_event::ConvertableToTraceFormat: | |
| 31 void AppendAsTraceFormat(std::string* out) const override; | |
| 32 | |
| 33 private: | |
| 34 const tracked_objects::Location posted_from_; | |
| 35 | |
| 36 DISALLOW_COPY_AND_ASSIGN(TracingInfo); | |
| 37 }; | |
| 38 | |
| 21 PendingTask(const tracked_objects::Location& posted_from, | 39 PendingTask(const tracked_objects::Location& posted_from, |
| 22 Closure task); | 40 Closure task); |
| 23 PendingTask(const tracked_objects::Location& posted_from, | 41 PendingTask(const tracked_objects::Location& posted_from, |
| 24 Closure task, | 42 Closure task, |
| 25 TimeTicks delayed_run_time, | 43 TimeTicks delayed_run_time, |
| 26 bool nestable); | 44 bool nestable); |
| 27 PendingTask(PendingTask&& other); | 45 PendingTask(PendingTask&& other); |
| 28 ~PendingTask(); | 46 ~PendingTask(); |
| 29 | 47 |
| 30 PendingTask& operator=(PendingTask&& other); | 48 PendingTask& operator=(PendingTask&& other); |
| 31 | 49 |
| 32 // Used to support sorting. | 50 // Used to support sorting. |
| 33 bool operator<(const PendingTask& other) const; | 51 bool operator<(const PendingTask& other) const; |
| 34 | 52 |
| 53 std::unique_ptr<trace_event::ConvertableToTraceFormat> GetTracingInfo() const; | |
|
caseq
2016/09/29 22:46:37
ditto.
gab
2016/10/03 15:18:58
Acknowledged.
| |
| 54 | |
| 35 // The task to run. | 55 // The task to run. |
| 36 Closure task; | 56 Closure task; |
| 37 | 57 |
| 38 // The site this PendingTask was posted from. | 58 // The site this PendingTask was posted from. |
| 39 tracked_objects::Location posted_from; | 59 tracked_objects::Location posted_from; |
| 40 | 60 |
| 41 // Secondary sort key for run time. | 61 // Secondary sort key for run time. |
| 42 int sequence_num; | 62 int sequence_num; |
| 43 | 63 |
| 44 // OK to dispatch from a nested loop. | 64 // OK to dispatch from a nested loop. |
| 45 bool nestable; | 65 bool nestable; |
| 46 | 66 |
| 47 // Needs high resolution timers. | 67 // Needs high resolution timers. |
| 48 bool is_high_res; | 68 bool is_high_res; |
| 49 }; | 69 }; |
| 50 | 70 |
| 51 using TaskQueue = std::queue<PendingTask>; | 71 using TaskQueue = std::queue<PendingTask>; |
| 52 | 72 |
| 53 // PendingTasks are sorted by their |delayed_run_time| property. | 73 // PendingTasks are sorted by their |delayed_run_time| property. |
| 54 using DelayedTaskQueue = std::priority_queue<base::PendingTask>; | 74 using DelayedTaskQueue = std::priority_queue<base::PendingTask>; |
| 55 | 75 |
| 56 } // namespace base | 76 } // namespace base |
| 57 | 77 |
| 58 #endif // BASE_PENDING_TASK_H_ | 78 #endif // BASE_PENDING_TASK_H_ |
| OLD | NEW |