| 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/WebScheduler.h" | 10 #include "public/platform/WebScheduler.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // by Oilpan. | 30 // by Oilpan. |
| 31 // | 31 // |
| 32 // In the Oilpan case, as WTF::Closure objects are off-heap, we have to cons
truct the | 32 // In the Oilpan case, as WTF::Closure objects are off-heap, we have to cons
truct 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 PassOwnPtr<CancellableTaskFactory> create(T* thisObject, void (T::*me
thod)(), typename WTF::EnableIf<IsGarbageCollectedType<T>::value>::Type* = nullp
tr) | 40 static PassOwnPtr<CancellableTaskFactory> create(T* thisObject, void (T::*me
thod)(), typename std::enable_if<IsGarbageCollectedType<T>::value>::type* = null
ptr) |
| 41 { | 41 { |
| 42 return adoptPtr(new CancellableTaskFactory(WTF::bind(method, AllowCrossT
hreadWeakPersistent<T>(thisObject)))); | 42 return adoptPtr(new CancellableTaskFactory(WTF::bind(method, AllowCrossT
hreadWeakPersistent<T>(thisObject)))); |
| 43 } | 43 } |
| 44 | 44 |
| 45 template<typename T> | 45 template<typename T> |
| 46 static PassOwnPtr<CancellableTaskFactory> create(T* thisObject, void (T::*me
thod)(), typename WTF::EnableIf<!IsGarbageCollectedType<T>::value>::Type* = null
ptr) | 46 static PassOwnPtr<CancellableTaskFactory> create(T* thisObject, void (T::*me
thod)(), typename std::enable_if<!IsGarbageCollectedType<T>::value>::type* = nul
lptr) |
| 47 { | 47 { |
| 48 return adoptPtr(new CancellableTaskFactory(WTF::bind(method, thisObject)
)); | 48 return adoptPtr(new CancellableTaskFactory(WTF::bind(method, thisObject)
)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool isPending() const | 51 bool isPending() const |
| 52 { | 52 { |
| 53 return m_weakPtrFactory.hasWeakPtrs(); | 53 return m_weakPtrFactory.hasWeakPtrs(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void cancel(); | 56 void cancel(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 WeakPtr<CancellableTaskFactory> m_weakPtr; | 84 WeakPtr<CancellableTaskFactory> m_weakPtr; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 OwnPtr<Closure> m_closure; | 87 OwnPtr<Closure> m_closure; |
| 88 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; | 88 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 } // namespace blink | 91 } // namespace blink |
| 92 | 92 |
| 93 #endif // CancellableTaskFactory_h | 93 #endif // CancellableTaskFactory_h |
| OLD | NEW |