Chromium Code Reviews| 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..5fd66bed89fd5c7f4d39342ebb6b7d0a59fd8b3b |
| --- /dev/null |
| +++ b/base/deferred_sequenced_task_runner.h |
| @@ -0,0 +1,83 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// 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/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 { |
| + 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; |
|
erikwright (departed)
2013/04/15 17:56:25
compiler_specific.h for OVERRIDE
msarda
2013/04/17 09:53:55
Done.
|
| + |
|
erikwright (departed)
2013/04/15 17:56:25
remove this blank line
msarda
2013/04/17 09:53:55
Done.
|
| + 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 all tasks in the |deferred_tasks_queue_| to |
|
erikwright (departed)
2013/04/15 17:56:25
"posts all queued tasks to the target executor." r
msarda
2013/04/17 09:53:55
The comment on what delay means was added followin
erikwright (departed)
2013/04/17 14:41:19
Sorry, the only change I'm referring to is s/tasks
msarda
2013/04/17 15:29:10
Done.
|
| + // the target executor. The deferred tasks are posted with their initial |
| + // delay, meaning that the task execution delay is actually measured from |
| + // Start. |
| + // Fails when called a second time. |
|
erikwright (departed)
2013/04/15 17:56:25
Ignores second and further calls. ?
msarda
2013/04/17 09:53:55
That was the initial implementation. I changed it
|
| + void Start(); |
| + |
| + private: |
| + struct DeferredTask { |
| + DeferredTask(); |
| + ~DeferredTask(); |
|
erikwright (departed)
2013/04/15 17:56:25
blank line after destructor?
msarda
2013/04/17 09:53:55
Done.
|
| + tracked_objects::Location posted_from; |
| + Closure task; |
| + // The delay this task was initially posted with. |
| + TimeDelta delay; |
| + bool is_non_nestable; |
| + }; |
| + |
| + virtual ~DeferredSequencedTaskRunner(); |
| + |
| + // Creates a |Task| object and adds it to |deferred_tasks_queue_|. |
| + void QueueDeferredTask(const tracked_objects::Location& from_here, |
| + const Closure& task, |
| + TimeDelta delay, |
| + bool is_non_nestable); |
| + |
| + mutable Lock lock_; |
|
erikwright (departed)
2013/04/15 17:56:25
Add a comment indicating what members are protecte
erikwright (departed)
2013/04/15 17:56:25
missing an #include for Lock
msarda
2013/04/17 09:53:55
Done.
msarda
2013/04/17 09:53:55
Done.
|
| + |
| + // True if this DeferredSequencedTaskRunner has already been started. |
|
erikwright (departed)
2013/04/15 17:56:25
I'm mildly opposed to the presence of these member
msarda
2013/04/17 09:53:55
I removed them.
|
| + bool started_; |
| + |
| + // Target task runner that executes the tasks. |
| + const scoped_refptr<SequencedTaskRunner> target_task_runner_; |
| + |
| + // Queue of tasks to be posted to |target_task_runner_| when this |
| + // |DeferredSequencedTaskRunner| is started. |
| + std::vector<DeferredTask> deferred_tasks_queue_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DeferredSequencedTaskRunner); |
| +}; |
| + |
| +} // namespace base |
| + |
| +#endif // BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_ |