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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
11 #include "base/threading/post_task_and_reply_impl.h" | 11 #include "base/threading/post_task_and_reply_impl.h" |
12 #include "base/tracked_objects.h" | 12 #include "base/tracked_objects.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl { | 18 class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl { |
19 public: | 19 public: |
20 PostTaskAndReplyWorkerPool(bool task_is_slow) : task_is_slow_(task_is_slow) { | 20 explicit PostTaskAndReplyWorkerPool(bool task_is_slow) |
| 21 : task_is_slow_(task_is_slow) { |
21 } | 22 } |
22 | 23 |
23 private: | 24 private: |
24 virtual bool PostTask(const tracked_objects::Location& from_here, | 25 virtual bool PostTask(const tracked_objects::Location& from_here, |
25 const Closure& task) OVERRIDE { | 26 const Closure& task) OVERRIDE { |
26 return WorkerPool::PostTask(from_here, task, task_is_slow_); | 27 return WorkerPool::PostTask(from_here, task, task_is_slow_); |
27 } | 28 } |
28 | 29 |
29 bool task_is_slow_; | 30 bool task_is_slow_; |
30 }; | 31 }; |
31 | 32 |
32 // WorkerPoolTaskRunner --------------------------------------------- | 33 // WorkerPoolTaskRunner --------------------------------------------- |
33 // A TaskRunner which posts tasks to a WorkerPool with a | 34 // A TaskRunner which posts tasks to a WorkerPool with a |
34 // fixed ShutdownBehavior. | 35 // fixed ShutdownBehavior. |
35 // | 36 // |
36 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). | 37 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). |
37 class WorkerPoolTaskRunner : public TaskRunner { | 38 class WorkerPoolTaskRunner : public TaskRunner { |
38 public: | 39 public: |
39 WorkerPoolTaskRunner(bool tasks_are_slow); | 40 explicit WorkerPoolTaskRunner(bool tasks_are_slow); |
40 | 41 |
41 // TaskRunner implementation | 42 // TaskRunner implementation |
42 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 43 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
43 const Closure& task, | 44 const Closure& task, |
44 TimeDelta delay) OVERRIDE; | 45 TimeDelta delay) OVERRIDE; |
45 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | 46 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
46 | 47 |
47 private: | 48 private: |
48 virtual ~WorkerPoolTaskRunner(); | 49 virtual ~WorkerPoolTaskRunner(); |
49 | 50 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 from_here, task, reply); | 108 from_here, task, reply); |
108 } | 109 } |
109 | 110 |
110 // static | 111 // static |
111 const scoped_refptr<TaskRunner>& | 112 const scoped_refptr<TaskRunner>& |
112 WorkerPool::GetTaskRunner(bool tasks_are_slow) { | 113 WorkerPool::GetTaskRunner(bool tasks_are_slow) { |
113 return g_taskrunners.Get().taskrunners_[tasks_are_slow]; | 114 return g_taskrunners.Get().taskrunners_[tasks_are_slow]; |
114 } | 115 } |
115 | 116 |
116 } // namespace base | 117 } // namespace base |
OLD | NEW |