OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_ |
| 6 #define BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/base_export.h" |
| 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/sequenced_task_runner.h" |
| 16 #include "base/time.h" |
| 17 #include "base/tracked_objects.h" |
| 18 |
| 19 namespace base { |
| 20 |
| 21 // A DeferredSequencedTaskRunner is a subclass of SequencedTaskRunner that |
| 22 // queues up all requests until the first call to Start is issued. |
| 23 class BASE_EXPORT DeferredSequencedTaskRunner : public SequencedTaskRunner { |
| 24 public: |
| 25 explicit DeferredSequencedTaskRunner( |
| 26 const scoped_refptr<SequencedTaskRunner>& target_runner); |
| 27 |
| 28 // TaskRunner implementation |
| 29 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 30 const Closure& task, |
| 31 TimeDelta delay) OVERRIDE; |
| 32 |
| 33 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
| 34 |
| 35 // SequencedTaskRunner implementation |
| 36 virtual bool PostNonNestableDelayedTask( |
| 37 const tracked_objects::Location& from_here, |
| 38 const Closure& task, |
| 39 TimeDelta delay) OVERRIDE; |
| 40 |
| 41 // Start the execution - posts alltasks in the |deferred_tasks_queue_| to |
| 42 // the target executor. |
| 43 // Ignores the call if this task runner is already started. |
| 44 void Start(); |
| 45 |
| 46 private: |
| 47 virtual ~DeferredSequencedTaskRunner(); |
| 48 |
| 49 struct DeferredTask { |
| 50 DeferredTask(); |
| 51 ~DeferredTask(); |
| 52 tracked_objects::Location posted_from; |
| 53 Closure task; |
| 54 TimeDelta delay; |
| 55 bool is_non_nestable; |
| 56 }; |
| 57 |
| 58 // Creates a |Task| object and adds it to |deferred_tasks_queue_|. |
| 59 virtual void QueueDeferredTask(const tracked_objects::Location& from_here, |
| 60 const Closure& task, |
| 61 TimeDelta delay, |
| 62 bool is_non_nestable); |
| 63 |
| 64 // True if this DeferredSequencedTaskRunner was already started. |
| 65 bool started_; |
| 66 |
| 67 // Target task runner that executes the tasks. |
| 68 const scoped_refptr<SequencedTaskRunner> target_task_runner_; |
| 69 |
| 70 // Queue if task to be posted to |target_task_runner_| when this |
| 71 // |DeferredSequencedTaskRunner| is started. |
| 72 std::vector<DeferredTask> deferred_tasks_queue_; |
| 73 |
| 74 mutable Lock lock_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(DeferredSequencedTaskRunner); |
| 77 }; |
| 78 |
| 79 } // namespace base |
| 80 |
| 81 #endif // BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_ |
OLD | NEW |