| OLD | NEW |
| 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 "modules/cachestorage/Cache.h" | 5 #include "modules/cachestorage/Cache.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 9 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 10 #include "bindings/core/v8/ExceptionState.h" | 10 #include "bindings/core/v8/ExceptionState.h" |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 promises.resize(requests.size()); | 577 promises.resize(requests.size()); |
| 578 for (size_t i = 0; i < requests.size(); ++i) { | 578 for (size_t i = 0; i < requests.size(); ++i) { |
| 579 if (!requests[i]->url().protocolIsInHTTPFamily()) | 579 if (!requests[i]->url().protocolIsInHTTPFamily()) |
| 580 return ScriptPromise::reject(scriptState, | 580 return ScriptPromise::reject(scriptState, |
| 581 V8ThrowException::createTypeError( | 581 V8ThrowException::createTypeError( |
| 582 scriptState->isolate(), | 582 scriptState->isolate(), |
| 583 "Add/AddAll does not support schemes " | 583 "Add/AddAll does not support schemes " |
| 584 "other than \"http\" or \"https\"")); | 584 "other than \"http\" or \"https\"")); |
| 585 if (requests[i]->method() != HTTPNames::GET) | 585 if (requests[i]->method() != HTTPNames::GET) |
| 586 return ScriptPromise::reject( | 586 return ScriptPromise::reject( |
| 587 scriptState, V8ThrowException::createTypeError( | 587 scriptState, |
| 588 scriptState->isolate(), | 588 V8ThrowException::createTypeError( |
| 589 "Add/AddAll only supports the GET request method.")); | 589 scriptState->isolate(), |
| 590 "Add/AddAll only supports the GET request method.")); |
| 590 requestInfos[i].setRequest(requests[i]); | 591 requestInfos[i].setRequest(requests[i]); |
| 591 | 592 |
| 592 promises[i] = m_scopedFetcher->fetch(scriptState, requestInfos[i], | 593 promises[i] = m_scopedFetcher->fetch(scriptState, requestInfos[i], |
| 593 Dictionary(), exceptionState); | 594 Dictionary(), exceptionState); |
| 594 } | 595 } |
| 595 | 596 |
| 596 return ScriptPromise::all(scriptState, promises) | 597 return ScriptPromise::all(scriptState, promises) |
| 597 .then(FetchResolvedForAdd::create(scriptState, this, requests)); | 598 .then(FetchResolvedForAdd::create(scriptState, this, requests)); |
| 598 } | 599 } |
| 599 | 600 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 barrierCallback->onError("Response body is already used"); | 652 barrierCallback->onError("Response body is already used"); |
| 652 return promise; | 653 return promise; |
| 653 } | 654 } |
| 654 | 655 |
| 655 BodyStreamBuffer* buffer = responses[i]->internalBodyBuffer(); | 656 BodyStreamBuffer* buffer = responses[i]->internalBodyBuffer(); |
| 656 if (buffer) { | 657 if (buffer) { |
| 657 // If the response has body, read the all data and create | 658 // If the response has body, read the all data and create |
| 658 // the blob handle and dispatch the put batch asynchronously. | 659 // the blob handle and dispatch the put batch asynchronously. |
| 659 FetchDataLoader* loader = FetchDataLoader::createLoaderAsBlobHandle( | 660 FetchDataLoader* loader = FetchDataLoader::createLoaderAsBlobHandle( |
| 660 responses[i]->internalMIMEType()); | 661 responses[i]->internalMIMEType()); |
| 661 buffer->startLoading( | 662 buffer->startLoading(loader, |
| 662 loader, new BlobHandleCallbackForPut(i, barrierCallback, requests[i], | 663 new BlobHandleCallbackForPut( |
| 663 responses[i])); | 664 i, barrierCallback, requests[i], responses[i])); |
| 664 continue; | 665 continue; |
| 665 } | 666 } |
| 666 | 667 |
| 667 WebServiceWorkerCache::BatchOperation batchOperation; | 668 WebServiceWorkerCache::BatchOperation batchOperation; |
| 668 batchOperation.operationType = WebServiceWorkerCache::OperationTypePut; | 669 batchOperation.operationType = WebServiceWorkerCache::OperationTypePut; |
| 669 requests[i]->populateWebServiceWorkerRequest(batchOperation.request); | 670 requests[i]->populateWebServiceWorkerRequest(batchOperation.request); |
| 670 responses[i]->populateWebServiceWorkerResponse(batchOperation.response); | 671 responses[i]->populateWebServiceWorkerResponse(batchOperation.response); |
| 671 barrierCallback->onSuccess(i, batchOperation); | 672 barrierCallback->onSuccess(i, batchOperation); |
| 672 } | 673 } |
| 673 | 674 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 699 WTF::makeUnique<CacheWithRequestsCallbacks>(resolver), webRequest, | 700 WTF::makeUnique<CacheWithRequestsCallbacks>(resolver), webRequest, |
| 700 toWebQueryParams(options)); | 701 toWebQueryParams(options)); |
| 701 return promise; | 702 return promise; |
| 702 } | 703 } |
| 703 | 704 |
| 704 WebServiceWorkerCache* Cache::webCache() const { | 705 WebServiceWorkerCache* Cache::webCache() const { |
| 705 return m_webCache.get(); | 706 return m_webCache.get(); |
| 706 } | 707 } |
| 707 | 708 |
| 708 } // namespace blink | 709 } // namespace blink |
| OLD | NEW |