Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: base/pending_task.cc

Issue 8565024: base: Refactor PendingTask out of MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style and build fix. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "base/tracked_objects.h"
8
9 namespace base {
10
11 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
12 const base::Closure& task)
13 : base::TrackingInfo(posted_from, TimeTicks()),
14 task(task),
15 posted_from(posted_from),
16 sequence_num(0),
17 nestable(false) {
18 }
19
20 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
21 const base::Closure& task,
22 TimeTicks delayed_run_time,
23 bool nestable)
24 : base::TrackingInfo(posted_from, delayed_run_time),
25 task(task),
26 posted_from(posted_from),
27 sequence_num(0),
28 nestable(nestable) {
29 }
30
31 PendingTask::~PendingTask() {
32 }
33
34 bool PendingTask::operator<(const PendingTask& other) const {
35 // Since the top of a priority queue is defined as the "greatest" element, we
36 // need to invert the comparison here. We want the smaller time to be at the
37 // top of the heap.
38
39 if (delayed_run_time < other.delayed_run_time)
40 return false;
41
42 if (delayed_run_time > other.delayed_run_time)
43 return true;
44
45 // If the times happen to match, then we use the sequence number to decide.
46 // Compare the difference to support integer roll-over.
47 return (sequence_num - other.sequence_num) > 0;
48 }
49
50 void TaskQueue::Swap(TaskQueue* queue) {
51 c.swap(queue->c); // Calls std::deque::swap.
52 }
53
54 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698