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

Unified Diff: content/test/data/service_worker/fetch_event_response_via_cache.js

Issue 1750333002: Reland of Pipe response_time from FetchManager to CacheStorage and ServiceWorkerURLRequestJob. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/test/data/service_worker/fetch_event_response_via_cache.js
diff --git a/content/test/data/service_worker/fetch_event_response_via_cache.js b/content/test/data/service_worker/fetch_event_response_via_cache.js
new file mode 100644
index 0000000000000000000000000000000000000000..4fd03db73db61b856b703dddd006eb3ab70b9095
--- /dev/null
+++ b/content/test/data/service_worker/fetch_event_response_via_cache.js
@@ -0,0 +1,28 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+this.onfetch = function(event) {
+ var CACHE_NAME = 'cache_name';
+ var cache = undefined;
+ var url = event.request.url;
+ event.respondWith(
+ caches.open(CACHE_NAME)
+ .then(function(c) {
+ cache = c;
+ return cache.match(url);
+ })
+ .then(function(response) {
+ if (response)
+ return response;
+ var cloned_response = undefined;
+ return fetch(url)
+ .then(function(res) {
+ cloned_response = res.clone();
+ return cache.put(url, res);
+ })
+ .then(function() {
+ return cloned_response;
+ });
+ }));
+ };

Powered by Google App Engine
This is Rietveld 408576698