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

Unified Diff: mojo/public/cpp/utility/run_loop.h

Issue 384513003: Remove RequestAnimationFrame from mojo, add delayed tasks to RunLoop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 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
Index: mojo/public/cpp/utility/run_loop.h
diff --git a/mojo/public/cpp/utility/run_loop.h b/mojo/public/cpp/utility/run_loop.h
index 74f870abc577eeca708b5134b87856eba7b81e61..e02f6455e9a95e6e3b69060bd14c0bd3a8b0e423 100644
--- a/mojo/public/cpp/utility/run_loop.h
+++ b/mojo/public/cpp/utility/run_loop.h
@@ -6,7 +6,9 @@
#define MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_
#include <map>
+#include <queue>
+#include "mojo/public/cpp/bindings/callback.h"
#include "mojo/public/cpp/system/core.h"
namespace mojo {
@@ -49,6 +51,10 @@ class RunLoop {
void Quit();
+ // Adds a task to be performed after delay has elapsed. Must be posted to the
+ // current thread's RunLoop.
+ void PostDelayedTask(const Closure& task, MojoTimeTicks delay);
+
private:
struct RunState;
struct WaitState;
@@ -70,6 +76,9 @@ class RunLoop {
typedef std::map<Handle, HandlerData> HandleToHandlerData;
+ // Do one unit of delayed work, if eligible.
+ void DoDelayedWork();
+
// Waits for a handle to be ready. Returns after servicing at least one
// handle (or there are no more handles) unless |non_blocking| is true,
// in which case it will also return if servicing at least one handle
@@ -100,6 +109,24 @@ class RunLoop {
// notify it.
int next_handler_id_;
+ struct PendingTask {
+ PendingTask(const Closure& task,
+ MojoTimeTicks runtime,
+ uint64_t sequence_number);
+ ~PendingTask();
+
+ bool operator<(const PendingTask& other) const;
+
+ Closure task;
+ MojoTimeTicks run_time;
+ uint64_t sequence_number;
+ };
+ // An ever increasing sequence number attached to each pending task in order
+ // to preserve relative order of tasks posted at the 'same' time.
+ uint64_t next_sequence_number_;
+ typedef std::priority_queue<PendingTask> DelayedTaskQueue;
+ DelayedTaskQueue delayed_tasks_;
+
MOJO_DISALLOW_COPY_AND_ASSIGN(RunLoop);
};

Powered by Google App Engine
This is Rietveld 408576698