OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CancellableTaskFactory_h |
| 6 #define CancellableTaskFactory_h |
| 7 |
| 8 #include "platform/PlatformExport.h" |
| 9 #include "public/platform/WebScheduler.h" |
| 10 #include "wtf/Functional.h" |
| 11 #include "wtf/Noncopyable.h" |
| 12 #include "wtf/OwnPtr.h" |
| 13 #include "wtf/PassOwnPtr.h" |
| 14 #include "wtf/RefCounted.h" |
| 15 #include "wtf/WeakPtr.h" |
| 16 |
| 17 namespace blink { |
| 18 class TraceLocation; |
| 19 |
| 20 class PLATFORM_EXPORT CancellableTaskFactory { |
| 21 WTF_MAKE_NONCOPYABLE(CancellableTaskFactory); |
| 22 |
| 23 public: |
| 24 explicit CancellableTaskFactory(PassOwnPtr<Closure> closure) |
| 25 : m_closure(closure) |
| 26 , m_weakPtrFactory(this) |
| 27 { |
| 28 } |
| 29 |
| 30 bool isPending() const |
| 31 { |
| 32 return m_weakPtrFactory.hasWeakPtrs(); |
| 33 } |
| 34 |
| 35 void cancel(); |
| 36 |
| 37 // Returns a task that can be disabled by calling cancel(). The user takes |
| 38 // ownership of the task. Creating a new task cancels any previous ones. |
| 39 WebThread::Task* task(); |
| 40 |
| 41 private: |
| 42 class CancellableTask : public WebThread::Task { |
| 43 WTF_MAKE_NONCOPYABLE(CancellableTask); |
| 44 |
| 45 public: |
| 46 explicit CancellableTask(WeakPtr<CancellableTaskFactory> weakPtr) |
| 47 : m_weakPtr(weakPtr) { } |
| 48 |
| 49 virtual ~CancellableTask() { } |
| 50 |
| 51 void run() override; |
| 52 |
| 53 private: |
| 54 WeakPtr<CancellableTaskFactory> m_weakPtr; |
| 55 }; |
| 56 |
| 57 OwnPtr<Closure> m_closure; |
| 58 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; |
| 59 }; |
| 60 |
| 61 } // namespace blink |
| 62 |
| 63 #endif // CancellableTaskFactory_h |
OLD | NEW |