Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Unified Diff: content/browser/service_worker/link_header_support.cc

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: change useCache to updateViaCache Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/link_header_support.cc
diff --git a/content/browser/service_worker/link_header_support.cc b/content/browser/service_worker/link_header_support.cc
index 32ce5777969044119357c0eb381863847c7686c7..d8f11bceb63186f31d22fce170617b1fd2fe0d64 100644
--- a/content/browser/service_worker/link_header_support.cc
+++ b/content/browser/service_worker/link_header_support.cc
@@ -33,6 +33,22 @@ void RegisterServiceWorkerFinished(int64_t trace_id, bool result) {
trace_id, "Success", result);
}
+blink::WebServiceWorkerUpdateViaCache ParseUpdateViaCache(
nhiroki 2017/06/21 15:04:58 Can you add a link to https://html.spec.whatwg.org
yuryu 2017/07/20 10:15:12 Done.
+ const std::unordered_map<std::string, base::Optional<std::string>>&
+ params) {
+ auto cache_param = params.find("updateviacache");
+ if (cache_param == params.end())
+ return blink::WebServiceWorkerUpdateViaCache::kImports;
+ const std::string& cache = cache_param->second.value_or("");
+ if (base::EqualsCaseInsensitiveASCII(cache, "imports"))
+ return blink::WebServiceWorkerUpdateViaCache::kImports;
+ if (base::EqualsCaseInsensitiveASCII(cache, "never"))
nhiroki 2017/06/21 15:04:58 never -> none? https://w3c.github.io/ServiceWorker
yuryu 2017/07/20 10:15:12 Done.
+ return blink::WebServiceWorkerUpdateViaCache::kNone;
+ if (base::EqualsCaseInsensitiveASCII(cache, "all"))
+ return blink::WebServiceWorkerUpdateViaCache::kAll;
+ return blink::WebServiceWorkerUpdateViaCache::kUnknown;
+}
+
void HandleServiceWorkerLink(
net::URLRequest* request,
const std::string& url,
@@ -95,6 +111,11 @@ void HandleServiceWorkerLink(
GURL scope_url = scope_param == params.end()
? script_url.Resolve("./")
: context_url.Resolve(scope_param->second.value_or(""));
+ blink::WebServiceWorkerUpdateViaCache update_via_cache =
+ ParseUpdateViaCache(params);
+ if (update_via_cache == blink::WebServiceWorkerUpdateViaCache::kUnknown) {
+ return;
+ }
if (!context_url.is_valid() || !script_url.is_valid() ||
!scope_url.is_valid())
@@ -119,7 +140,7 @@ void HandleServiceWorkerLink(
"ServiceWorker", "LinkHeaderResourceThrottle::HandleServiceWorkerLink",
++trace_id, "Pattern", scope_url.spec(), "Script URL", script_url.spec());
service_worker_context->RegisterServiceWorker(
- scope_url, script_url,
+ scope_url, script_url, update_via_cache,
base::Bind(&RegisterServiceWorkerFinished, trace_id));
}

Powered by Google App Engine
This is Rietveld 408576698