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 public: | |
|
jochen (gone - plz use gerrit)
2015/01/26 15:53:31
nit. also make this non copyable
alex clarke (OOO till 29th)
2015/01/26 17:00:45
Done.
| |
| 39 explicit CancellableTask(WeakPtr<CancellableTaskFactory> weakPtr) : m_we akPtr(weakPtr) { } | |
|
Sami
2015/01/26 16:08:14
nit: Something like |factory| would be a little mo
| |
| 40 virtual ~CancellableTask() { } | |
| 41 | |
| 42 void run() override; | |
| 43 | |
| 44 private: | |
| 45 WeakPtr<CancellableTaskFactory> m_weakPtr; | |
| 46 }; | |
| 47 | |
| 48 void runInternal(); | |
| 49 | |
| 50 OwnPtr<Closure> m_closure; | |
| 51 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; | |
| 52 | |
| 53 friend class CancellableTask; | |
| 54 }; | |
| 55 | |
| 56 } // namespace blink | |
| 57 | |
| 58 #endif // CancellableTaskFactory_h | |
| OLD | NEW |