| Index: third_party/WebKit/Source/wtf/MakeCancellable.h
|
| diff --git a/third_party/WebKit/Source/wtf/MakeCancellable.h b/third_party/WebKit/Source/wtf/MakeCancellable.h
|
| index e1c58cdd486bf29493aa9ebc1619b78f12b9adbb..5340eb3cafda0f2805e62b612717215c7d3b2d5c 100644
|
| --- a/third_party/WebKit/Source/wtf/MakeCancellable.h
|
| +++ b/third_party/WebKit/Source/wtf/MakeCancellable.h
|
| @@ -35,18 +35,25 @@ class FunctionCancellerImpl final : public FunctionCanceller {
|
| public:
|
| FunctionCancellerImpl(std::unique_ptr<Function<void(Params...)>> function)
|
| : m_function(std::move(function))
|
| + , m_weakPtrFactory(this)
|
| {
|
| DCHECK(m_function);
|
| }
|
|
|
| - void runUnlessCancelled(const ScopedFunctionCanceller&, Params... params)
|
| + void run(const ScopedFunctionCanceller&, Params... params)
|
| {
|
| - if (m_function)
|
| - (*m_function)(std::forward<Params>(params)...);
|
| + DCHECK(m_function);
|
| + (*m_function)(std::forward<Params>(params)...);
|
| + }
|
| +
|
| + WeakPtr<FunctionCancellerImpl> createWeakPtr()
|
| + {
|
| + return m_weakPtrFactory.createWeakPtr();
|
| }
|
|
|
| void cancel() override
|
| {
|
| + m_weakPtrFactory.revokeAll();
|
| m_function = nullptr;
|
| }
|
|
|
| @@ -59,6 +66,7 @@ private:
|
| ~FunctionCancellerImpl() override = default;
|
|
|
| std::unique_ptr<WTF::Function<void(Params...)>> m_function;
|
| + WeakPtrFactory<FunctionCancellerImpl<Params...>> m_weakPtrFactory;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(FunctionCancellerImpl);
|
| };
|
| @@ -163,7 +171,7 @@ MakeCancellableResult<Params...> makeCancellable(std::unique_ptr<Function<void(P
|
| // // resolves a circular strong reference:
|
| // // foo -> m_canceller -> m_function -> foo
|
| // result.function = nullptr;
|
| - auto wrappedFunction = bind(&Canceller::runUnlessCancelled, canceller, ScopedFunctionCanceller(canceller));
|
| + auto wrappedFunction = bind(&Canceller::run, canceller->createWeakPtr(), ScopedFunctionCanceller(canceller));
|
| return MakeCancellableResult<Params...>(ScopedFunctionCanceller(canceller.release()), std::move(wrappedFunction));
|
| }
|
|
|
|
|