worker: Ensure to use the main thread to remove items from MemoryCache
blink::MemoryCache can be accessed only from the main thread.
Before this CL WorkerGlobalScope used ParentExecutionContextTaskRunners
to post a task to remove an item from MemoryCache. This worked because
the task runners were always bound to the main thread. However, when
we start a service worker on the IO thread, there would be no
"parent execution context" and thus no
ParentExecutionContextTaskRunners. Using task runners which are
bound to the IO thread violates the assumption MemoryCache has.
This CL changes to use the main thread task runner instead of
ParentExecutionContextTaskRunners. Thread::GetTaskRunner() is
a deprecated method but it's hard not to use because alternatives
are bound to execution contexts and there is no parent execution
context for service workers.
Bug: 692909
Change-Id: Ieb9b97bcc06398b323c2a78d8bbc0755533580a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1731832
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683479}
diff --git a/third_party/blink/renderer/core/workers/worker_global_scope.cc b/third_party/blink/renderer/core/workers/worker_global_scope.cc
index 650f293..42fdc3c 100644
--- a/third_party/blink/renderer/core/workers/worker_global_scope.cc
+++ b/third_party/blink/renderer/core/workers/worker_global_scope.cc
@@ -526,10 +526,10 @@
}
void WorkerGlobalScope::RemoveURLFromMemoryCache(const KURL& url) {
+ // MemoryCache can be accessed only from the main thread.
PostCrossThreadTask(
- *thread_->GetParentExecutionContextTaskRunners()->Get(
- TaskType::kNetworking),
- FROM_HERE, CrossThreadBindOnce(&RemoveURLFromMemoryCacheInternal, url));
+ *Thread::MainThread()->GetTaskRunner(), FROM_HERE,
+ CrossThreadBindOnce(&RemoveURLFromMemoryCacheInternal, url));
}
NOINLINE void WorkerGlobalScope::InitializeURL(const KURL& url) {