Chromium Code Reviews| 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 #ifndef CancellableTaskFactory_h | 5 #ifndef CancellableTaskFactory_h |
| 6 #define CancellableTaskFactory_h | 6 #define CancellableTaskFactory_h |
| 7 | 7 |
| 8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 10 #include "public/platform/WebTaskRunner.h" | 10 #include "public/platform/WebTaskRunner.h" |
| 11 #include "wtf/Allocator.h" | 11 #include "wtf/Allocator.h" |
| 12 #include "wtf/Functional.h" | 12 #include "wtf/Functional.h" |
| 13 #include "wtf/Noncopyable.h" | 13 #include "wtf/Noncopyable.h" |
| 14 #include "wtf/PtrUtil.h" | 14 #include "wtf/PtrUtil.h" |
| 15 #include "wtf/WeakPtr.h" | 15 #include "wtf/WeakPtr.h" |
| 16 #include <memory> | 16 #include <memory> |
| 17 #include <type_traits> | 17 #include <type_traits> |
| 18 | 18 |
| 19 // WebTaskRunner::postCancellableTask will replace CancellableTaskFactory. | |
| 20 // Use postCancellableTask in new code. | |
| 21 // Example: For |task_runner| and |foo| below. | |
| 22 // WebTaskRunner* task_runner; | |
| 23 // Foo* foo; | |
| 24 // | |
| 25 // CancellableTaskFactory factory(foo, &Foo::bar); | |
| 26 // task_runner->postTask(BLINK_FROM_HERE, factory.cancelAndCreate()); | |
| 27 // factory.cancel(); | |
| 28 // | |
| 29 // Above is equivalent to below: | |
| 30 // | |
| 31 // std::unique_ptr<WTF::Closure> task = | |
| 32 // WTF::bind(wrapPersistent(foo), &Foo::bar); | |
| 33 // RefPtr<TaskHandle> handle = | |
| 34 // task_runner->postCancellableTask(BLINK_FROM_HERE, std::move(task)); | |
| 35 // handle->cancel(); | |
| 36 // | |
| 37 // Note that the task is not automatically cancelled on TaskHandle scope out. | |
|
Sami
2016/10/26 12:32:51
Is the last sentence still accurate?
tzik
2016/10/27 06:38:53
Yes, it's mostly still valid. Added a comment to m
| |
| 38 | |
| 19 namespace blink { | 39 namespace blink { |
| 20 | 40 |
| 21 class TraceLocation; | 41 class TraceLocation; |
| 22 | 42 |
| 23 class PLATFORM_EXPORT CancellableTaskFactory { | 43 class PLATFORM_EXPORT CancellableTaskFactory { |
| 24 WTF_MAKE_NONCOPYABLE(CancellableTaskFactory); | 44 WTF_MAKE_NONCOPYABLE(CancellableTaskFactory); |
| 25 USING_FAST_MALLOC(CancellableTaskFactory); | 45 USING_FAST_MALLOC(CancellableTaskFactory); |
| 26 | 46 |
| 27 public: | 47 public: |
| 28 // A pair of mutually exclusive factory methods are provided for constructing | 48 // A pair of mutually exclusive factory methods are provided for constructing |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 WeakPtr<CancellableTaskFactory> m_weakPtr; | 109 WeakPtr<CancellableTaskFactory> m_weakPtr; |
| 90 }; | 110 }; |
| 91 | 111 |
| 92 std::unique_ptr<WTF::Closure> m_closure; | 112 std::unique_ptr<WTF::Closure> m_closure; |
| 93 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; | 113 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; |
| 94 }; | 114 }; |
| 95 | 115 |
| 96 } // namespace blink | 116 } // namespace blink |
| 97 | 117 |
| 98 #endif // CancellableTaskFactory_h | 118 #endif // CancellableTaskFactory_h |
| OLD | NEW |