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

Side by Side Diff: Source/modules/serviceworkers/polyfills/cachePolyfill.js

Issue 311343003: ServiceWorker polyfill Fetch implementation. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix memory error Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A simple, incomplete implementation of the Cache API, intended to facilitate 5 // A simple, incomplete implementation of the Cache API, intended to facilitate
6 // end to end serviceworker testing. 6 // end to end serviceworker testing.
7 7
8 // See https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.htm l#cache 8 // See https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.htm l#cache
9 9
10 // FIXME: Support AbstractResponse/OpaqueResponse correctly. 10 // FIXME: Support AbstractResponse/OpaqueResponse correctly.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 that.entriesByMethod[request.method] = {}; 57 that.entriesByMethod[request.method] = {};
58 } 58 }
59 59
60 var entriesByUrl = that.entriesByMethod[request.method]; 60 var entriesByUrl = that.entriesByMethod[request.method];
61 entriesByUrl[request.url] = response; 61 entriesByUrl[request.url] = response;
62 62
63 resolve(); 63 resolve();
64 }); 64 });
65 }; 65 };
66 66
67 // FIXME: Implement this. 67 Cache.prototype.add = function(request) {
68 Cache.prototype.add = Promise.reject.bind(Promise, 'Cache.prototype.add() no t implemented.'); 68 var that = this;
69 request = _castToRequest(request);
70 return new Promise(function (resolve, reject) {
71 fetch(request).then(
72 function(response) {
73 that.put(request, response).then(resolve);
74 },
75 reject);
76 });
77 };
69 78
70 // FIXME: Add QueryParams argument. 79 // FIXME: Add QueryParams argument.
71 Cache.prototype.delete = function(request) { 80 Cache.prototype.delete = function(request) {
72 request = _castToRequest(request); 81 request = _castToRequest(request);
73 82
74 var that = this; 83 var that = this;
75 return new Promise(function(resolve, reject) { 84 return new Promise(function(resolve, reject) {
76 if (that.entriesByMethod.hasOwnProperty(request.method)) { 85 if (that.entriesByMethod.hasOwnProperty(request.method)) {
77 var entriesByUrl = that.entriesByMethod[request.method]; 86 var entriesByUrl = that.entriesByMethod[request.method];
78 delete entriesByUrl[request.url]; 87 delete entriesByUrl[request.url];
(...skipping 24 matching lines...) Expand all
103 var entry = entriesByUrl[request.url]; 112 var entry = entriesByUrl[request.url];
104 resolve(entry); 113 resolve(entry);
105 }); 114 });
106 }; 115 };
107 116
108 // FIXME: Implement this. 117 // FIXME: Implement this.
109 Cache.prototype.matchAll = Promise.reject.bind(Promise, 'Cache.prototype.mat chAll not implemented.'); 118 Cache.prototype.matchAll = Promise.reject.bind(Promise, 'Cache.prototype.mat chAll not implemented.');
110 119
111 global.Cache = global.Cache || Cache; 120 global.Cache = global.Cache || Cache;
112 }(self)); // window or worker global scope. 121 }(self)); // window or worker global scope.
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp ('k') | Source/modules/serviceworkers/polyfills/fetchPolyfill.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698