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

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

Issue 10496002: Revert 140102 - Remove old PostDelayedTask interfaces that use int ms instead of TimeDelta. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
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,
44 TimeDelta delay) OVERRIDE; 47 TimeDelta delay) OVERRIDE;
45 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; 48 virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
46 49
47 private: 50 private:
48 virtual ~WorkerPoolTaskRunner(); 51 virtual ~WorkerPoolTaskRunner();
49 52
50 // Helper function for posting a delayed task. Asserts that the delay is 53 // Helper function for posting a delayed task. Asserts that the delay is
51 // zero because non-zero delays are not supported. 54 // zero because non-zero delays are not supported.
52 bool PostDelayedTaskAssertZeroDelay( 55 bool PostDelayedTaskAssertZeroDelay(
53 const tracked_objects::Location& from_here, 56 const tracked_objects::Location& from_here,
54 const Closure& task, 57 const Closure& task,
55 base::TimeDelta delay); 58 int64 delay_ms);
56 59
57 const bool tasks_are_slow_; 60 const bool tasks_are_slow_;
58 61
59 DISALLOW_COPY_AND_ASSIGN(WorkerPoolTaskRunner); 62 DISALLOW_COPY_AND_ASSIGN(WorkerPoolTaskRunner);
60 }; 63 };
61 64
62 WorkerPoolTaskRunner::WorkerPoolTaskRunner(bool tasks_are_slow) 65 WorkerPoolTaskRunner::WorkerPoolTaskRunner(bool tasks_are_slow)
63 : tasks_are_slow_(tasks_are_slow) { 66 : tasks_are_slow_(tasks_are_slow) {
64 } 67 }
65 68
66 WorkerPoolTaskRunner::~WorkerPoolTaskRunner() { 69 WorkerPoolTaskRunner::~WorkerPoolTaskRunner() {
67 } 70 }
68 71
69 bool WorkerPoolTaskRunner::PostDelayedTask( 72 bool WorkerPoolTaskRunner::PostDelayedTask(
70 const tracked_objects::Location& from_here, 73 const tracked_objects::Location& from_here,
71 const Closure& task, 74 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,
72 TimeDelta delay) { 82 TimeDelta delay) {
73 return PostDelayedTaskAssertZeroDelay(from_here, task, delay); 83 return PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
74 } 84 }
75 85
76 bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { 86 bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const {
77 return WorkerPool::RunsTasksOnCurrentThread(); 87 return WorkerPool::RunsTasksOnCurrentThread();
78 } 88 }
79 89
80 bool WorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( 90 bool WorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay(
81 const tracked_objects::Location& from_here, 91 const tracked_objects::Location& from_here,
82 const Closure& task, 92 const Closure& task,
83 base::TimeDelta delay) { 93 int64 delay_ms) {
84 DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0) 94 DCHECK_EQ(delay_ms, 0)
85 << "WorkerPoolTaskRunner does not support non-zero delays"; 95 << "WorkerPoolTaskRunner does not support non-zero delays";
86 return WorkerPool::PostTask(from_here, task, tasks_are_slow_); 96 return WorkerPool::PostTask(from_here, task, tasks_are_slow_);
87 } 97 }
88 98
89 struct TaskRunnerHolder { 99 struct TaskRunnerHolder {
90 TaskRunnerHolder() { 100 TaskRunnerHolder() {
91 taskrunners_[0] = new WorkerPoolTaskRunner(false); 101 taskrunners_[0] = new WorkerPoolTaskRunner(false);
92 taskrunners_[1] = new WorkerPoolTaskRunner(true); 102 taskrunners_[1] = new WorkerPoolTaskRunner(true);
93 } 103 }
94 scoped_refptr<TaskRunner> taskrunners_[2]; 104 scoped_refptr<TaskRunner> taskrunners_[2];
(...skipping 12 matching lines...) Expand all
107 from_here, task, reply); 117 from_here, task, reply);
108 } 118 }
109 119
110 // static 120 // static
111 const scoped_refptr<TaskRunner>& 121 const scoped_refptr<TaskRunner>&
112 WorkerPool::GetTaskRunner(bool tasks_are_slow) { 122 WorkerPool::GetTaskRunner(bool tasks_are_slow) {
113 return g_taskrunners.Get().taskrunners_[tasks_are_slow]; 123 return g_taskrunners.Get().taskrunners_[tasks_are_slow];
114 } 124 }
115 125
116 } // namespace base 126 } // 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