Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: base/threading/worker_pool.cc

Issue 9703053: Remove old Sleep and PostDelayedTask interfaces that use int ms instead of TimeDelta. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase onto master. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 23 matching lines...) Expand all
34 // fixed ShutdownBehavior. 34 // fixed ShutdownBehavior.
35 // 35 //
36 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). 36 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner).
37 class WorkerPoolTaskRunner : public TaskRunner { 37 class WorkerPoolTaskRunner : public TaskRunner {
38 public: 38 public:
39 WorkerPoolTaskRunner(bool tasks_are_slow); 39 WorkerPoolTaskRunner(bool tasks_are_slow);
40 40
41 // TaskRunner implementation 41 // TaskRunner implementation
42 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, 42 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
43 const Closure& task, 43 const Closure& task,
44 int64 delay_ms) OVERRIDE;
45 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
46 const Closure& task,
47 TimeDelta delay) OVERRIDE; 44 TimeDelta delay) OVERRIDE;
48 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; 45 virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
49 46
50 private: 47 private:
51 virtual ~WorkerPoolTaskRunner(); 48 virtual ~WorkerPoolTaskRunner();
52 49
53 // Helper function for posting a delayed task. Asserts that the delay is 50 // Helper function for posting a delayed task. Asserts that the delay is
54 // zero because non-zero delays are not supported. 51 // zero because non-zero delays are not supported.
55 bool PostDelayedTaskAssertZeroDelay( 52 bool PostDelayedTaskAssertZeroDelay(
56 const tracked_objects::Location& from_here, 53 const tracked_objects::Location& from_here,
57 const Closure& task, 54 const Closure& task,
58 int64 delay_ms); 55 base::TimeDelta delay);
59 56
60 const bool tasks_are_slow_; 57 const bool tasks_are_slow_;
61 58
62 DISALLOW_COPY_AND_ASSIGN(WorkerPoolTaskRunner); 59 DISALLOW_COPY_AND_ASSIGN(WorkerPoolTaskRunner);
63 }; 60 };
64 61
65 WorkerPoolTaskRunner::WorkerPoolTaskRunner(bool tasks_are_slow) 62 WorkerPoolTaskRunner::WorkerPoolTaskRunner(bool tasks_are_slow)
66 : tasks_are_slow_(tasks_are_slow) { 63 : tasks_are_slow_(tasks_are_slow) {
67 } 64 }
68 65
69 WorkerPoolTaskRunner::~WorkerPoolTaskRunner() { 66 WorkerPoolTaskRunner::~WorkerPoolTaskRunner() {
70 } 67 }
71 68
72 bool WorkerPoolTaskRunner::PostDelayedTask( 69 bool WorkerPoolTaskRunner::PostDelayedTask(
73 const tracked_objects::Location& from_here, 70 const tracked_objects::Location& from_here,
74 const Closure& task, 71 const Closure& task,
75 int64 delay_ms) {
76 return PostDelayedTaskAssertZeroDelay(from_here, task, delay_ms);
77 }
78
79 bool WorkerPoolTaskRunner::PostDelayedTask(
80 const tracked_objects::Location& from_here,
81 const Closure& task,
82 TimeDelta delay) { 72 TimeDelta delay) {
83 return PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp()); 73 return PostDelayedTaskAssertZeroDelay(from_here, task, delay);
84 } 74 }
85 75
86 bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { 76 bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const {
87 return WorkerPool::RunsTasksOnCurrentThread(); 77 return WorkerPool::RunsTasksOnCurrentThread();
88 } 78 }
89 79
90 bool WorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( 80 bool WorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay(
91 const tracked_objects::Location& from_here, 81 const tracked_objects::Location& from_here,
92 const Closure& task, 82 const Closure& task,
93 int64 delay_ms) { 83 base::TimeDelta delay) {
94 DCHECK_EQ(delay_ms, 0) 84 DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0)
95 << "WorkerPoolTaskRunner does not support non-zero delays"; 85 << "WorkerPoolTaskRunner does not support non-zero delays";
96 return WorkerPool::PostTask(from_here, task, tasks_are_slow_); 86 return WorkerPool::PostTask(from_here, task, tasks_are_slow_);
97 } 87 }
98 88
99 struct TaskRunnerHolder { 89 struct TaskRunnerHolder {
100 TaskRunnerHolder() { 90 TaskRunnerHolder() {
101 taskrunners_[0] = new WorkerPoolTaskRunner(false); 91 taskrunners_[0] = new WorkerPoolTaskRunner(false);
102 taskrunners_[1] = new WorkerPoolTaskRunner(true); 92 taskrunners_[1] = new WorkerPoolTaskRunner(true);
103 } 93 }
104 scoped_refptr<TaskRunner> taskrunners_[2]; 94 scoped_refptr<TaskRunner> taskrunners_[2];
(...skipping 12 matching lines...) Expand all
117 from_here, task, reply); 107 from_here, task, reply);
118 } 108 }
119 109
120 // static 110 // static
121 const scoped_refptr<TaskRunner>& 111 const scoped_refptr<TaskRunner>&
122 WorkerPool::GetTaskRunner(bool tasks_are_slow) { 112 WorkerPool::GetTaskRunner(bool tasks_are_slow) {
123 return g_taskrunners.Get().taskrunners_[tasks_are_slow]; 113 return g_taskrunners.Get().taskrunners_[tasks_are_slow];
124 } 114 }
125 115
126 } // namespace base 116 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool_task_runner.cc ('k') | chrome/browser/policy/cloud_policy_refresh_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698