Index: base/deferred_sequenced_task_runner.h |
diff --git a/base/deferred_sequenced_task_runner.h b/base/deferred_sequenced_task_runner.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..283efc57994305c3475951763a21281231a7ed9a |
--- /dev/null |
+++ b/base/deferred_sequenced_task_runner.h |
@@ -0,0 +1,81 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
tfarina
2013/03/27 14:35:11
nit: Copyright 2013
msarda
2013/03/29 14:40:03
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_ |
+#define BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_ |
+ |
+#include <vector> |
+ |
+#include "base/base_export.h" |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/sequenced_task_runner.h" |
+#include "base/time.h" |
+#include "base/tracked_objects.h" |
+ |
+namespace base { |
+ |
+// A DeferredSequencedTaskRunner is a subclass of SequencedTaskRunner that |
+// queues up all requests until the first call to Start is issued. |
+class BASE_EXPORT DeferredSequencedTaskRunner : public SequencedTaskRunner { |
Jeffrey Yasskin
2013/03/27 18:07:37
Please write a test.
|
+ public: |
+ explicit DeferredSequencedTaskRunner( |
+ const scoped_refptr<SequencedTaskRunner>& target_runner); |
+ |
+ // TaskRunner implementation |
+ virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
+ const Closure& task, |
+ TimeDelta delay) OVERRIDE; |
+ |
+ virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
+ |
+ // SequencedTaskRunner implementation |
+ virtual bool PostNonNestableDelayedTask( |
+ const tracked_objects::Location& from_here, |
+ const Closure& task, |
+ TimeDelta delay) OVERRIDE; |
+ |
+ // Start the execution - posts alltasks in the |deferred_tasks_queue_| to |
+ // the target executor. |
+ // Ignores the call if this task runner is already started. |
+ void Start(); |
+ |
+ private: |
+ virtual ~DeferredSequencedTaskRunner(); |
+ |
+ struct DeferredTask { |
+ DeferredTask(); |
+ ~DeferredTask(); |
+ tracked_objects::Location posted_from; |
+ Closure task; |
+ TimeDelta delay; |
Jeffrey Yasskin
2013/03/27 18:07:37
Do you want the delay to be measured from Start()
msarda
2013/03/29 14:40:03
Done.
|
+ bool is_non_nestable; |
+ }; |
+ |
+ // Creates a |Task| object and adds it to |deferred_tasks_queue_|. |
+ virtual void QueueDeferredTask(const tracked_objects::Location& from_here, |
Jeffrey Yasskin
2013/03/27 18:07:37
Does this need to be virtual? I don't like encoura
msarda
2013/03/29 14:40:03
Done.
|
+ const Closure& task, |
+ TimeDelta delay, |
+ bool is_non_nestable); |
+ |
+ // True if this DeferredSequencedTaskRunner was already started. |
Jeffrey Yasskin
2013/03/27 18:07:37
s/was already/has been/, I think.
msarda
2013/03/29 14:40:03
Done.
|
+ bool started_; |
+ |
+ // Target task runner that executes the tasks. |
+ const scoped_refptr<SequencedTaskRunner> target_task_runner_; |
+ |
+ // Queue if task to be posted to |target_task_runner_| when this |
Jeffrey Yasskin
2013/03/27 18:07:37
s/if/of/?? s/task/tasks/?
msarda
2013/03/29 14:40:03
Done.
|
+ // |DeferredSequencedTaskRunner| is started. |
+ std::vector<DeferredTask> deferred_tasks_queue_; |
+ |
+ mutable Lock lock_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DeferredSequencedTaskRunner); |
+}; |
+ |
+} // namespace base |
+ |
+#endif // BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_ |