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

Unified Diff: base/message_loop.cc

Issue 8565024: base: Refactor PendingTask out of MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_loop.h ('k') | base/pending_task.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop.cc
diff --git a/base/message_loop.cc b/base/message_loop.cc
index f4db3238c51215369ddba24983668501ca114fd3..3ff2068efdda9e6eb4e89ef4fba8aa04c7d5e165 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -35,6 +35,7 @@
#include <gdk/gdkx.h>
#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
+using base::PendingTask;
using base::TimeDelta;
using base::TimeTicks;
@@ -260,10 +261,10 @@ void MessageLoop::PostTask(
const tracked_objects::Location& from_here, Task* task) {
DCHECK(task);
PendingTask pending_task(
+ from_here,
base::Bind(
&base::subtle::TaskClosureAdapter::Run,
new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
- from_here,
CalculateDelayedRuntime(0), true);
AddToIncomingQueue(&pending_task);
}
@@ -272,10 +273,10 @@ void MessageLoop::PostDelayedTask(
const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
DCHECK(task);
PendingTask pending_task(
+ from_here,
base::Bind(
&base::subtle::TaskClosureAdapter::Run,
new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
- from_here,
CalculateDelayedRuntime(delay_ms), true);
AddToIncomingQueue(&pending_task);
}
@@ -284,10 +285,10 @@ void MessageLoop::PostNonNestableTask(
const tracked_objects::Location& from_here, Task* task) {
DCHECK(task);
PendingTask pending_task(
+ from_here,
base::Bind(
&base::subtle::TaskClosureAdapter::Run,
new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
- from_here,
CalculateDelayedRuntime(0), false);
AddToIncomingQueue(&pending_task);
}
@@ -296,10 +297,10 @@ void MessageLoop::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
DCHECK(task);
PendingTask pending_task(
+ from_here,
base::Bind(
&base::subtle::TaskClosureAdapter::Run,
new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
- from_here,
CalculateDelayedRuntime(delay_ms), false);
AddToIncomingQueue(&pending_task);
}
@@ -307,7 +308,7 @@ void MessageLoop::PostNonNestableDelayedTask(
void MessageLoop::PostTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
- PendingTask pending_task(task, from_here, CalculateDelayedRuntime(0), true);
+ PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), true);
AddToIncomingQueue(&pending_task);
}
@@ -315,7 +316,7 @@ void MessageLoop::PostDelayedTask(
const tracked_objects::Location& from_here, const base::Closure& task,
int64 delay_ms) {
DCHECK(!task.is_null()) << from_here.ToString();
- PendingTask pending_task(task, from_here,
+ PendingTask pending_task(from_here, task,
CalculateDelayedRuntime(delay_ms), true);
AddToIncomingQueue(&pending_task);
}
@@ -323,7 +324,7 @@ void MessageLoop::PostDelayedTask(
void MessageLoop::PostNonNestableTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
- PendingTask pending_task(task, from_here, CalculateDelayedRuntime(0), false);
+ PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), false);
AddToIncomingQueue(&pending_task);
}
@@ -331,7 +332,7 @@ void MessageLoop::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here, const base::Closure& task,
int64 delay_ms) {
DCHECK(!task.is_null()) << from_here.ToString();
- PendingTask pending_task(task, from_here,
+ PendingTask pending_task(from_here, task,
CalculateDelayedRuntime(delay_ms), false);
AddToIncomingQueue(&pending_task);
}
@@ -774,40 +775,6 @@ MessageLoop::AutoRunState::~AutoRunState() {
}
//------------------------------------------------------------------------------
-// MessageLoop::PendingTask
-
-MessageLoop::PendingTask::PendingTask(
- const base::Closure& task,
- const tracked_objects::Location& posted_from,
- TimeTicks delayed_run_time,
- bool nestable)
- : base::TrackingInfo(posted_from, delayed_run_time),
- task(task),
- posted_from(posted_from),
- sequence_num(0),
- nestable(nestable) {
-}
-
-MessageLoop::PendingTask::~PendingTask() {
-}
-
-bool MessageLoop::PendingTask::operator<(const PendingTask& other) const {
- // Since the top of a priority queue is defined as the "greatest" element, we
- // need to invert the comparison here. We want the smaller time to be at the
- // top of the heap.
-
- if (delayed_run_time < other.delayed_run_time)
- return false;
-
- if (delayed_run_time > other.delayed_run_time)
- return true;
-
- // If the times happen to match, then we use the sequence number to decide.
- // Compare the difference to support integer roll-over.
- return (sequence_num - other.sequence_num) > 0;
-}
-
-//------------------------------------------------------------------------------
// MessageLoopForUI
#if defined(OS_WIN)
« no previous file with comments | « base/message_loop.h ('k') | base/pending_task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698