OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/WebTaskRunner.h" | 5 #include "platform/WebTaskRunner.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // can lead to data races with ref counted objects like StringImpl. See | 120 // can lead to data races with ref counted objects like StringImpl. See |
121 // crbug.com/679915 for more details. | 121 // crbug.com/679915 for more details. |
122 void WebTaskRunner::PostTask(const WebTraceLocation& location, | 122 void WebTaskRunner::PostTask(const WebTraceLocation& location, |
123 std::unique_ptr<CrossThreadClosure> task) { | 123 std::unique_ptr<CrossThreadClosure> task) { |
124 ToSingleThreadTaskRunner()->PostTask( | 124 ToSingleThreadTaskRunner()->PostTask( |
125 location, base::Bind(&RunCrossThreadClosure, base::Passed(&task))); | 125 location, base::Bind(&RunCrossThreadClosure, base::Passed(&task))); |
126 } | 126 } |
127 | 127 |
128 void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location, | 128 void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location, |
129 std::unique_ptr<CrossThreadClosure> task, | 129 std::unique_ptr<CrossThreadClosure> task, |
130 long long delay_ms) { | 130 WTF::TimeDelta delay) { |
131 ToSingleThreadTaskRunner()->PostDelayedTask( | 131 ToSingleThreadTaskRunner()->PostDelayedTask( |
132 location, base::Bind(&RunCrossThreadClosure, base::Passed(&task)), | 132 location, base::Bind(&RunCrossThreadClosure, base::Passed(&task)), delay); |
133 base::TimeDelta::FromMilliseconds(delay_ms)); | |
134 } | 133 } |
135 | 134 |
136 void WebTaskRunner::PostTask(const WebTraceLocation& location, | 135 void WebTaskRunner::PostTask(const WebTraceLocation& location, |
137 std::unique_ptr<WTF::Closure> task) { | 136 std::unique_ptr<WTF::Closure> task) { |
138 ToSingleThreadTaskRunner()->PostTask(location, | 137 ToSingleThreadTaskRunner()->PostTask(location, |
139 ConvertToBaseCallback(std::move(task))); | 138 ConvertToBaseCallback(std::move(task))); |
140 } | 139 } |
141 | 140 |
142 void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location, | 141 void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location, |
143 std::unique_ptr<WTF::Closure> task, | 142 std::unique_ptr<WTF::Closure> task, |
144 long long delay_ms) { | 143 WTF::TimeDelta delay) { |
145 ToSingleThreadTaskRunner()->PostDelayedTask( | 144 ToSingleThreadTaskRunner()->PostDelayedTask( |
146 location, ConvertToBaseCallback(std::move(task)), | 145 location, ConvertToBaseCallback(std::move(task)), delay); |
147 base::TimeDelta::FromMilliseconds(delay_ms)); | |
148 } | 146 } |
149 | 147 |
150 TaskHandle WebTaskRunner::PostCancellableTask( | 148 TaskHandle WebTaskRunner::PostCancellableTask( |
151 const WebTraceLocation& location, | 149 const WebTraceLocation& location, |
152 std::unique_ptr<WTF::Closure> task) { | 150 std::unique_ptr<WTF::Closure> task) { |
153 DCHECK(RunsTasksOnCurrentThread()); | 151 DCHECK(RunsTasksOnCurrentThread()); |
154 RefPtr<TaskHandle::Runner> runner = | 152 RefPtr<TaskHandle::Runner> runner = |
155 AdoptRef(new TaskHandle::Runner(std::move(task))); | 153 AdoptRef(new TaskHandle::Runner(std::move(task))); |
156 PostTask(location, WTF::Bind(&TaskHandle::Runner::Run, runner->AsWeakPtr(), | 154 PostTask(location, WTF::Bind(&TaskHandle::Runner::Run, runner->AsWeakPtr(), |
157 TaskHandle(runner))); | 155 TaskHandle(runner))); |
158 return TaskHandle(runner); | 156 return TaskHandle(runner); |
159 } | 157 } |
160 | 158 |
161 TaskHandle WebTaskRunner::PostDelayedCancellableTask( | 159 TaskHandle WebTaskRunner::PostDelayedCancellableTask( |
162 const WebTraceLocation& location, | 160 const WebTraceLocation& location, |
163 std::unique_ptr<WTF::Closure> task, | 161 std::unique_ptr<WTF::Closure> task, |
164 long long delay_ms) { | 162 WTF::TimeDelta delay) { |
165 DCHECK(RunsTasksOnCurrentThread()); | 163 DCHECK(RunsTasksOnCurrentThread()); |
166 RefPtr<TaskHandle::Runner> runner = | 164 RefPtr<TaskHandle::Runner> runner = |
167 AdoptRef(new TaskHandle::Runner(std::move(task))); | 165 AdoptRef(new TaskHandle::Runner(std::move(task))); |
168 PostDelayedTask(location, | 166 PostDelayedTask(location, |
169 WTF::Bind(&TaskHandle::Runner::Run, runner->AsWeakPtr(), | 167 WTF::Bind(&TaskHandle::Runner::Run, runner->AsWeakPtr(), |
170 TaskHandle(runner)), | 168 TaskHandle(runner)), |
171 delay_ms); | 169 delay); |
172 return TaskHandle(runner); | 170 return TaskHandle(runner); |
173 } | 171 } |
174 | 172 |
175 WebTaskRunner::~WebTaskRunner() = default; | 173 WebTaskRunner::~WebTaskRunner() = default; |
176 | 174 |
177 } // namespace blink | 175 } // namespace blink |
OLD | NEW |