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

Side by Side Diff: third_party/WebKit/Source/modules/cachestorage/Cache.cpp

Issue 2480293004: Mandate unique_ptr for base::IDMap in IDMapOwnPointer mode. (Closed)
Patch Set: Make changes requested by danakj, fix a few more headers Created 4 years 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 "modules/cachestorage/Cache.h" 5 #include "modules/cachestorage/Cache.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
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"
11 #include "bindings/core/v8/V8Binding.h" 11 #include "bindings/core/v8/V8Binding.h"
12 #include "bindings/core/v8/V8ThrowException.h" 12 #include "bindings/core/v8/V8ThrowException.h"
13 #include "bindings/modules/v8/V8Response.h" 13 #include "bindings/modules/v8/V8Response.h"
14 #include "core/dom/DOMException.h" 14 #include "core/dom/DOMException.h"
15 #include "core/inspector/ConsoleMessage.h" 15 #include "core/inspector/ConsoleMessage.h"
16 #include "modules/cachestorage/CacheStorageError.h" 16 #include "modules/cachestorage/CacheStorageError.h"
17 #include "modules/fetch/BodyStreamBuffer.h" 17 #include "modules/fetch/BodyStreamBuffer.h"
18 #include "modules/fetch/FetchDataLoader.h" 18 #include "modules/fetch/FetchDataLoader.h"
19 #include "modules/fetch/GlobalFetch.h" 19 #include "modules/fetch/GlobalFetch.h"
20 #include "modules/fetch/Request.h" 20 #include "modules/fetch/Request.h"
21 #include "modules/fetch/Response.h" 21 #include "modules/fetch/Response.h"
22 #include "platform/HTTPNames.h" 22 #include "platform/HTTPNames.h"
23 #include "platform/Histogram.h" 23 #include "platform/Histogram.h"
24 #include "public/platform/modules/serviceworker/WebServiceWorkerCache.h" 24 #include "public/platform/modules/serviceworker/WebServiceWorkerCache.h"
25 #include <memory> 25 #include <memory>
26 #include <utility>
26 27
27 namespace blink { 28 namespace blink {
28 29
29 namespace { 30 namespace {
30 31
31 // FIXME: Consider using CallbackPromiseAdapter. 32 // FIXME: Consider using CallbackPromiseAdapter.
32 class CacheMatchCallbacks : public WebServiceWorkerCache::CacheMatchCallbacks { 33 class CacheMatchCallbacks : public WebServiceWorkerCache::CacheMatchCallbacks {
33 WTF_MAKE_NONCOPYABLE(CacheMatchCallbacks); 34 WTF_MAKE_NONCOPYABLE(CacheMatchCallbacks);
34 35
35 public: 36 public:
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 ASSERT(index < m_batchOperations.size()); 299 ASSERT(index < m_batchOperations.size());
299 if (m_completed) 300 if (m_completed)
300 return; 301 return;
301 if (!m_resolver->getExecutionContext() || 302 if (!m_resolver->getExecutionContext() ||
302 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) 303 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
303 return; 304 return;
304 m_batchOperations[index] = batchOperation; 305 m_batchOperations[index] = batchOperation;
305 if (--m_numberOfRemainingOperations != 0) 306 if (--m_numberOfRemainingOperations != 0)
306 return; 307 return;
307 m_cache->webCache()->dispatchBatch( 308 m_cache->webCache()->dispatchBatch(
308 new CallbackPromiseAdapter<void, CacheStorageError>(m_resolver), 309 WTF::makeUnique<CallbackPromiseAdapter<void, CacheStorageError>>(
310 m_resolver),
309 m_batchOperations); 311 m_batchOperations);
310 } 312 }
311 313
312 void onError(const String& errorMessage) { 314 void onError(const String& errorMessage) {
313 if (m_completed) 315 if (m_completed)
314 return; 316 return;
315 m_completed = true; 317 m_completed = true;
316 if (!m_resolver->getExecutionContext() || 318 if (!m_resolver->getExecutionContext() ||
317 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) 319 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
318 return; 320 return;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 const CacheQueryOptions& options) { 526 const CacheQueryOptions& options) {
525 WebServiceWorkerRequest webRequest; 527 WebServiceWorkerRequest webRequest;
526 request->populateWebServiceWorkerRequest(webRequest); 528 request->populateWebServiceWorkerRequest(webRequest);
527 529
528 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 530 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
529 const ScriptPromise promise = resolver->promise(); 531 const ScriptPromise promise = resolver->promise();
530 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { 532 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) {
531 resolver->resolve(); 533 resolver->resolve();
532 return promise; 534 return promise;
533 } 535 }
534 m_webCache->dispatchMatch(new CacheMatchCallbacks(resolver), webRequest, 536 m_webCache->dispatchMatch(WTF::makeUnique<CacheMatchCallbacks>(resolver),
535 toWebQueryParams(options)); 537 webRequest, toWebQueryParams(options));
536 return promise; 538 return promise;
537 } 539 }
538 540
539 ScriptPromise Cache::matchAllImpl(ScriptState* scriptState) { 541 ScriptPromise Cache::matchAllImpl(ScriptState* scriptState) {
540 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 542 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
541 const ScriptPromise promise = resolver->promise(); 543 const ScriptPromise promise = resolver->promise();
542 m_webCache->dispatchMatchAll(new CacheWithResponsesCallbacks(resolver), 544 m_webCache->dispatchMatchAll(
543 WebServiceWorkerRequest(), 545 WTF::makeUnique<CacheWithResponsesCallbacks>(resolver),
544 WebServiceWorkerCache::QueryParams()); 546 WebServiceWorkerRequest(), WebServiceWorkerCache::QueryParams());
545 return promise; 547 return promise;
546 } 548 }
547 549
548 ScriptPromise Cache::matchAllImpl(ScriptState* scriptState, 550 ScriptPromise Cache::matchAllImpl(ScriptState* scriptState,
549 const Request* request, 551 const Request* request,
550 const CacheQueryOptions& options) { 552 const CacheQueryOptions& options) {
551 WebServiceWorkerRequest webRequest; 553 WebServiceWorkerRequest webRequest;
552 request->populateWebServiceWorkerRequest(webRequest); 554 request->populateWebServiceWorkerRequest(webRequest);
553 555
554 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 556 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
555 const ScriptPromise promise = resolver->promise(); 557 const ScriptPromise promise = resolver->promise();
556 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { 558 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) {
557 resolver->resolve(HeapVector<Member<Response>>()); 559 resolver->resolve(HeapVector<Member<Response>>());
558 return promise; 560 return promise;
559 } 561 }
560 m_webCache->dispatchMatchAll(new CacheWithResponsesCallbacks(resolver), 562 m_webCache->dispatchMatchAll(
561 webRequest, toWebQueryParams(options)); 563 WTF::makeUnique<CacheWithResponsesCallbacks>(resolver), webRequest,
564 toWebQueryParams(options));
562 return promise; 565 return promise;
563 } 566 }
564 567
565 ScriptPromise Cache::addAllImpl(ScriptState* scriptState, 568 ScriptPromise Cache::addAllImpl(ScriptState* scriptState,
566 const HeapVector<Member<Request>>& requests, 569 const HeapVector<Member<Request>>& requests,
567 ExceptionState& exceptionState) { 570 ExceptionState& exceptionState) {
568 if (requests.isEmpty()) 571 if (requests.isEmpty())
569 return ScriptPromise::castUndefined(scriptState); 572 return ScriptPromise::castUndefined(scriptState);
570 573
571 HeapVector<RequestInfo> requestInfos; 574 HeapVector<RequestInfo> requestInfos;
(...skipping 29 matching lines...) Expand all
601 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypeDelete; 604 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypeDelete;
602 request->populateWebServiceWorkerRequest(batchOperations[0].request); 605 request->populateWebServiceWorkerRequest(batchOperations[0].request);
603 batchOperations[0].matchParams = toWebQueryParams(options); 606 batchOperations[0].matchParams = toWebQueryParams(options);
604 607
605 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 608 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
606 const ScriptPromise promise = resolver->promise(); 609 const ScriptPromise promise = resolver->promise();
607 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { 610 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) {
608 resolver->resolve(false); 611 resolver->resolve(false);
609 return promise; 612 return promise;
610 } 613 }
611 m_webCache->dispatchBatch(new CacheDeleteCallback(resolver), batchOperations); 614 m_webCache->dispatchBatch(WTF::makeUnique<CacheDeleteCallback>(resolver),
615 batchOperations);
612 return promise; 616 return promise;
613 } 617 }
614 618
615 ScriptPromise Cache::putImpl(ScriptState* scriptState, 619 ScriptPromise Cache::putImpl(ScriptState* scriptState,
616 const HeapVector<Member<Request>>& requests, 620 const HeapVector<Member<Request>>& requests,
617 const HeapVector<Member<Response>>& responses) { 621 const HeapVector<Member<Response>>& responses) {
618 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 622 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
619 const ScriptPromise promise = resolver->promise(); 623 const ScriptPromise promise = resolver->promise();
620 BarrierCallbackForPut* barrierCallback = 624 BarrierCallbackForPut* barrierCallback =
621 new BarrierCallbackForPut(requests.size(), this, resolver); 625 new BarrierCallbackForPut(requests.size(), this, resolver);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 responses[i]->populateWebServiceWorkerResponse(batchOperation.response); 670 responses[i]->populateWebServiceWorkerResponse(batchOperation.response);
667 barrierCallback->onSuccess(i, batchOperation); 671 barrierCallback->onSuccess(i, batchOperation);
668 } 672 }
669 673
670 return promise; 674 return promise;
671 } 675 }
672 676
673 ScriptPromise Cache::keysImpl(ScriptState* scriptState) { 677 ScriptPromise Cache::keysImpl(ScriptState* scriptState) {
674 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 678 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
675 const ScriptPromise promise = resolver->promise(); 679 const ScriptPromise promise = resolver->promise();
676 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 680 m_webCache->dispatchKeys(
677 WebServiceWorkerRequest(), 681 WTF::makeUnique<CacheWithRequestsCallbacks>(resolver),
678 WebServiceWorkerCache::QueryParams()); 682 WebServiceWorkerRequest(), WebServiceWorkerCache::QueryParams());
679 return promise; 683 return promise;
680 } 684 }
681 685
682 ScriptPromise Cache::keysImpl(ScriptState* scriptState, 686 ScriptPromise Cache::keysImpl(ScriptState* scriptState,
683 const Request* request, 687 const Request* request,
684 const CacheQueryOptions& options) { 688 const CacheQueryOptions& options) {
685 WebServiceWorkerRequest webRequest; 689 WebServiceWorkerRequest webRequest;
686 request->populateWebServiceWorkerRequest(webRequest); 690 request->populateWebServiceWorkerRequest(webRequest);
687 691
688 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 692 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
689 const ScriptPromise promise = resolver->promise(); 693 const ScriptPromise promise = resolver->promise();
690 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { 694 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) {
691 resolver->resolve(HeapVector<Member<Request>>()); 695 resolver->resolve(HeapVector<Member<Request>>());
692 return promise; 696 return promise;
693 } 697 }
694 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), webRequest, 698 m_webCache->dispatchKeys(
695 toWebQueryParams(options)); 699 WTF::makeUnique<CacheWithRequestsCallbacks>(resolver), webRequest,
700 toWebQueryParams(options));
696 return promise; 701 return promise;
697 } 702 }
698 703
699 WebServiceWorkerCache* Cache::webCache() const { 704 WebServiceWorkerCache* Cache::webCache() const {
700 return m_webCache.get(); 705 return m_webCache.get();
701 } 706 }
702 707
703 } // namespace blink 708 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698