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

Unified Diff: Source/core/workers/WorkerScriptLoader.cpp

Issue 1213443006: Invoke WorkerScriptLoader's m_finishedCallback callback safely. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review #3 Created 5 years, 6 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
Index: Source/core/workers/WorkerScriptLoader.cpp
diff --git a/Source/core/workers/WorkerScriptLoader.cpp b/Source/core/workers/WorkerScriptLoader.cpp
index 15dee1bffecaf174eb8588d8fefcd8e87308edb9..89e190b472133b86c1ed37938fed9675b349c92d 100644
--- a/Source/core/workers/WorkerScriptLoader.cpp
+++ b/Source/core/workers/WorkerScriptLoader.cpp
@@ -47,7 +47,6 @@ WorkerScriptLoader::WorkerScriptLoader()
, m_failed(false)
, m_identifier(0)
, m_appCacheID(0)
- , m_finishing(false)
, m_requestContext(WebURLRequest::RequestContextWorker)
{
}
@@ -95,6 +94,9 @@ void WorkerScriptLoader::loadAsynchronously(ExecutionContext& executionContext,
resourceLoaderOptions.allowCredentials = AllowStoredCredentials;
m_threadableLoader = ThreadableLoader::create(executionContext, this, *request, options, resourceLoaderOptions);
+ if (m_failed)
+ notifyFinished();
+ // Do nothing here since notifyFinished() could delete |this|.
}
const KURL& WorkerScriptLoader::responseURL() const
@@ -178,7 +180,14 @@ void WorkerScriptLoader::didFailRedirectCheck()
void WorkerScriptLoader::notifyError()
{
m_failed = true;
- notifyFinished();
+ // notifyError() could be called before ThreadableLoader::create() returns
+ // e.g. from didFail(), and in that case m_threadableLoader is not yet set
+ // (i.e. still null).
+ // Since the callback invocation in notifyFinished() potentially delete
haraken 2015/07/02 06:18:06 Another way to avoid this would be to make WorkerS
Takashi Toyoshima 2015/07/02 07:33:56 Yep, originally this class was RefCounted, and I c
+ // |this| object, the callback invocation should be postponed until the
+ // create() call returns. See loadAsynchronously() for the postponed call.
+ if (m_threadableLoader)
+ notifyFinished();
}
void WorkerScriptLoader::cancel()
@@ -194,12 +203,12 @@ String WorkerScriptLoader::script()
void WorkerScriptLoader::notifyFinished()
haraken 2015/07/02 06:18:06 If this method is invoked only in a case where som
Takashi Toyoshima 2015/07/02 07:33:56 Good point. Maybe we should use notifyFinished() e
{
- if (!m_finishedCallback || m_finishing)
+ ASSERT(m_failed);
+ if (!m_finishedCallback)
return;
- m_finishing = true;
- if (m_finishedCallback)
- (*m_finishedCallback)();
+ OwnPtr<Closure> callback = m_finishedCallback.release();
+ (*callback)();
}
void WorkerScriptLoader::processContentSecurityPolicy(const ResourceResponse& response)

Powered by Google App Engine
This is Rietveld 408576698