Commit 39970a79 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Enable ServiceWorkerRegistration#updateViaCache by default.

This ships updateViaCache which controls whether the browser cache is
used for service worker update checks. Importantly, this changes the
default behavior, since the default value of updateViaCache is 'imports',
which skips the browser cache for the main service worker script and
uses it only for import scripts. However, actually checking import
script contents for updates is not yet implemented, so effectively the
default is 'none': https://crbug.com/648295.

Thanks to Emma Haruka Iwao (yuryu@) for doing the bulk of the
implementation work.

Intent to ship: https://groups.google.com/a/chromium.org/d/msg/blink-dev/RwjXGTAbuuA/7Q3NPlJ4BAAJ

Bug: 675540
Change-Id: Ifdbaaa76b028e07ac26b9db28d9c59c7b8bd055f
Reviewed-on: https://chromium-review.googlesource.com/1056756
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558639}
parent f534543c
......@@ -137,11 +137,6 @@ class ServiceWorkerContextRequestHandlerTest : public testing::Test {
void TestBypassCache(const GURL& url,
ResourceType resource_type,
bool expect_bypass) {
// TODO(https://crbug.com/675540): Remove the following command line switch
// when updateViaCache is shipped to stable.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
std::unique_ptr<net::URLRequest> request(CreateRequest(url));
std::unique_ptr<ServiceWorkerContextRequestHandler> handler(
CreateHandler(resource_type));
......@@ -190,34 +185,6 @@ TEST_F(ServiceWorkerContextRequestHandlerTest, UpdateBefore24Hours) {
TestBypassCacheForImportedScript(false);
}
// TODO(https://crbug.com/675540): Remove the
// UpdateBefore24HoursWithoutUpdateViaCache test when the update_via_cache flag
// is shipped to stable as this is to test the legacy behavior.
TEST_F(ServiceWorkerContextRequestHandlerTest,
UpdateBefore24HoursWithoutUpdateViaCache) {
registration_->set_last_update_check(base::Time::Now());
version_->SetStatus(ServiceWorkerVersion::NEW);
// Conduct a resource fetch for the main script.
base::HistogramTester histograms;
std::unique_ptr<net::URLRequest> request(CreateRequest(script_url_));
std::unique_ptr<ServiceWorkerContextRequestHandler> handler(
CreateHandler(RESOURCE_TYPE_SERVICE_WORKER));
std::unique_ptr<net::URLRequestJob> job(
handler->MaybeCreateJob(request.get(), nullptr, nullptr));
ASSERT_TRUE(job.get());
ServiceWorkerWriteToCacheJob* sw_job =
static_cast<ServiceWorkerWriteToCacheJob*>(job.get());
histograms.ExpectUniqueSample(
"ServiceWorker.ContextRequestHandlerStatus.NewWorker.MainScript",
static_cast<int>(
ServiceWorkerContextRequestHandler::CreateJobStatus::WRITE_JOB),
1);
// Verify the net request is not initialized to bypass the browser cache.
EXPECT_FALSE(sw_job->net_request_->load_flags() & net::LOAD_BYPASS_CACHE);
}
TEST_F(ServiceWorkerContextRequestHandlerTest,
UpdateBefore24HoursWithUpdateViaCacheAll) {
registration_->SetUpdateViaCache(
......
......@@ -1466,15 +1466,10 @@ void ServiceWorkerDatabase::WriteRegistrationDataInBatch(
for (uint32_t feature : registration.used_features)
data.add_used_features(feature);
// TODO(https://crbug.com/675540): Remove the the command line check and
// always set to data when shipping the updateViaCache flag to stable.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalWebPlatformFeatures)) {
data.set_update_via_cache(
static_cast<
ServiceWorkerRegistrationData_ServiceWorkerUpdateViaCacheType>(
registration.update_via_cache));
}
data.set_update_via_cache(
static_cast<
ServiceWorkerRegistrationData_ServiceWorkerUpdateViaCacheType>(
registration.update_via_cache));
std::string value;
bool success = data.SerializeToString(&value);
......
......@@ -62,11 +62,6 @@ class CONTENT_EXPORT ServiceWorkerWriteToCacheJob
private:
friend class ServiceWorkerContextRequestHandlerTest;
// TODO(https://crbug.com/675540): Remove the following
// FRIEND_TEST_ALL_PREFIXES directive when the update_via_cache flag is
// shipped to stable.
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
UpdateBefore24HoursWithoutUpdateViaCache);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
ServiceWorkerDataRequestAnnotation);
......
......@@ -215,12 +215,6 @@ bool ServiceWorkerUtils::ExtractSinglePartHttpRange(
bool ServiceWorkerUtils::ShouldBypassCacheDueToUpdateViaCache(
bool is_main_script,
blink::mojom::ServiceWorkerUpdateViaCache cache_mode) {
// TODO(https://crbug.com/675540): Remove the command line check and always
// respect cache_mode when shipping updateViaCache flag to stable.
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalWebPlatformFeatures)) {
return false;
}
switch (cache_mode) {
case blink::mojom::ServiceWorkerUpdateViaCache::kImports:
return is_main_script;
......
......@@ -821,6 +821,7 @@ interface ServiceWorkerRegistration : EventTarget
getter pushManager
getter scope
getter sync
getter updateViaCache
getter waiting
method constructor
method getNotifications
......
......@@ -788,6 +788,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter pushManager
[Worker] getter scope
[Worker] getter sync
[Worker] getter updateViaCache
[Worker] getter waiting
[Worker] method constructor
[Worker] method getNotifications
......
......@@ -6067,6 +6067,7 @@ interface ServiceWorkerRegistration : EventTarget
getter pushManager
getter scope
getter sync
getter updateViaCache
getter waiting
method constructor
method getNotifications
......
......@@ -783,6 +783,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter pushManager
[Worker] getter scope
[Worker] getter sync
[Worker] getter updateViaCache
[Worker] getter waiting
[Worker] method constructor
[Worker] method getNotifications
......
......@@ -1147,7 +1147,7 @@
},
{
name: "ServiceWorkerUpdateViaCache",
status: "experimental",
status: "stable",
},
{
name: "SetRootScroller",
......
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