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" | |
willchan no longer on Chromium
2013/04/05 02:56:41
Why?
msarda
2013/04/08 17:37:18
Done.
| |
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. | |
willchan no longer on Chromium
2013/04/05 02:56:41
Start() to indicate it's a member function.
msarda
2013/04/08 17:37:18
Done.
| |
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 all tasks in the |deferred_tasks_queue_| to | |
42 // the target executor. The deferred tasks are posted with their initial | |
43 // delay, meaning that the task execution delay is actually measured from | |
44 // Start. | |
45 // Ignores the call if this task runner is already started. | |
willchan no longer on Chromium
2013/04/05 02:56:41
This is all personal style preference, and despite
msarda
2013/04/08 17:37:18
I did consider it, but I can go either way. I chan
| |
46 void Start(); | |
47 | |
48 private: | |
49 virtual ~DeferredSequencedTaskRunner(); | |
50 | |
51 struct DeferredTask { | |
willchan no longer on Chromium
2013/04/05 02:56:41
Types go before destructors. Move this up.
msarda
2013/04/08 17:37:18
Done.
| |
52 DeferredTask(); | |
53 ~DeferredTask(); | |
54 tracked_objects::Location posted_from; | |
55 Closure task; | |
56 // The delay this task was initially posted with. | |
57 TimeDelta delay; | |
58 bool is_non_nestable; | |
59 }; | |
60 | |
61 // Creates a |Task| object and adds it to |deferred_tasks_queue_|. | |
62 void QueueDeferredTask(const tracked_objects::Location& from_here, | |
63 const Closure& task, | |
64 TimeDelta delay, | |
65 bool is_non_nestable); | |
66 | |
67 // True if this DeferredSequencedTaskRunner has already been started. | |
68 bool started_; | |
69 | |
70 // Target task runner that executes the tasks. | |
71 const scoped_refptr<SequencedTaskRunner> target_task_runner_; | |
72 | |
73 // Queue of tasks to be posted to |target_task_runner_| when this | |
74 // |DeferredSequencedTaskRunner| is started. | |
75 std::vector<DeferredTask> deferred_tasks_queue_; | |
76 | |
77 mutable Lock lock_; | |
willchan no longer on Chromium
2013/04/05 02:56:41
Move this to be first. It guards all the other mem
msarda
2013/04/08 17:37:18
Done.
| |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(DeferredSequencedTaskRunner); | |
80 }; | |
81 | |
82 } // namespace base | |
83 | |
84 #endif // BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_ | |
OLD | NEW |