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.
5 #include "base/pending_task.h"
10 PendingTask::PendingTask() = default;
12 PendingTask::PendingTask(const Location& posted_from, OnceClosure task)
13 : PendingTask(posted_from, std::move(task), TimeTicks(), TimeTicks()) {}
15 PendingTask::PendingTask(const Location& posted_from,
18 TimeTicks delayed_run_time)
19 : task(std::move(task)),
20 posted_from(posted_from),
21 queue_time(queue_time),
22 delayed_run_time(delayed_run_time) {}
24 PendingTask::PendingTask(PendingTask&& other) = default;
26 PendingTask::~PendingTask() = default;
28 PendingTask& PendingTask::operator=(PendingTask&& other) = default;
30 bool PendingTask::operator<(const PendingTask& other) const {
31 // Since the top of a priority queue is defined as the "greatest" element, we
32 // need to invert the comparison here. We want the smaller time to be at the
35 if (delayed_run_time < other.delayed_run_time)
38 if (delayed_run_time > other.delayed_run_time)
41 // If the times happen to match, then we use the sequence number to decide.
42 // Compare the difference to support integer roll-over.
43 return (sequence_num - other.sequence_num) > 0;
46 TimeTicks PendingTask::GetDesiredExecutionTime() const {
47 if (!delayed_run_time.is_null())
48 return delayed_run_time;