| 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/scheduler/CancellableTaskFactory.h" | 6 #include "platform/scheduler/CancellableTaskFactory.h" |
| 7 | 7 |
| 8 #include "public/platform/Platform.h" | |
| 9 #include "wtf/InstanceCounter.h" | |
| 10 | |
| 11 namespace blink { | 8 namespace blink { |
| 12 | 9 |
| 13 void CancellableTaskFactory::cancel() | 10 void CancellableTaskFactory::cancel() |
| 14 { | 11 { |
| 15 m_weakPtrFactory.revokeAll(); | 12 ASSERT(m_thread == currentThread()); |
| 13 |
| 14 if (m_task) { |
| 15 m_task->cancel(); |
| 16 m_task = nullptr; |
| 17 } |
| 16 } | 18 } |
| 17 | 19 |
| 18 WebThread::Task* CancellableTaskFactory::task() | 20 WebThread::Task* CancellableTaskFactory::task() |
| 19 { | 21 { |
| 22 ASSERT(m_thread == currentThread()); |
| 23 |
| 20 cancel(); | 24 cancel(); |
| 21 return new CancellableTask(m_weakPtrFactory.createWeakPtr()); | 25 m_task = new CancellableTask(this); |
| 26 return m_task; |
| 22 } | 27 } |
| 23 | 28 |
| 24 void CancellableTaskFactory::CancellableTask::run() | 29 void CancellableTaskFactory::CancellableTask::run() |
| 25 { | 30 { |
| 26 if (m_weakPtr.get()) { | 31 if (m_factory) { |
| 27 Closure* closure = m_weakPtr->m_closure.get(); | 32 ASSERT(m_factory->m_thread == currentThread()); |
| 28 m_weakPtr->m_weakPtrFactory.revokeAll(); | 33 m_factory->m_task = nullptr; |
| 29 (*closure)(); | 34 (*m_factory->m_closure)(); |
| 35 m_factory = nullptr; |
| 30 } | 36 } |
| 31 } | 37 } |
| 32 | 38 |
| 33 } // namespace blink | 39 } // namespace blink |
| OLD | NEW |