Chromium Code Reviews| Index: base/message_loop.h |
| diff --git a/base/message_loop.h b/base/message_loop.h |
| index d23899784b3a27d33d166a118d6e579d96e400af..b8d1724e3e43ebbc16870354918bc2ce9d293e16 100644 |
| --- a/base/message_loop.h |
| +++ b/base/message_loop.h |
| @@ -10,6 +10,7 @@ |
| #include <string> |
| #include "base/basictypes.h" |
| +#include "base/callback.h" |
| #include "base/message_pump.h" |
| #include "base/observer_list.h" |
| #include "base/ref_counted.h" |
| @@ -161,6 +162,22 @@ class MessageLoop : public base::MessagePump::Delegate { |
| void PostNonNestableDelayedTask( |
| const tracked_objects::Location& from_here, Task* task, int64 delay_ms); |
| + void PostClosure( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& closure); |
| + |
| + void PostDelayedClosure( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& closure, int64 delay_ms); |
| + |
| + void PostNonNestableClosure( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& closure); |
| + |
| + void PostNonNestableDelayedClosure( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& closure, int64 delay_ms); |
| + |
| // A variant on PostTask that deletes the given object. This is useful |
| // if the object needs to live until the next run of the MessageLoop (for |
| // example, deleting a RenderProcessHost from within an IPC callback is not |
| @@ -344,14 +361,22 @@ class MessageLoop : public base::MessagePump::Delegate { |
| // This structure is copied around by value. |
| struct PendingTask { |
| - PendingTask(Task* task, bool nestable) |
| - : task(task), sequence_num(0), nestable(nestable) { |
| + PendingTask(Task* task, base::TimeTicks delayed_run_time, bool nestable) |
| + : task(task), delayed_run_time(delayed_run_time), sequence_num(0), |
| + nestable(nestable) { |
| + } |
| + |
| + PendingTask(const base::Closure& closure, base::TimeTicks delayed_run_time, |
| + bool nestable) |
| + : task(NULL), closure(closure), delayed_run_time(delayed_run_time), |
| + sequence_num(0), nestable(nestable) { |
| } |
| // Used to support sorting. |
| bool operator<(const PendingTask& other) const; |
| Task* task; // The task to run. |
|
darin (slow to review)
2011/02/15 05:05:47
It would be nice to implement the old Task-based m
awong
2011/02/15 08:24:42
Hah...yes it would. I was initially thinking of a
|
| + base::Closure closure; // The Closure to run if task == NULL. |
| base::TimeTicks delayed_run_time; // The time when the task should be run. |
| int sequence_num; // Secondary sort key for run time. |
| bool nestable; // OK to dispatch from a nested loop. |
| @@ -397,6 +422,9 @@ class MessageLoop : public base::MessagePump::Delegate { |
| // Runs the specified task and deletes it. |
| void RunTask(Task* task); |
| + // Runs the specified Closure. |
| + void RunClosure(const base::Closure& closure); |
| + |
| // Calls RunTask or queues the pending_task on the deferred task list if it |
| // cannot be run right now. Returns true if the task was run. |
| bool DeferOrRunPendingTask(const PendingTask& pending_task); |
| @@ -404,6 +432,9 @@ class MessageLoop : public base::MessagePump::Delegate { |
| // Adds the pending task to delayed_work_queue_. |
| void AddToDelayedWorkQueue(const PendingTask& pending_task); |
| + // Adds the pending task to our incoming_queue_. |
| + void AddToIncomingQueue(const PendingTask& pending_task); |
| + |
| // Load tasks from the incoming_queue_ into work_queue_ if the latter is |
| // empty. The former requires a lock to access, while the latter is directly |
| // accessible on this thread. |
| @@ -414,9 +445,8 @@ class MessageLoop : public base::MessagePump::Delegate { |
| // true if some work was done. |
| bool DeletePendingTasks(); |
| - // Post a task to our incomming queue. |
| - void PostTask_Helper(const tracked_objects::Location& from_here, Task* task, |
| - int64 delay_ms, bool nestable); |
| + // Calcuates the time at which a PendingTask should run. |
| + base::TimeTicks CalculateDelayedRuntime(int64 delay_ms); |
| // Start recording histogram info about events and action IF it was enabled |
| // and IF the statistics recorder can accept a registration of our histogram. |
| @@ -464,9 +494,9 @@ class MessageLoop : public base::MessagePump::Delegate { |
| scoped_refptr<base::Histogram> message_histogram_; |
| // A null terminated list which creates an incoming_queue of tasks that are |
| - // acquired under a mutex for processing on this instance's thread. These tasks |
| - // have not yet been sorted out into items for our work_queue_ vs items that |
| - // will be handled by the TimerManager. |
| + // acquired under a mutex for processing on this instance's thread. These |
| + // tasks have not yet been sorted out into items for our work_queue_ vs items |
| + // that will be handled by the TimerManager. |
| TaskQueue incoming_queue_; |
| // Protect access to incoming_queue_. |
| mutable base::Lock incoming_queue_lock_; |