Commit 0fa1b4bb authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

ServiceWorker: Avoid specific error handling from DidCloseWorkerGlobalScope()

ServiceWorkerGlobalScopeProxy::DidCloseWorkerGlobalScope() is called after
WorkerGlobalScope::close() to report the event somewhere. close() is a common
way to stop worker global scope, so its report function should also be common.
Otherwise, it's difficult to use close() for general purposes.

For that, this CL avoids error handling specific to failures on loading installed
scripts from DidCloseWorkerGlobalScope().

Change-Id: Icd36425f33727c0ea703471a7b376e33e9663784
Bug: 900429
Reviewed-on: https://chromium-review.googlesource.com/c/1309558
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604536}
parent d3c34e80
......@@ -75,6 +75,10 @@ class CORE_EXPORT WorkerReportingProxy {
// via ResourceLoader. Called before WillEvaluateClassicScript().
virtual void DidLoadInstalledScript() {}
// Invoked when it's failed to load the worker's main script from
// InstalledScriptsManager.
virtual void DidFailToLoadInstalledScript() {}
// Invoked when the main classic script is about to be evaluated.
virtual void WillEvaluateClassicScript(size_t script_size,
size_t cached_metadata_size) {}
......
......@@ -155,6 +155,9 @@ void ServiceWorkerGlobalScope::EvaluateClassicScript(
std::unique_ptr<InstalledScriptsManager::ScriptData> script_data =
installed_scripts_manager->GetScriptData(script_url);
if (!script_data) {
ReportingProxy().DidFailToLoadInstalledScript();
// This will eventually initiate worker thread termination. See
// ServiceWorkerGlobalScopeProxy::DidCloseWorkerGlobalScope() for details.
close();
return;
}
......
......@@ -649,6 +649,15 @@ void ServiceWorkerGlobalScopeProxy::DidLoadInstalledScript() {
Client().WorkerScriptLoaded();
}
void ServiceWorkerGlobalScopeProxy::DidFailToLoadInstalledScript() {
DCHECK(WorkerGlobalScope()->IsContextThread());
// Tell ServiceWorkerContextClient about the failure. The generic
// WorkerContextFailedToStart() wouldn't make sense because
// WorkerContextStarted() was already called.
Client().FailedToLoadInstalledScript();
}
void ServiceWorkerGlobalScopeProxy::WillEvaluateClassicScript(
size_t script_size,
size_t cached_metadata_size) {
......@@ -686,18 +695,13 @@ void ServiceWorkerGlobalScopeProxy::DidEvaluateModuleScript(bool success) {
void ServiceWorkerGlobalScopeProxy::DidCloseWorkerGlobalScope() {
DCHECK(WorkerGlobalScope()->IsContextThread());
// close() is not web-exposed. This is called when ServiceWorkerGlobalScope
// internally requests close() due to failure on startup when installed
// scripts couldn't be read.
// close() is not web-exposed for ServiceWorker. This is called when
// ServiceWorkerGlobalScope internally requests close(), for example, due to
// failure on startup when installed scripts couldn't be read.
//
// This may look like a roundabout way to terminate the thread, but close()
// seems like the standard way to initiate termination from inside the thread.
// Tell ServiceWorkerContextClient about the failure. The generic
// WorkerContextFailedToStart() wouldn't make sense because
// WorkerContextStarted() was already called.
Client().FailedToLoadInstalledScript();
// ServiceWorkerGlobalScope expects us to terminate the thread, so request
// that here.
PostCrossThreadTask(
......
......@@ -154,6 +154,7 @@ class ServiceWorkerGlobalScopeProxy final
void DidCreateWorkerGlobalScope(WorkerOrWorkletGlobalScope*) override;
void DidInitializeWorkerContext() override;
void DidLoadInstalledScript() override;
void DidFailToLoadInstalledScript() override;
void WillEvaluateClassicScript(size_t script_size,
size_t cached_metadata_size) override;
void WillEvaluateImportedClassicScript(size_t script_size,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment