| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // In the Oilpan case, as WTF::SameThreadClosure objects are off-heap, we ha
ve to construct the | 32 // In the Oilpan case, as WTF::SameThreadClosure objects are off-heap, we ha
ve to construct the |
| 33 // closure in such a manner that it doesn't end up referring back to the own
ing heap | 33 // closure in such a manner that it doesn't end up referring back to the own
ing heap |
| 34 // object with a strong Persistent<> GC root reference. If we do, this will
create | 34 // object with a strong Persistent<> GC root reference. If we do, this will
create |
| 35 // a heap <-> off-heap cycle and leak, the owning object can never be GCed. | 35 // a heap <-> off-heap cycle and leak, the owning object can never be GCed. |
| 36 // Instead, the closure will keep an off-heap persistent reference of the we
ak | 36 // Instead, the closure will keep an off-heap persistent reference of the we
ak |
| 37 // variety, which will refer back to the owner heap object safely (but weakl
y.) | 37 // variety, which will refer back to the owner heap object safely (but weakl
y.) |
| 38 // | 38 // |
| 39 template<typename T> | 39 template<typename T> |
| 40 static std::unique_ptr<CancellableTaskFactory> create(T* thisObject, void (T
::*method)(), typename std::enable_if<IsGarbageCollectedType<T>::value>::type* =
nullptr) | 40 static std::unique_ptr<CancellableTaskFactory> create(T* thisObject, void (T
::*method)(), typename std::enable_if<IsGarbageCollectedType<T>::value>::type* =
nullptr) |
| 41 { | 41 { |
| 42 return wrapUnique(new CancellableTaskFactory(WTF::bind(method, CrossThre
adWeakPersistentThisPointer<T>(thisObject)))); | 42 return wrapUnique(new CancellableTaskFactory(WTF::bind(method, wrapWeakP
ersistent(thisObject)))); |
| 43 } | 43 } |
| 44 | 44 |
| 45 template<typename T> | 45 template<typename T> |
| 46 static std::unique_ptr<CancellableTaskFactory> create(T* thisObject, void (T
::*method)(), typename std::enable_if<!IsGarbageCollectedType<T>::value>::type*
= nullptr) | 46 static std::unique_ptr<CancellableTaskFactory> create(T* thisObject, void (T
::*method)(), typename std::enable_if<!IsGarbageCollectedType<T>::value>::type*
= nullptr) |
| 47 { | 47 { |
| 48 return wrapUnique(new CancellableTaskFactory(WTF::bind(method, WTF::unre
tained(thisObject)))); | 48 return wrapUnique(new CancellableTaskFactory(WTF::bind(method, WTF::unre
tained(thisObject)))); |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool isPending() const | 51 bool isPending() const |
| 52 { | 52 { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 WeakPtr<CancellableTaskFactory> m_weakPtr; | 85 WeakPtr<CancellableTaskFactory> m_weakPtr; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 std::unique_ptr<SameThreadClosure> m_closure; | 88 std::unique_ptr<SameThreadClosure> m_closure; |
| 89 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; | 89 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 } // namespace blink | 92 } // namespace blink |
| 93 | 93 |
| 94 #endif // CancellableTaskFactory_h | 94 #endif // CancellableTaskFactory_h |
| OLD | NEW |