Commit be7c3d70 authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

[Extension] Correctly dispose worker's ScriptContext.

While disposing a worker script context on worker thread, its corresponding
extension might have already vanished from RendererExtensionRegistry because
of ExtensionMsg_Unload IPC. This means that detecting whether the
script context had extension API bindings installed through
ExtensionAPIEnabledForServiceWorkerScript() won't return correct state.

This CL changes worker disposal to inspect ServiceWorkerData instead,
which should be non null if extension bindings were installed in the
worker script context.

Bug: 1005541
Test: Update{un,}packedExtension flakiness reduces locally, see crbug.com/984522
Change-Id: Ib33148a81ebcc720cf26b754c26a520bb4e22b92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815226
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarDavid Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699964}
parent f80d1e25
......@@ -558,9 +558,10 @@ void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread(
int64_t service_worker_version_id,
const GURL& service_worker_scope,
const GURL& script_url) {
if (!ExtensionsRendererClient::Get()
->ExtensionAPIEnabledForServiceWorkerScript(service_worker_scope,
script_url)) {
// Note that using ExtensionAPIEnabledForServiceWorkerScript() won't work here
// as RendererExtensionRegistry might have already unloaded this extension.
// Use the existence of ServiceWorkerData as the source of truth instead.
if (!WorkerThreadDispatcher::GetServiceWorkerData()) {
// If extension APIs in service workers aren't enabled, we just need to
// remove the context.
g_worker_script_context_set.Get().Remove(v8_context, script_url);
......
......@@ -35,6 +35,12 @@ base::LazyInstance<WorkerThreadDispatcher>::DestructorAtExit
base::LazyInstance<base::ThreadLocalPointer<extensions::ServiceWorkerData>>::
DestructorAtExit g_data_tls = LAZY_INSTANCE_INITIALIZER;
ServiceWorkerData* GetServiceWorkerDataChecked() {
ServiceWorkerData* data = WorkerThreadDispatcher::GetServiceWorkerData();
DCHECK(data);
return data;
}
} // namespace
WorkerThreadDispatcher::WorkerThreadDispatcher() {}
......@@ -54,24 +60,22 @@ void WorkerThreadDispatcher::Init(content::RenderThread* render_thread) {
// static
NativeExtensionBindingsSystem* WorkerThreadDispatcher::GetBindingsSystem() {
return GetServiceWorkerData()->bindings_system();
return GetServiceWorkerDataChecked()->bindings_system();
}
// static
V8SchemaRegistry* WorkerThreadDispatcher::GetV8SchemaRegistry() {
return GetServiceWorkerData()->v8_schema_registry();
return GetServiceWorkerDataChecked()->v8_schema_registry();
}
// static
ScriptContext* WorkerThreadDispatcher::GetScriptContext() {
return GetServiceWorkerData()->context();
return GetServiceWorkerDataChecked()->context();
}
// static
ServiceWorkerData* WorkerThreadDispatcher::GetServiceWorkerData() {
ServiceWorkerData* data = g_data_tls.Pointer()->Get();
DCHECK(data);
return data;
return g_data_tls.Pointer()->Get();
}
// static
......
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