Commit 8a5ede2a authored by shimazu's avatar shimazu Committed by Commit bot

ServiceWorker: Bypass SW when the script doesn't have fetch handler

When the script doesn't have a fetch handler, a request
will immediately go to the network after passed to SW in current implementation.
However, if SW is down, this procedure will wait for waking SW up though SW
doesn't have fetch handler. This patch enables the request to directly go to
network bypassing SW in this situation.

BUG=605844
TEST=/out/Release/content_unittest --gtest_filter="ServiceWorkerControlleeRequestHandlerTest.FallbackWithNoFetchHandler"

Review-Url: https://codereview.chromium.org/2019613003
Cr-Commit-Position: refs/heads/master@{#396787}
parent 5d967288
......@@ -26,6 +26,23 @@
namespace content {
namespace {
bool MaybeForwardToServiceWorker(ServiceWorkerURLRequestJob* job,
const ServiceWorkerVersion* version) {
DCHECK(job);
DCHECK(version);
if (version->has_fetch_handler()) {
job->ForwardToServiceWorker();
return true;
}
job->FallbackToNetwork();
return false;
}
} // namespace
ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler(
base::WeakPtr<ServiceWorkerContextCore> context,
base::WeakPtr<ServiceWorkerProviderHost> provider_host,
......@@ -251,15 +268,15 @@ ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource(
}
ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_);
bool is_forwarded =
MaybeForwardToServiceWorker(job_.get(), active_version.get());
job_->ForwardToServiceWorker();
TRACE_EVENT_ASYNC_END2(
"ServiceWorker",
"ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
job_.get(),
"Status", status,
"Info",
"Forwarded to the ServiceWorker");
job_.get(), "Status", status, "Info",
(is_forwarded) ? "Forwarded to the ServiceWorker"
: "Skipped the ServiceWorker which has no fetch handler");
}
void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged(
......@@ -282,7 +299,8 @@ void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged(
provider_host_->AssociateRegistration(registration,
false /* notify_controllerchange */);
job_->ForwardToServiceWorker();
MaybeForwardToServiceWorker(job_.get(), version);
}
void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration(
......@@ -352,7 +370,7 @@ void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() {
DCHECK(job_.get());
DCHECK(context_);
DCHECK(provider_host_->active_version());
job_->ForwardToServiceWorker();
MaybeForwardToServiceWorker(job_.get(), provider_host_->active_version());
}
void ServiceWorkerControlleeRequestHandler::OnPrepareToRestart() {
......
......@@ -330,6 +330,8 @@ class CONTENT_EXPORT ServiceWorkerVersion
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
ActivateWaitingVersion);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
FallbackWithNoFetchHandler);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, IdleTimeout);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, SetDevToolsAttached);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_FreshWorker);
......
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