Commit 200baa21 authored by tzik's avatar tzik Committed by Commit bot

Use ParentFrameTaskRunners in WorkerLoaderProxyProvider::postTaskToLoader impls

Implementations of WorkerLoaderProxyProvider::postTaskToLoader have used
ExecutionContext::postTask to post tasks to the main thread. However,
the posted tasks are unexpectedly throttled, and that delays the startup
time of service workers.
This CL replaces ExecutionContext::postTask there with ParentFrameTaskRunners
and WebTaskRunner::postTask, so that the posted task is routed to suitable
task runners.

BUG=667310, 671084

Review-Url: https://codereview.chromium.org/2574703002
Cr-Commit-Position: refs/heads/master@{#438146}
parent a1b7b922
......@@ -48,6 +48,11 @@ class CORE_EXPORT ExecutionContextTask {
ExecutionContextTask() {}
virtual ~ExecutionContextTask() {}
virtual void performTask(ExecutionContext*) = 0;
void performTaskIfContextIsValid(ExecutionContext* context) {
if (context)
performTask(context);
}
};
namespace internal {
......
......@@ -240,6 +240,8 @@ class WorkerThreadableLoaderTestHelper : public ThreadableLoaderTestHelper,
void onSetUp() override {
m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>();
m_securityOrigin = document().getSecurityOrigin();
m_parentFrameTaskRunners =
ParentFrameTaskRunners::create(&m_dummyPageHolder->frame());
m_workerThread = WTF::wrapUnique(new WorkerThreadForTest(
this, *m_mockWorkerReportingProxy, m_threadHeapMode));
......@@ -329,7 +331,12 @@ class WorkerThreadableLoaderTestHelper : public ThreadableLoaderTestHelper,
std::unique_ptr<ExecutionContextTask> task) override {
DCHECK(m_workerThread);
DCHECK(m_workerThread->isCurrentThread());
document().postTask(location, std::move(task));
m_parentFrameTaskRunners->get(TaskType::Networking)
->postTask(
BLINK_FROM_HERE,
crossThreadBind(&ExecutionContextTask::performTaskIfContextIsValid,
WTF::passed(std::move(task)),
wrapCrossThreadWeakPersistent(&document())));
}
void postTaskToWorkerGlobalScope(
......@@ -344,6 +351,7 @@ class WorkerThreadableLoaderTestHelper : public ThreadableLoaderTestHelper,
std::unique_ptr<WorkerThreadForTest> m_workerThread;
std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners;
Checkpoint m_checkpoint;
// |m_loader| must be touched only from the worker thread only.
CrossThreadPersistent<ThreadableLoader> m_loader;
......
......@@ -74,9 +74,12 @@ void ThreadedMessagingProxyBase::postTaskToLoader(
const WebTraceLocation& location,
std::unique_ptr<ExecutionContextTask> task) {
DCHECK(getExecutionContext()->isDocument());
// TODO(hiroshige,yuryu): Make this not use ExecutionContextTask and use
// m_parentFrameTaskRunners->get(TaskType::Networking) instead.
getExecutionContext()->postTask(location, std::move(task));
m_parentFrameTaskRunners->get(TaskType::Networking)
->postTask(BLINK_FROM_HERE,
crossThreadBind(
&ExecutionContextTask::performTaskIfContextIsValid,
WTF::passed(std::move(task)),
wrapCrossThreadWeakPersistent(getExecutionContext())));
}
void ThreadedMessagingProxyBase::countFeature(UseCounter::Feature feature) {
......
......@@ -263,10 +263,13 @@ void WebEmbeddedWorkerImpl::postMessageToPageInspector(const String& message) {
void WebEmbeddedWorkerImpl::postTaskToLoader(
const WebTraceLocation& location,
std::unique_ptr<ExecutionContextTask> task) {
// TODO(hiroshige,yuryu): Make this not use ExecutionContextTask and
// consider using m_mainThreadTaskRunners->get(TaskType::Networking)
// instead.
m_mainFrame->frame()->document()->postTask(location, std::move(task));
m_mainThreadTaskRunners->get(TaskType::Networking)
->postTask(
BLINK_FROM_HERE,
crossThreadBind(
&ExecutionContextTask::performTaskIfContextIsValid,
WTF::passed(std::move(task)),
wrapCrossThreadWeakPersistent(m_mainFrame->frame()->document())));
}
void WebEmbeddedWorkerImpl::postTaskToWorkerGlobalScope(
......
......@@ -51,6 +51,7 @@
#include "platform/CrossThreadFunctional.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/heap/Handle.h"
#include "platform/heap/Persistent.h"
#include "platform/network/ContentSecurityPolicyParsers.h"
#include "platform/network/ResourceResponse.h"
#include "platform/weborigin/KURL.h"
......@@ -306,10 +307,12 @@ void WebSharedWorkerImpl::didTerminateWorkerThreadOnMainThread() {
void WebSharedWorkerImpl::postTaskToLoader(
const WebTraceLocation& location,
std::unique_ptr<ExecutionContextTask> task) {
// TODO(hiroshige,yuryu): Make this not use ExecutionContextTask and
// consider using m_parentFrameTaskRunners->get(TaskType::Networking)
// instead.
m_mainFrame->frame()->document()->postTask(location, std::move(task));
m_parentFrameTaskRunners->get(TaskType::Networking)
->postTask(FROM_HERE,
crossThreadBind(
&ExecutionContextTask::performTaskIfContextIsValid,
WTF::passed(std::move(task)),
wrapCrossThreadWeakPersistent(m_loadingDocument.get())));
}
void WebSharedWorkerImpl::postTaskToWorkerGlobalScope(
......
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