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

Unified Diff: Source/modules/crypto/CryptoResultImpl.cpp

Issue 263163006: Fix crash when ExecutionContext is torn down before a crypto operation has completed. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix comment typo Created 6 years, 7 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 | « Source/bindings/v8/ScriptPromiseResolverWithContext.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/CryptoResultImpl.cpp
diff --git a/Source/modules/crypto/CryptoResultImpl.cpp b/Source/modules/crypto/CryptoResultImpl.cpp
index 13ba840dea5239b1379282550fc7492c5ce111ca..ef38706bf2199217048fb8c5f7092535c17e5ad0 100644
--- a/Source/modules/crypto/CryptoResultImpl.cpp
+++ b/Source/modules/crypto/CryptoResultImpl.cpp
@@ -88,10 +88,10 @@ ExceptionCode toExceptionCode(blink::WebCryptoErrorType errorType)
//
// This is achieved by making CryptoResultImpl hold a WeakPtr to the PromiseState.
// The PromiseState deletes itself after being notified of completion.
-// Additionally the PromiseState deletes itself when the ExecutionContext is
+// Additionally the PromiseState is deleted when the ExecutionContext is
// destroyed (necessary to avoid leaks when dealing with WebWorker threads,
// which may die before the operation is completed).
-class CryptoResultImpl::PromiseState FINAL : public ContextLifecycleObserver {
+class CryptoResultImpl::PromiseState FINAL {
public:
static WeakPtr<PromiseState> create(ExecutionContext* context)
{
@@ -99,10 +99,8 @@ public:
return promiseState->m_weakFactory.createWeakPtr();
}
- // Override from ContextLifecycleObserver
- virtual void contextDestroyed() OVERRIDE
+ void contextDestroyed()
{
- ContextLifecycleObserver::contextDestroyed();
delete this;
}
@@ -142,15 +140,41 @@ public:
}
private:
+ // This subclass of ScriptPromiseResolverWithContext is to be notified
+ // when the context was destroyed.
+ class PromiseResolver FINAL : public ScriptPromiseResolverWithContext {
+ public:
+ static PassRefPtr<PromiseResolver> create(ScriptState* scriptState, PromiseState* promiseState)
+ {
+ RefPtr<PromiseResolver> resolver = adoptRef(new PromiseResolver(scriptState, promiseState));
+ resolver->suspendIfNeeded();
+ return resolver.release();
+ }
+
+ virtual void contextDestroyed() OVERRIDE
+ {
+ ScriptPromiseResolverWithContext::contextDestroyed();
+ m_promiseState->contextDestroyed();
+ }
+
+ private:
+ explicit PromiseResolver(ScriptState* scriptState, PromiseState* promiseState)
+ : ScriptPromiseResolverWithContext(scriptState)
+ , m_promiseState(promiseState)
+ {
+ }
+
+ PromiseState* m_promiseState;
+ };
+
explicit PromiseState(ExecutionContext* context)
- : ContextLifecycleObserver(context)
- , m_weakFactory(this)
- , m_promiseResolver(ScriptPromiseResolverWithContext::create(ScriptState::current(toIsolate(context))))
+ : m_weakFactory(this)
+ , m_promiseResolver(PromiseResolver::create(ScriptState::current(toIsolate(context)), this))
{
}
WeakPtrFactory<PromiseState> m_weakFactory;
- RefPtr<ScriptPromiseResolverWithContext> m_promiseResolver;
+ RefPtr<PromiseResolver> m_promiseResolver;
};
CryptoResultImpl::~CryptoResultImpl()
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolverWithContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698