OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_THREADING_SEQUENCED_WORKER_POOL_TASK_RUNNER_H_ | |
6 #define BASE_THREADING_SEQUENCED_WORKER_POOL_TASK_RUNNER_H_ | |
7 #pragma once | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/callback_forward.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/sequenced_task_runner.h" | |
14 #include "base/threading/sequenced_worker_pool.h" | |
15 #include "base/time.h" | |
16 | |
17 namespace tracked_objects { | |
18 class Location; | |
19 } // namespace tracked_objects | |
20 | |
21 namespace base { | |
22 | |
23 // A SequencedTaskRunner which posts tasks to a SequencedWorkerPool with a | |
24 // fixed sequence token. | |
25 // | |
26 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). | |
27 class BASE_EXPORT SequencedWorkerPoolTaskRunner : public SequencedTaskRunner { | |
28 public: | |
29 SequencedWorkerPoolTaskRunner(const scoped_refptr<SequencedWorkerPool>& pool, | |
30 SequencedWorkerPool::SequenceToken token); | |
31 | |
32 // TaskRunner implementation | |
33 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
34 const Closure& task, | |
35 int64 delay_ms) OVERRIDE; | |
36 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
37 const Closure& task, | |
38 TimeDelta delay) OVERRIDE; | |
39 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | |
40 | |
41 // SequencedTaskRunner implementation | |
42 virtual bool PostNonNestableDelayedTask( | |
43 const tracked_objects::Location& from_here, | |
44 const Closure& task, | |
45 int64 delay_ms) OVERRIDE; | |
46 virtual bool PostNonNestableDelayedTask( | |
47 const tracked_objects::Location& from_here, | |
48 const Closure& task, | |
49 TimeDelta delay) OVERRIDE; | |
50 | |
51 private: | |
52 virtual ~SequencedWorkerPoolTaskRunner(); | |
53 | |
54 // Helper function for posting a delayed task. Asserts that the delay is | |
55 // zero because non-zero delays are not yet supported. | |
56 bool PostDelayedTaskAssertZeroDelay( | |
57 const tracked_objects::Location& from_here, | |
58 const Closure& task, | |
59 int64 delay_ms); | |
60 bool PostDelayedTaskAssertZeroDelay( | |
61 const tracked_objects::Location& from_here, | |
62 const Closure& task, | |
63 TimeDelta delay); | |
64 | |
65 const scoped_refptr<SequencedWorkerPool> pool_; | |
66 | |
67 const SequencedWorkerPool::SequenceToken token_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolTaskRunner); | |
70 }; | |
71 | |
72 } // namespace base | |
73 | |
74 #endif // BASE_THREADING_SEQUENCED_TASK_RUNNER_IMPL_H_ | |
OLD | NEW |