| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 TaskHandle& TaskHandle::operator=(TaskHandle&& other) { | 104 TaskHandle& TaskHandle::operator=(TaskHandle&& other) { |
| 105 TaskHandle tmp(std::move(other)); | 105 TaskHandle tmp(std::move(other)); |
| 106 runner_.Swap(tmp.runner_); | 106 runner_.Swap(tmp.runner_); |
| 107 return *this; | 107 return *this; |
| 108 } | 108 } |
| 109 | 109 |
| 110 TaskHandle::TaskHandle(RefPtr<Runner> runner) : runner_(std::move(runner)) { | 110 TaskHandle::TaskHandle(RefPtr<Runner> runner) : runner_(std::move(runner)) { |
| 111 DCHECK(runner_); | 111 DCHECK(runner_); |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool WebTaskRunner::RunsTasksOnCurrentThread() { | |
| 115 return RunsTasksInCurrentSequence(); | |
| 116 } | |
| 117 | |
| 118 // Use a custom function for base::Bind instead of convertToBaseCallback to | 114 // Use a custom function for base::Bind instead of convertToBaseCallback to |
| 119 // avoid copying the closure later in the call chain. Copying the bound state | 115 // avoid copying the closure later in the call chain. Copying the bound state |
| 120 // can lead to data races with ref counted objects like StringImpl. See | 116 // can lead to data races with ref counted objects like StringImpl. See |
| 121 // crbug.com/679915 for more details. | 117 // crbug.com/679915 for more details. |
| 122 void WebTaskRunner::PostTask(const WebTraceLocation& location, | 118 void WebTaskRunner::PostTask(const WebTraceLocation& location, |
| 123 std::unique_ptr<CrossThreadClosure> task) { | 119 std::unique_ptr<CrossThreadClosure> task) { |
| 124 ToSingleThreadTaskRunner()->PostTask( | 120 ToSingleThreadTaskRunner()->PostTask( |
| 125 location, base::Bind(&RunCrossThreadClosure, base::Passed(&task))); | 121 location, base::Bind(&RunCrossThreadClosure, base::Passed(&task))); |
| 126 } | 122 } |
| 127 | 123 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 141 void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location, | 137 void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location, |
| 142 std::unique_ptr<WTF::Closure> task, | 138 std::unique_ptr<WTF::Closure> task, |
| 143 TimeDelta delay) { | 139 TimeDelta delay) { |
| 144 ToSingleThreadTaskRunner()->PostDelayedTask( | 140 ToSingleThreadTaskRunner()->PostDelayedTask( |
| 145 location, ConvertToBaseCallback(std::move(task)), delay); | 141 location, ConvertToBaseCallback(std::move(task)), delay); |
| 146 } | 142 } |
| 147 | 143 |
| 148 TaskHandle WebTaskRunner::PostCancellableTask( | 144 TaskHandle WebTaskRunner::PostCancellableTask( |
| 149 const WebTraceLocation& location, | 145 const WebTraceLocation& location, |
| 150 std::unique_ptr<WTF::Closure> task) { | 146 std::unique_ptr<WTF::Closure> task) { |
| 151 DCHECK(RunsTasksOnCurrentThread()); | 147 DCHECK(RunsTasksInCurrentSequence()); |
| 152 RefPtr<TaskHandle::Runner> runner = | 148 RefPtr<TaskHandle::Runner> runner = |
| 153 AdoptRef(new TaskHandle::Runner(std::move(task))); | 149 AdoptRef(new TaskHandle::Runner(std::move(task))); |
| 154 PostTask(location, WTF::Bind(&TaskHandle::Runner::Run, runner->AsWeakPtr(), | 150 PostTask(location, WTF::Bind(&TaskHandle::Runner::Run, runner->AsWeakPtr(), |
| 155 TaskHandle(runner))); | 151 TaskHandle(runner))); |
| 156 return TaskHandle(runner); | 152 return TaskHandle(runner); |
| 157 } | 153 } |
| 158 | 154 |
| 159 TaskHandle WebTaskRunner::PostDelayedCancellableTask( | 155 TaskHandle WebTaskRunner::PostDelayedCancellableTask( |
| 160 const WebTraceLocation& location, | 156 const WebTraceLocation& location, |
| 161 std::unique_ptr<WTF::Closure> task, | 157 std::unique_ptr<WTF::Closure> task, |
| 162 TimeDelta delay) { | 158 TimeDelta delay) { |
| 163 DCHECK(RunsTasksOnCurrentThread()); | 159 DCHECK(RunsTasksInCurrentSequence()); |
| 164 RefPtr<TaskHandle::Runner> runner = | 160 RefPtr<TaskHandle::Runner> runner = |
| 165 AdoptRef(new TaskHandle::Runner(std::move(task))); | 161 AdoptRef(new TaskHandle::Runner(std::move(task))); |
| 166 PostDelayedTask(location, | 162 PostDelayedTask(location, |
| 167 WTF::Bind(&TaskHandle::Runner::Run, runner->AsWeakPtr(), | 163 WTF::Bind(&TaskHandle::Runner::Run, runner->AsWeakPtr(), |
| 168 TaskHandle(runner)), | 164 TaskHandle(runner)), |
| 169 delay); | 165 delay); |
| 170 return TaskHandle(runner); | 166 return TaskHandle(runner); |
| 171 } | 167 } |
| 172 | 168 |
| 173 WebTaskRunner::~WebTaskRunner() = default; | 169 WebTaskRunner::~WebTaskRunner() = default; |
| 174 | 170 |
| 175 } // namespace blink | 171 } // namespace blink |
| OLD | NEW |