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

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

Issue 1018243002: [Fetch] Support various operations after reading data partially. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@async-read
Patch Set: Created 5 years, 9 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
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/ExceptionState.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Response body is already used")); 365 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Response body is already used"));
366 366
367 if (request->hasBody()) 367 if (request->hasBody())
368 request->setBodyUsed(); 368 request->setBodyUsed();
369 if (response->hasBody()) 369 if (response->hasBody())
370 response->setBodyUsed(); 370 response->setBodyUsed();
371 371
372 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 372 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
373 const ScriptPromise promise = resolver->promise(); 373 const ScriptPromise promise = resolver->promise();
374 if (BodyStreamBuffer* buffer = response->internalBuffer()) { 374 if (BodyStreamBuffer* buffer = response->internalBuffer()) {
375 if (buffer == response->buffer() && response->streamAccessed()) { 375 if (buffer == response->buffer() && response->streamAccessed())
376 bool dataLost = false; 376 buffer = response->createDrainingStream();
377 buffer = response->createDrainingStream(&dataLost);
378 if (dataLost) {
379 resolver->reject(DOMException::create(NotSupportedError, "Storin g the Response which .body is partially read is not supported."));
380 return promise;
381 }
382 }
383 // If the response body type is stream, read the all data and create the 377 // If the response body type is stream, read the all data and create the
384 // blob handle and dispatch the put batch asynchronously. 378 // blob handle and dispatch the put batch asynchronously.
385 buffer->readAllAndCreateBlobHandle(response->internalContentTypeForBuffe r(), new AsyncPutBatch(resolver, this, request, response)); 379 buffer->readAllAndCreateBlobHandle(response->internalContentTypeForBuffe r(), new AsyncPutBatch(resolver, this, request, response));
386 return promise; 380 return promise;
387 } 381 }
388 WebVector<WebServiceWorkerCache::BatchOperation> batchOperations(size_t(1)); 382 WebVector<WebServiceWorkerCache::BatchOperation> batchOperations(size_t(1));
389 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypePut; 383 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypePut;
390 request->populateWebServiceWorkerRequest(batchOperations[0].request); 384 request->populateWebServiceWorkerRequest(batchOperations[0].request);
391 response->populateWebServiceWorkerResponse(batchOperations[0].response); 385 response->populateWebServiceWorkerResponse(batchOperations[0].response);
392 386
(...skipping 19 matching lines...) Expand all
412 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ ueryParams(options)); 406 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ ueryParams(options));
413 return promise; 407 return promise;
414 } 408 }
415 409
416 WebServiceWorkerCache* Cache::webCache() const 410 WebServiceWorkerCache* Cache::webCache() const
417 { 411 {
418 return m_webCache.get(); 412 return m_webCache.get();
419 } 413 }
420 414
421 } // namespace blink 415 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/fetch/Response.cpp ('k') | Source/modules/serviceworkers/RespondWithObserver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698