Bug 1742438 - Prep Part 6: CacheCreator is managed by ScriptLoadInfo, not WorkerScriptLoader; r=asuth

This follows up the cancellation requirements -- CacheCreator is a main thread only datastructure,
which must be cleaned up once the last ScriptLoadInfo is dispatched. Previously, we determined this
via iteration. Now, we manage it as part of ScriptLoadInfo, and release our reference to it when we
dispatch a given ScriptLoadInfo. Later, once we transition to ScriptLoadRequest and LoadContexts,
the cache information can live on a ServiceWorkerLoadContext[1]. This will help use differentiate
between regular worker loader environments and service worker environments.

[1]: https://searchfox.org/mozilla-central/rev/997a56b018662e2940c99bbaf57a6ac9d1aa5422/js/loader/LoadContextBase.h#22-34

Differential Revision: https://phabricator.services.mozilla.com/D145448
This commit is contained in:
Yulia Startsev
2022-07-14 17:07:22 +00:00
parent 3ad3357a52
commit dd548088e7
8 changed files with 86 additions and 51 deletions

View File

@@ -532,12 +532,13 @@ void WorkerScriptLoader::LoadingFinished(ScriptLoadInfo* aLoadInfo,
}
void WorkerScriptLoader::MaybeExecuteFinishedScripts(
const ScriptLoadInfo* aLoadInfo) {
ScriptLoadInfo* aLoadInfo) {
AssertIsOnMainThread();
// We execute the last step if we don't have a pending operation with the
// cache and the loading is completed.
if (aLoadInfo->Finished()) {
aLoadInfo->ClearCacheCreator();
DispatchProcessPendingRequests();
}
}
@@ -613,22 +614,6 @@ void WorkerScriptLoader::CancelMainThread(nsresult aCancelResult) {
}
mCancelMainThread = Some(aCancelResult);
if (mCacheCreator) {
MOZ_ASSERT(mWorkerPrivate->IsServiceWorker());
DeleteCache(aCancelResult);
}
}
void WorkerScriptLoader::DeleteCache(nsresult aReason) {
AssertIsOnMainThread();
if (!mCacheCreator) {
return;
}
mCacheCreator->DeleteCache(aReason);
mCacheCreator = nullptr;
}
nsresult WorkerScriptLoader::LoadScripts() {
@@ -657,12 +642,13 @@ nsresult WorkerScriptLoader::LoadScripts() {
return NS_OK;
}
MOZ_ASSERT(!mCacheCreator);
mCacheCreator = new CacheCreator(mWorkerPrivate);
RefPtr<CacheCreator> cacheCreator = new CacheCreator(mWorkerPrivate);
for (ScriptLoadInfo* loadInfo : mLoadingRequests) {
mCacheCreator->AddLoader(MakeNotNull<RefPtr<CacheLoadHandler>>(
mWorkerPrivate, loadInfo, IsMainWorkerScript(), this));
loadInfo->SetCacheCreator(cacheCreator);
loadInfo->GetCacheCreator()->AddLoader(
MakeNotNull<RefPtr<CacheLoadHandler>>(mWorkerPrivate, loadInfo,
IsMainWorkerScript(), this));
}
// The worker may have a null principal on first load, but in that case its
@@ -674,7 +660,7 @@ nsresult WorkerScriptLoader::LoadScripts() {
principal = parentWorker->GetPrincipal();
}
nsresult rv = mCacheCreator->Load(principal);
nsresult rv = cacheCreator->Load(principal);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@@ -890,10 +876,6 @@ void WorkerScriptLoader::DispatchProcessPendingRequests() {
// If there are no unexecutable load infos, we can unuse things before the
// execution of the scripts and the stopping of the sync loop.
if (loadedScripts.Length()) {
if (mLoadingRequests.IsEmpty()) {
mCacheCreator = nullptr;
}
RefPtr<ScriptExecutorRunnable> runnable = new ScriptExecutorRunnable(
*this, mSyncLoopTarget, std::move(loadedScripts),
/* aAllScriptsExecutable = */ mLoadingRequests.IsEmpty());