OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/threading/worker_pool.h" | 5 #include "base/threading/worker_pool.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
12 #include "base/threading/post_task_and_reply_impl.h" | 12 #include "base/threading/post_task_and_reply_impl.h" |
13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl { | 19 class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl { |
20 public: | 20 public: |
21 explicit PostTaskAndReplyWorkerPool(bool task_is_slow) | 21 explicit PostTaskAndReplyWorkerPool(bool task_is_slow) |
22 : task_is_slow_(task_is_slow) { | 22 : task_is_slow_(task_is_slow) { |
23 } | 23 } |
24 | 24 |
25 private: | 25 private: |
26 virtual bool PostTask(const tracked_objects::Location& from_here, | 26 bool PostTask(const tracked_objects::Location& from_here, |
27 const Closure& task) OVERRIDE { | 27 const Closure& task) override { |
28 return WorkerPool::PostTask(from_here, task, task_is_slow_); | 28 return WorkerPool::PostTask(from_here, task, task_is_slow_); |
29 } | 29 } |
30 | 30 |
31 bool task_is_slow_; | 31 bool task_is_slow_; |
32 }; | 32 }; |
33 | 33 |
34 // WorkerPoolTaskRunner --------------------------------------------- | 34 // WorkerPoolTaskRunner --------------------------------------------- |
35 // A TaskRunner which posts tasks to a WorkerPool with a | 35 // A TaskRunner which posts tasks to a WorkerPool with a |
36 // fixed ShutdownBehavior. | 36 // fixed ShutdownBehavior. |
37 // | 37 // |
38 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). | 38 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). |
39 class WorkerPoolTaskRunner : public TaskRunner { | 39 class WorkerPoolTaskRunner : public TaskRunner { |
40 public: | 40 public: |
41 explicit WorkerPoolTaskRunner(bool tasks_are_slow); | 41 explicit WorkerPoolTaskRunner(bool tasks_are_slow); |
42 | 42 |
43 // TaskRunner implementation | 43 // TaskRunner implementation |
44 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 44 bool PostDelayedTask(const tracked_objects::Location& from_here, |
45 const Closure& task, | 45 const Closure& task, |
46 TimeDelta delay) OVERRIDE; | 46 TimeDelta delay) override; |
47 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | 47 bool RunsTasksOnCurrentThread() const override; |
48 | 48 |
49 private: | 49 private: |
50 virtual ~WorkerPoolTaskRunner(); | 50 virtual ~WorkerPoolTaskRunner(); |
51 | 51 |
52 // Helper function for posting a delayed task. Asserts that the delay is | 52 // Helper function for posting a delayed task. Asserts that the delay is |
53 // zero because non-zero delays are not supported. | 53 // zero because non-zero delays are not supported. |
54 bool PostDelayedTaskAssertZeroDelay( | 54 bool PostDelayedTaskAssertZeroDelay( |
55 const tracked_objects::Location& from_here, | 55 const tracked_objects::Location& from_here, |
56 const Closure& task, | 56 const Closure& task, |
57 base::TimeDelta delay); | 57 base::TimeDelta delay); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 from_here, task, reply); | 115 from_here, task, reply); |
116 } | 116 } |
117 | 117 |
118 // static | 118 // static |
119 const scoped_refptr<TaskRunner>& | 119 const scoped_refptr<TaskRunner>& |
120 WorkerPool::GetTaskRunner(bool tasks_are_slow) { | 120 WorkerPool::GetTaskRunner(bool tasks_are_slow) { |
121 return g_taskrunners.Get().taskrunners_[tasks_are_slow]; | 121 return g_taskrunners.Get().taskrunners_[tasks_are_slow]; |
122 } | 122 } |
123 | 123 |
124 } // namespace base | 124 } // namespace base |
OLD | NEW |