Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/CancellableTaskFactory.h

Issue 2353913005: Add WebTaskRunner::postCancellableTask (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 the scope out of
38 // RefPtr<TaskHandle>, since the wrapped task has a reference to the TaskHandle.
39
19 namespace blink { 40 namespace blink {
20 41
21 class TraceLocation; 42 class TraceLocation;
22 43
23 class PLATFORM_EXPORT CancellableTaskFactory { 44 class PLATFORM_EXPORT CancellableTaskFactory {
24 WTF_MAKE_NONCOPYABLE(CancellableTaskFactory); 45 WTF_MAKE_NONCOPYABLE(CancellableTaskFactory);
25 USING_FAST_MALLOC(CancellableTaskFactory); 46 USING_FAST_MALLOC(CancellableTaskFactory);
26 47
27 public: 48 public:
28 // A pair of mutually exclusive factory methods are provided for constructing 49 // A pair of mutually exclusive factory methods are provided for constructing
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 WeakPtr<CancellableTaskFactory> m_weakPtr; 110 WeakPtr<CancellableTaskFactory> m_weakPtr;
90 }; 111 };
91 112
92 std::unique_ptr<WTF::Closure> m_closure; 113 std::unique_ptr<WTF::Closure> m_closure;
93 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; 114 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory;
94 }; 115 };
95 116
96 } // namespace blink 117 } // namespace blink
97 118
98 #endif // CancellableTaskFactory_h 119 #endif // CancellableTaskFactory_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698