Chromium Code Reviews| 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 public: | |
| 23 explicit CancellableTaskFactory(PassOwnPtr<Closure> closure) : m_closure(clo sure), m_weakPtrFactory(this) { } | |
| 24 | |
| 25 bool isPending() const | |
| 26 { | |
| 27 return m_weakPtrFactory.hasWeakPtrs(); | |
| 28 } | |
| 29 | |
| 30 void cancel(); | |
| 31 | |
| 32 // Returns a task that can be disabled by calling cancel(). The user takes | |
| 33 // ownership of the task. Creating a new task cancels any previous ones. | |
| 34 WebThread::Task* task(); | |
| 35 | |
| 36 private: | |
| 37 class CancellableTask : public WebThread::Task { | |
| 38 WTF_MAKE_NONCOPYABLE(CancellableTask); | |
| 39 public: | |
| 40 explicit CancellableTask(WeakPtr<CancellableTaskFactory> weakPtr) : m_we akPtr(weakPtr) { } | |
| 41 virtual ~CancellableTask() { } | |
| 42 | |
| 43 void run() override; | |
| 44 | |
| 45 private: | |
| 46 WeakPtr<CancellableTaskFactory> m_weakPtr; | |
| 47 }; | |
| 48 | |
| 49 OwnPtr<Closure> m_closure; | |
| 50 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; | |
| 51 | |
| 52 friend class CancellableTask; | |
|
jochen (gone - plz use gerrit)
2015/01/27 09:59:20
inner classes are automatically friends, no?
alex clarke (OOO till 29th)
2015/01/27 11:41:19
Done.
| |
| 53 }; | |
| 54 | |
| 55 } // namespace blink | |
| 56 | |
| 57 #endif // CancellableTaskFactory_h | |
| OLD | NEW |