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

Side by Side Diff: Source/modules/serviceworkers/Cache.cpp

Issue 694083002: Service Worker Cache: Simplify exception/rejection processing (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add exception state to fixture Created 6 years, 1 month 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
« no previous file with comments | « Source/modules/serviceworkers/Cache.h ('k') | Source/modules/serviceworkers/Cache.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "config.h" 5 #include "config.h"
6 #include "modules/serviceworkers/Cache.h" 6 #include "modules/serviceworkers/Cache.h"
7 7
8 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8ThrowException.h" 11 #include "bindings/core/v8/V8ThrowException.h"
11 #include "core/dom/DOMException.h" 12 #include "core/dom/DOMException.h"
12 #include "modules/serviceworkers/Request.h" 13 #include "modules/serviceworkers/Request.h"
13 #include "modules/serviceworkers/Response.h" 14 #include "modules/serviceworkers/Response.h"
14 #include "public/platform/WebServiceWorkerCache.h" 15 #include "public/platform/WebServiceWorkerCache.h"
15 16
16 namespace blink { 17 namespace blink {
17 18
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 virtual void onError(WebServiceWorkerCacheError* reason) override 142 virtual void onError(WebServiceWorkerCacheError* reason) override
142 { 143 {
143 m_resolver->reject(Cache::domExceptionForCacheError(*reason)); 144 m_resolver->reject(Cache::domExceptionForCacheError(*reason));
144 m_resolver.clear(); 145 m_resolver.clear();
145 } 146 }
146 147
147 private: 148 private:
148 RefPtr<ScriptPromiseResolver> m_resolver; 149 RefPtr<ScriptPromiseResolver> m_resolver;
149 }; 150 };
150 151
151 ScriptPromise rejectForCacheError(ScriptState* scriptState, WebServiceWorkerCach eError error)
152 {
153 return ScriptPromise::rejectWithDOMException(scriptState, Cache::domExceptio nForCacheError(error));
154 }
155
156 ScriptPromise rejectAsNotImplemented(ScriptState* scriptState) 152 ScriptPromise rejectAsNotImplemented(ScriptState* scriptState)
157 { 153 {
158 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError, "Cache is not implemented")); 154 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError, "Cache is not implemented"));
159 } 155 }
160 156
161 } // namespace 157 } // namespace
162 158
163 Cache* Cache::create(WebServiceWorkerCache* webCache) 159 Cache* Cache::create(WebServiceWorkerCache* webCache)
164 { 160 {
165 return new Cache(webCache); 161 return new Cache(webCache);
166 } 162 }
167 163
168 ScriptPromise Cache::match(ScriptState* scriptState, Request* request, const Cac heQueryOptions& options) 164 ScriptPromise Cache::match(ScriptState* scriptState, Request* request, const Cac heQueryOptions& options)
169 { 165 {
170 return matchImpl(scriptState, request, options); 166 return matchImpl(scriptState, request, options);
171 } 167 }
172 168
173 ScriptPromise Cache::match(ScriptState* scriptState, const String& requestString , const CacheQueryOptions& options) 169 ScriptPromise Cache::match(ScriptState* scriptState, const String& requestString , const CacheQueryOptions& options, ExceptionState& exceptionState)
174 { 170 {
175 TrackExceptionState exceptionState;
176 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); 171 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState);
177 if (exceptionState.hadException()) { 172 if (exceptionState.hadException())
178 // FIXME: We should throw the caught error. 173 return ScriptPromise();
179 return rejectForCacheError(scriptState, WebServiceWorkerCacheErrorNotFou nd);
180 }
181 return matchImpl(scriptState, request, options); 174 return matchImpl(scriptState, request, options);
182 } 175 }
183 176
184 ScriptPromise Cache::matchAll(ScriptState* scriptState, Request* request, const CacheQueryOptions& options) 177 ScriptPromise Cache::matchAll(ScriptState* scriptState, Request* request, const CacheQueryOptions& options)
185 { 178 {
186 return matchAllImpl(scriptState, request, options); 179 return matchAllImpl(scriptState, request, options);
187 } 180 }
188 181
189 ScriptPromise Cache::matchAll(ScriptState* scriptState, const String& requestStr ing, const CacheQueryOptions& options) 182 ScriptPromise Cache::matchAll(ScriptState* scriptState, const String& requestStr ing, const CacheQueryOptions& options, ExceptionState& exceptionState)
190 { 183 {
191 TrackExceptionState exceptionState;
192 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); 184 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState);
193 if (exceptionState.hadException()) { 185 if (exceptionState.hadException())
194 // FIXME: We should throw the caught error. 186 return ScriptPromise();
195 return rejectForCacheError(scriptState, WebServiceWorkerCacheErrorNotFou nd);
196 }
197 return matchAllImpl(scriptState, request, options); 187 return matchAllImpl(scriptState, request, options);
198 } 188 }
199 189
200 ScriptPromise Cache::add(ScriptState* scriptState, Request* request) 190 ScriptPromise Cache::add(ScriptState* scriptState, Request* request)
201 { 191 {
202 return addImpl(scriptState, request); 192 return addImpl(scriptState, request);
203 } 193 }
204 194
205 ScriptPromise Cache::add(ScriptState* scriptState, const String& requestString) 195 ScriptPromise Cache::add(ScriptState* scriptState, const String& requestString, ExceptionState& exceptionState)
206 { 196 {
207 TrackExceptionState exceptionState;
208 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); 197 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState);
209 if (exceptionState.hadException()) { 198 if (exceptionState.hadException())
210 // FIXME: We should throw the caught error. 199 return ScriptPromise();
211 return rejectForCacheError(scriptState, WebServiceWorkerCacheErrorNotFou nd);
212 }
213 return addImpl(scriptState, request); 200 return addImpl(scriptState, request);
214 } 201 }
215 202
216 ScriptPromise Cache::addAll(ScriptState* scriptState, const Vector<ScriptValue>& rawRequests) 203 ScriptPromise Cache::addAll(ScriptState* scriptState, const Vector<ScriptValue>& rawRequests)
217 { 204 {
218 // FIXME: Implement this. 205 // FIXME: Implement this.
219 return rejectAsNotImplemented(scriptState); 206 return rejectAsNotImplemented(scriptState);
220 } 207 }
221 208
222 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, Request* request, const CacheQueryOptions& options) 209 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, Request* request, const CacheQueryOptions& options)
223 { 210 {
224 return deleteImpl(scriptState, request, options); 211 return deleteImpl(scriptState, request, options);
225 } 212 }
226 213
227 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, const String& requ estString, const CacheQueryOptions& options) 214 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, const String& requ estString, const CacheQueryOptions& options, ExceptionState& exceptionState)
228 { 215 {
229 TrackExceptionState exceptionState;
230 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); 216 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState);
231 if (exceptionState.hadException()) { 217 if (exceptionState.hadException())
232 // FIXME: We should throw the caught error. 218 return ScriptPromise();
233 return rejectForCacheError(scriptState, WebServiceWorkerCacheErrorNotFou nd);
234 }
235 return deleteImpl(scriptState, request, options); 219 return deleteImpl(scriptState, request, options);
236 } 220 }
237 221
238 ScriptPromise Cache::put(ScriptState* scriptState, Request* request, Response* r esponse) 222 ScriptPromise Cache::put(ScriptState* scriptState, Request* request, Response* r esponse)
239 { 223 {
240 return putImpl(scriptState, request, response); 224 return putImpl(scriptState, request, response);
241 } 225 }
242 226
243 ScriptPromise Cache::put(ScriptState* scriptState, const String& requestString, Response* response) 227 ScriptPromise Cache::put(ScriptState* scriptState, const String& requestString, Response* response, ExceptionState& exceptionState)
244 { 228 {
245 TrackExceptionState exceptionState;
246 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); 229 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState);
247 if (exceptionState.hadException()) { 230 if (exceptionState.hadException())
248 // FIXME: We should throw the caught error. 231 return ScriptPromise();
249 return rejectForCacheError(scriptState, WebServiceWorkerCacheErrorNotFou nd);
250 }
251 return putImpl(scriptState, request, response); 232 return putImpl(scriptState, request, response);
252 } 233 }
253 234
254 ScriptPromise Cache::keys(ScriptState* scriptState) 235 ScriptPromise Cache::keys(ScriptState* scriptState)
255 { 236 {
256 return keysImpl(scriptState); 237 return keysImpl(scriptState);
257 } 238 }
258 239
259 ScriptPromise Cache::keys(ScriptState* scriptState, Request* request, const Cach eQueryOptions& options) 240 ScriptPromise Cache::keys(ScriptState* scriptState, Request* request, const Cach eQueryOptions& options)
260 { 241 {
261 return keysImpl(scriptState, request, options); 242 return keysImpl(scriptState, request, options);
262 } 243 }
263 244
264 ScriptPromise Cache::keys(ScriptState* scriptState, const String& requestString, const CacheQueryOptions& options) 245 ScriptPromise Cache::keys(ScriptState* scriptState, const String& requestString, const CacheQueryOptions& options, ExceptionState& exceptionState)
265 { 246 {
266 TrackExceptionState exceptionState;
267 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); 247 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState);
268 if (exceptionState.hadException()) { 248 if (exceptionState.hadException())
269 // FIXME: We should throw the caught error. 249 return ScriptPromise();
270 return rejectForCacheError(scriptState, WebServiceWorkerCacheErrorNotFou nd);
271 }
272 return keysImpl(scriptState, request, options); 250 return keysImpl(scriptState, request, options);
273 } 251 }
274 252
275 Cache::Cache(WebServiceWorkerCache* webCache) 253 Cache::Cache(WebServiceWorkerCache* webCache)
276 : m_webCache(adoptPtr(webCache)) { } 254 : m_webCache(adoptPtr(webCache)) { }
277 255
278 ScriptPromise Cache::matchImpl(ScriptState* scriptState, const Request* request, const CacheQueryOptions& options) 256 ScriptPromise Cache::matchImpl(ScriptState* scriptState, const Request* request, const CacheQueryOptions& options)
279 { 257 {
280 WebServiceWorkerRequest webRequest; 258 WebServiceWorkerRequest webRequest;
281 request->populateWebServiceWorkerRequest(webRequest); 259 request->populateWebServiceWorkerRequest(webRequest);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 WebServiceWorkerRequest webRequest; 347 WebServiceWorkerRequest webRequest;
370 request->populateWebServiceWorkerRequest(webRequest); 348 request->populateWebServiceWorkerRequest(webRequest);
371 349
372 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 350 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
373 const ScriptPromise promise = resolver->promise(); 351 const ScriptPromise promise = resolver->promise();
374 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ ueryParams(options)); 352 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ ueryParams(options));
375 return promise; 353 return promise;
376 } 354 }
377 355
378 } // namespace blink 356 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/Cache.h ('k') | Source/modules/serviceworkers/Cache.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698