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

Unified Diff: base/message_loop.h

Issue 6463013: Add support for base::Closure in the MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/base
Patch Set: Created 9 years, 10 months 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 | « no previous file | base/message_loop.cc » ('j') | base/message_loop.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop.h
diff --git a/base/message_loop.h b/base/message_loop.h
index d23899784b3a27d33d166a118d6e579d96e400af..43babb21da8f460fbe43d06df5f0e1671610baf6 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.
+ 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.
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | base/message_loop.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698