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

Unified Diff: base/timer/timer.h

Issue 637983003: Add support to base::Timer for custom task runners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final rebase Created 6 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 | « no previous file | base/timer/timer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/timer/timer.h
diff --git a/base/timer/timer.h b/base/timer/timer.h
index 4ef2f456395d5f4b44ebaedbcb06145f6c30cf5f..7e2c1d41f134aa7bdc1c950c01c7645a782cc184 100644
--- a/base/timer/timer.h
+++ b/base/timer/timer.h
@@ -60,6 +60,7 @@
namespace base {
class BaseTimerTaskInternal;
+class SingleThreadTaskRunner;
//-----------------------------------------------------------------------------
// This class wraps MessageLoop::PostDelayedTask to manage delayed and repeating
@@ -87,6 +88,10 @@ class BASE_EXPORT Timer {
// Returns the current delay for this timer.
virtual TimeDelta GetCurrentDelay() const;
+ // Set the task runner on which the task should be scheduled. This method can
+ // only be called before any tasks have been scheduled.
+ virtual void SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner);
+
// Start the timer to run at the given |delay| from now. If the timer is
// already running, it will be replaced to call the given |user_task|.
virtual void Start(const tracked_objects::Location& posted_from,
@@ -128,6 +133,11 @@ class BASE_EXPORT Timer {
// and desired_run_time_ are reset to Now() + delay.
void PostNewScheduledTask(TimeDelta delay);
+ // Returns the task runner on which the task should be scheduled. If the
+ // corresponding task_runner_ field is null, the task runner for the current
+ // thread is returned.
+ scoped_refptr<SingleThreadTaskRunner> GetTaskRunner();
+
// Disable scheduled_task_ and abandon it so that it no longer refers back to
// this object.
void AbandonScheduledTask();
@@ -145,6 +155,10 @@ class BASE_EXPORT Timer {
// RunScheduledTask() at scheduled_run_time_.
BaseTimerTaskInternal* scheduled_task_;
+ // The task runner on which the task should be scheduled. If it is null, the
+ // task runner for the current thread should be used.
+ scoped_refptr<SingleThreadTaskRunner> task_runner_;
+
// Location in user code.
tracked_objects::Location posted_from_;
// Delay requested by user.
« no previous file with comments | « no previous file | base/timer/timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698