[M94 Dev][Tizen] Fix for errors for generating ninja files
[platform/framework/web/chromium-efl.git] / base / pending_task.cc
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 #include "base/pending_task.h"
6
7
8 namespace base {
9
10 PendingTask::PendingTask() = default;
11
12 PendingTask::PendingTask(const Location& posted_from, OnceClosure task)
13     : PendingTask(posted_from, std::move(task), TimeTicks(), TimeTicks()) {}
14
15 PendingTask::PendingTask(const Location& posted_from,
16                          OnceClosure task,
17                          TimeTicks queue_time,
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) {}
23
24 PendingTask::PendingTask(PendingTask&& other) = default;
25
26 PendingTask::~PendingTask() = default;
27
28 PendingTask& PendingTask::operator=(PendingTask&& other) = default;
29
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
33   // top of the heap.
34
35   if (delayed_run_time < other.delayed_run_time)
36     return false;
37
38   if (delayed_run_time > other.delayed_run_time)
39     return true;
40
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;
44 }
45
46 TimeTicks PendingTask::GetDesiredExecutionTime() const {
47   if (!delayed_run_time.is_null())
48     return delayed_run_time;
49   return queue_time;
50 }
51
52 }  // namespace base