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

Unified Diff: third_party/WebKit/Source/wtf/MakeCancellable.h

Issue 2322253002: Use WTF::WeakPtr in WTF::makeCancellable (Closed)
Patch Set: +test Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/MakeCancellableTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/MakeCancellableTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698