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

Side by Side Diff: content/browser/cache_storage/cache_storage_cache.cc

Issue 2242883002: [CacheStorage] Use QueryCache everywhere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from PS9 Created 4 years, 4 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 "content/browser/cache_storage/cache_storage_cache.h" 5 #include "content/browser/cache_storage/cache_storage_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 : request(std::move(request)), 241 : request(std::move(request)),
242 options(options), 242 options(options),
243 callback(callback), 243 callback(callback),
244 out_requests(new Requests), 244 out_requests(new Requests),
245 out_responses(new Responses), 245 out_responses(new Responses),
246 out_blob_data_handles(new BlobDataHandles) {} 246 out_blob_data_handles(new BlobDataHandles) {}
247 247
248 std::unique_ptr<ServiceWorkerFetchRequest> request; 248 std::unique_ptr<ServiceWorkerFetchRequest> request;
249 CacheStorageCacheQueryParams options; 249 CacheStorageCacheQueryParams options;
250 QueryCacheResultsCallback callback; 250 QueryCacheResultsCallback callback;
251 QueryCacheType query_type;
251 252
252 std::unique_ptr<Requests> out_requests; 253 std::unique_ptr<Requests> out_requests;
253 std::unique_ptr<Responses> out_responses; 254 std::unique_ptr<Responses> out_responses;
254 std::unique_ptr<BlobDataHandles> out_blob_data_handles; 255 std::unique_ptr<BlobDataHandles> out_blob_data_handles;
256 std::vector<disk_cache::ScopedEntryPtr> out_entries;
255 257
256 std::unique_ptr<OpenAllEntriesContext> entries_context; 258 std::unique_ptr<OpenAllEntriesContext> entries_context;
257 259
258 private: 260 private:
259 DISALLOW_COPY_AND_ASSIGN(QueryCacheResults); 261 DISALLOW_COPY_AND_ASSIGN(QueryCacheResults);
260 }; 262 };
261 263
262 // static 264 // static
263 std::unique_ptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache( 265 std::unique_ptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache(
264 const GURL& origin, 266 const GURL& origin,
(...skipping 26 matching lines...) Expand all
291 cache->InitBackend(); 293 cache->InitBackend();
292 return base::WrapUnique(cache); 294 return base::WrapUnique(cache);
293 } 295 }
294 296
295 base::WeakPtr<CacheStorageCache> CacheStorageCache::AsWeakPtr() { 297 base::WeakPtr<CacheStorageCache> CacheStorageCache::AsWeakPtr() {
296 return weak_ptr_factory_.GetWeakPtr(); 298 return weak_ptr_factory_.GetWeakPtr();
297 } 299 }
298 300
299 void CacheStorageCache::Match( 301 void CacheStorageCache::Match(
300 std::unique_ptr<ServiceWorkerFetchRequest> request, 302 std::unique_ptr<ServiceWorkerFetchRequest> request,
303 const CacheStorageCacheQueryParams& match_params,
301 const ResponseCallback& callback) { 304 const ResponseCallback& callback) {
302 if (backend_state_ == BACKEND_CLOSED) { 305 if (backend_state_ == BACKEND_CLOSED) {
303 callback.Run(CACHE_STORAGE_ERROR_STORAGE, 306 callback.Run(CACHE_STORAGE_ERROR_STORAGE,
304 std::unique_ptr<ServiceWorkerResponse>(), 307 std::unique_ptr<ServiceWorkerResponse>(),
305 std::unique_ptr<storage::BlobDataHandle>()); 308 std::unique_ptr<storage::BlobDataHandle>());
306 return; 309 return;
307 } 310 }
308 311
309 scheduler_->ScheduleOperation( 312 scheduler_->ScheduleOperation(
310 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), 313 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(),
311 base::Passed(std::move(request)), 314 base::Passed(std::move(request)), match_params,
312 scheduler_->WrapCallbackToRunNext(callback))); 315 scheduler_->WrapCallbackToRunNext(callback)));
313 } 316 }
314 317
315 void CacheStorageCache::MatchAll( 318 void CacheStorageCache::MatchAll(
316 std::unique_ptr<ServiceWorkerFetchRequest> request, 319 std::unique_ptr<ServiceWorkerFetchRequest> request,
317 const CacheStorageCacheQueryParams& match_params, 320 const CacheStorageCacheQueryParams& match_params,
318 const ResponsesCallback& callback) { 321 const ResponsesCallback& callback) {
319 if (backend_state_ == BACKEND_CLOSED) { 322 if (backend_state_ == BACKEND_CLOSED) {
320 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Responses>(), 323 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Responses>(),
321 std::unique_ptr<BlobDataHandles>()); 324 std::unique_ptr<BlobDataHandles>());
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 584
582 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); 585 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback);
583 586
584 if (rv != net::ERR_IO_PENDING) 587 if (rv != net::ERR_IO_PENDING)
585 open_entry_callback.Run(rv); 588 open_entry_callback.Run(rv);
586 } 589 }
587 590
588 void CacheStorageCache::QueryCache( 591 void CacheStorageCache::QueryCache(
589 std::unique_ptr<ServiceWorkerFetchRequest> request, 592 std::unique_ptr<ServiceWorkerFetchRequest> request,
590 const CacheStorageCacheQueryParams& options, 593 const CacheStorageCacheQueryParams& options,
594 QueryCacheType query_type,
591 const QueryCacheResultsCallback& callback) { 595 const QueryCacheResultsCallback& callback) {
592 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 596 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
593 if (backend_state_ != BACKEND_OPEN) { 597 if (backend_state_ != BACKEND_OPEN) {
594 callback.Run(CACHE_STORAGE_ERROR_STORAGE, 598 callback.Run(CACHE_STORAGE_ERROR_STORAGE,
595 std::unique_ptr<QueryCacheResults>()); 599 std::unique_ptr<QueryCacheResults>());
596 return; 600 return;
597 } 601 }
598 602
599 if (!options.ignore_method && request && !request->method.empty() && 603 if (!options.ignore_method && request && !request->method.empty() &&
600 request->method != "GET") { 604 request->method != "GET") {
601 callback.Run(CACHE_STORAGE_OK, base::MakeUnique<QueryCacheResults>( 605 callback.Run(CACHE_STORAGE_OK, base::MakeUnique<QueryCacheResults>(
602 std::move(request), options, callback)); 606 std::move(request), options, callback));
603 return; 607 return;
604 } 608 }
605 609
610 ServiceWorkerFetchRequest* request_ptr = request.get();
611
606 std::unique_ptr<QueryCacheResults> query_cache_results( 612 std::unique_ptr<QueryCacheResults> query_cache_results(
607 new QueryCacheResults(std::move(request), options, callback)); 613 new QueryCacheResults(std::move(request), options, callback));
614 query_cache_results->query_type = query_type;
615
616 if (query_cache_results->request &&
617 !query_cache_results->request->url.is_empty() && !options.ignore_search) {
618 // There is no need to scan the entire backend, just search for the exact
619 // URL.
620 std::unique_ptr<disk_cache::Entry*> entry =
621 base::MakeUnique<disk_cache::Entry*>();
622 disk_cache::Entry** entry_ptr = entry.get();
623
624 net::CompletionCallback open_entry_callback =
625 base::Bind(&CacheStorageCache::QueryCacheDidOpenEntry,
626 weak_ptr_factory_.GetWeakPtr(),
627 base::Passed(std::move(query_cache_results)),
628 base::Passed(std::move(entry)));
629 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr,
630 open_entry_callback);
631 if (rv != net::ERR_IO_PENDING)
632 open_entry_callback.Run(rv);
633 return;
634 }
635
608 OpenAllEntries(base::Bind(&CacheStorageCache::QueryCacheDidOpenAllEntries, 636 OpenAllEntries(base::Bind(&CacheStorageCache::QueryCacheDidOpenAllEntries,
609 weak_ptr_factory_.GetWeakPtr(), 637 weak_ptr_factory_.GetWeakPtr(),
610 base::Passed(std::move(query_cache_results)))); 638 base::Passed(std::move(query_cache_results))));
611 } 639 }
612 640
641 void CacheStorageCache::QueryCacheDidOpenEntry(
642 std::unique_ptr<QueryCacheResults> query_cache_results,
643 std::unique_ptr<disk_cache::Entry*> entry,
644 int rv) {
645 if (rv != net::OK) {
646 QueryCacheResults* results = query_cache_results.get();
647 results->callback.Run(CACHE_STORAGE_OK, std::move(query_cache_results));
648 return;
649 }
650
651 std::unique_ptr<OpenAllEntriesContext> entries_context =
652 base::MakeUnique<OpenAllEntriesContext>();
653 entries_context->entries.push_back(*entry.get());
654 QueryCacheDidOpenAllEntries(std::move(query_cache_results),
655 std::move(entries_context), CACHE_STORAGE_OK);
656 }
657
613 void CacheStorageCache::QueryCacheDidOpenAllEntries( 658 void CacheStorageCache::QueryCacheDidOpenAllEntries(
614 std::unique_ptr<QueryCacheResults> query_cache_results, 659 std::unique_ptr<QueryCacheResults> query_cache_results,
615 std::unique_ptr<OpenAllEntriesContext> entries_context, 660 std::unique_ptr<OpenAllEntriesContext> entries_context,
616 CacheStorageError error) { 661 CacheStorageError error) {
617 if (error != CACHE_STORAGE_OK) { 662 if (error != CACHE_STORAGE_OK) {
618 query_cache_results->callback.Run(error, 663 query_cache_results->callback.Run(error,
619 std::unique_ptr<QueryCacheResults>()); 664 std::unique_ptr<QueryCacheResults>());
620 return; 665 return;
621 } 666 }
622 667
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 *iter = nullptr; 711 *iter = nullptr;
667 712
668 if (!metadata) { 713 if (!metadata) {
669 entry->Doom(); 714 entry->Doom();
670 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1); 715 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1);
671 return; 716 return;
672 } 717 }
673 718
674 ServiceWorkerFetchRequest request; 719 ServiceWorkerFetchRequest request;
675 PopulateRequestFromMetadata(*metadata, GURL(entry->GetKey()), &request); 720 PopulateRequestFromMetadata(*metadata, GURL(entry->GetKey()), &request);
676 query_cache_results->out_requests->push_back(request);
677 721
678 ServiceWorkerResponse response; 722 ServiceWorkerResponse response;
679 PopulateResponseMetadata(*metadata, &response); 723 PopulateResponseMetadata(*metadata, &response);
680 724
725 if (query_cache_results->request &&
726 !query_cache_results->options.ignore_vary &&
727 !VaryMatches(query_cache_results->request->headers, request.headers,
728 response.headers)) {
729 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1);
730 return;
731 }
732
733 if (query_cache_results->query_type == QueryCacheType::CACHE_ENTRIES) {
734 query_cache_results->out_entries.push_back(std::move(entry));
735 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1);
736 return;
737 }
738 DCHECK_EQ(QueryCacheType::REQUESTS_AND_RESPONSES,
739 query_cache_results->query_type);
740
741 query_cache_results->out_requests->push_back(request);
742
681 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) { 743 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) {
682 query_cache_results->out_responses->push_back(response); 744 query_cache_results->out_responses->push_back(response);
683 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1); 745 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1);
684 return; 746 return;
685 } 747 }
686 748
687 if (!blob_storage_context_) { 749 if (!blob_storage_context_) {
688 query_cache_results->callback.Run(CACHE_STORAGE_ERROR_STORAGE, 750 query_cache_results->callback.Run(CACHE_STORAGE_ERROR_STORAGE,
689 std::unique_ptr<QueryCacheResults>()); 751 std::unique_ptr<QueryCacheResults>());
690 return; 752 return;
691 } 753 }
692 754
693 std::unique_ptr<storage::BlobDataHandle> blob_data_handle = 755 std::unique_ptr<storage::BlobDataHandle> blob_data_handle =
694 PopulateResponseBody(std::move(entry), &response); 756 PopulateResponseBody(std::move(entry), &response);
695 757
696 query_cache_results->out_responses->push_back(response); 758 query_cache_results->out_responses->push_back(response);
697 query_cache_results->out_blob_data_handles->push_back(*blob_data_handle); 759 query_cache_results->out_blob_data_handles->push_back(*blob_data_handle);
698 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1); 760 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1);
699 } 761 }
700 762
701 void CacheStorageCache::MatchImpl( 763 void CacheStorageCache::MatchImpl(
702 std::unique_ptr<ServiceWorkerFetchRequest> request, 764 std::unique_ptr<ServiceWorkerFetchRequest> request,
765 const CacheStorageCacheQueryParams& match_params,
703 const ResponseCallback& callback) { 766 const ResponseCallback& callback) {
704 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 767 MatchAllImpl(std::move(request), match_params,
705 if (backend_state_ != BACKEND_OPEN) { 768 base::Bind(&CacheStorageCache::MatchDidMatchAll,
706 callback.Run(CACHE_STORAGE_ERROR_STORAGE, 769 weak_ptr_factory_.GetWeakPtr(), callback));
707 std::unique_ptr<ServiceWorkerResponse>(), 770 }
771
772 void CacheStorageCache::MatchDidMatchAll(
773 const ResponseCallback& callback,
774 CacheStorageError match_all_error,
775 std::unique_ptr<Responses> match_all_responses,
776 std::unique_ptr<BlobDataHandles> match_all_handles) {
777 if (match_all_error != CACHE_STORAGE_OK) {
778 callback.Run(match_all_error, std::unique_ptr<ServiceWorkerResponse>(),
708 std::unique_ptr<storage::BlobDataHandle>()); 779 std::unique_ptr<storage::BlobDataHandle>());
709 return; 780 return;
710 } 781 }
711 782
712 if (!request->method.empty() && request->method != "GET") { 783 if (match_all_responses->empty()) {
713 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND, 784 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND,
714 std::unique_ptr<ServiceWorkerResponse>(), 785 std::unique_ptr<ServiceWorkerResponse>(),
715 std::unique_ptr<storage::BlobDataHandle>()); 786 std::unique_ptr<storage::BlobDataHandle>());
716 return; 787 return;
717 } 788 }
718 789
719 std::unique_ptr<disk_cache::Entry*> scoped_entry_ptr( 790 std::unique_ptr<ServiceWorkerResponse> response =
720 new disk_cache::Entry*()); 791 base::MakeUnique<ServiceWorkerResponse>(match_all_responses->at(0));
721 disk_cache::Entry** entry_ptr = scoped_entry_ptr.get();
722 ServiceWorkerFetchRequest* request_ptr = request.get();
723 792
724 net::CompletionCallback open_entry_callback = base::Bind( 793 std::unique_ptr<storage::BlobDataHandle> data_handle;
725 &CacheStorageCache::MatchDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), 794 if (response->blob_size > 0) {
726 base::Passed(std::move(request)), callback, 795 // NOTE: This assumes that MatchAll returns the handles in the same order
727 base::Passed(std::move(scoped_entry_ptr))); 796 // as the responses.
728 797 data_handle =
729 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, 798 base::MakeUnique<storage::BlobDataHandle>(match_all_handles->at(0));
730 open_entry_callback);
731 if (rv != net::ERR_IO_PENDING)
732 open_entry_callback.Run(rv);
733 }
734
735 void CacheStorageCache::MatchDidOpenEntry(
736 std::unique_ptr<ServiceWorkerFetchRequest> request,
737 const ResponseCallback& callback,
738 std::unique_ptr<disk_cache::Entry*> entry_ptr,
739 int rv) {
740 if (rv != net::OK) {
741 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND,
742 std::unique_ptr<ServiceWorkerResponse>(),
743 std::unique_ptr<storage::BlobDataHandle>());
744 return;
745 }
746 disk_cache::ScopedEntryPtr entry(*entry_ptr);
747
748 MetadataCallback headers_callback = base::Bind(
749 &CacheStorageCache::MatchDidReadMetadata, weak_ptr_factory_.GetWeakPtr(),
750 base::Passed(std::move(request)), callback,
751 base::Passed(std::move(entry)));
752
753 ReadMetadata(*entry_ptr, headers_callback);
754 }
755
756 void CacheStorageCache::MatchDidReadMetadata(
757 std::unique_ptr<ServiceWorkerFetchRequest> request,
758 const ResponseCallback& callback,
759 disk_cache::ScopedEntryPtr entry,
760 std::unique_ptr<CacheMetadata> metadata) {
761 if (!metadata) {
762 callback.Run(CACHE_STORAGE_ERROR_STORAGE,
763 std::unique_ptr<ServiceWorkerResponse>(),
764 std::unique_ptr<storage::BlobDataHandle>());
765 return;
766 } 799 }
767 800
768 std::unique_ptr<ServiceWorkerResponse> response(new ServiceWorkerResponse); 801 callback.Run(CACHE_STORAGE_OK, std::move(response), std::move(data_handle));
769 PopulateResponseMetadata(*metadata, response.get());
770
771 ServiceWorkerHeaderMap cached_request_headers;
772 for (int i = 0; i < metadata->request().headers_size(); ++i) {
773 const CacheHeaderMap header = metadata->request().headers(i);
774 DCHECK_EQ(std::string::npos, header.name().find('\0'));
775 DCHECK_EQ(std::string::npos, header.value().find('\0'));
776 cached_request_headers[header.name()] = header.value();
777 }
778
779 if (!VaryMatches(request->headers, cached_request_headers,
780 response->headers)) {
781 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND,
782 std::unique_ptr<ServiceWorkerResponse>(),
783 std::unique_ptr<storage::BlobDataHandle>());
784 return;
785 }
786
787 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) {
788 callback.Run(CACHE_STORAGE_OK, std::move(response),
789 std::unique_ptr<storage::BlobDataHandle>());
790 return;
791 }
792
793 if (!blob_storage_context_) {
794 callback.Run(CACHE_STORAGE_ERROR_STORAGE,
795 std::unique_ptr<ServiceWorkerResponse>(),
796 std::unique_ptr<storage::BlobDataHandle>());
797 return;
798 }
799
800 std::unique_ptr<storage::BlobDataHandle> blob_data_handle =
801 PopulateResponseBody(std::move(entry), response.get());
802 callback.Run(CACHE_STORAGE_OK, std::move(response),
803 std::move(blob_data_handle));
804 } 802 }
805 803
806 void CacheStorageCache::MatchAllImpl( 804 void CacheStorageCache::MatchAllImpl(
807 std::unique_ptr<ServiceWorkerFetchRequest> request, 805 std::unique_ptr<ServiceWorkerFetchRequest> request,
808 const CacheStorageCacheQueryParams& options, 806 const CacheStorageCacheQueryParams& options,
809 const ResponsesCallback& callback) { 807 const ResponsesCallback& callback) {
810 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 808 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
811 if (backend_state_ != BACKEND_OPEN) { 809 if (backend_state_ != BACKEND_OPEN) {
812 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Responses>(), 810 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Responses>(),
813 std::unique_ptr<BlobDataHandles>()); 811 std::unique_ptr<BlobDataHandles>());
814 return; 812 return;
815 } 813 }
816 814
817 QueryCache(std::move(request), options, 815 QueryCache(std::move(request), options,
816 QueryCacheType::REQUESTS_AND_RESPONSES,
818 base::Bind(&CacheStorageCache::MatchAllDidQueryCache, 817 base::Bind(&CacheStorageCache::MatchAllDidQueryCache,
819 weak_ptr_factory_.GetWeakPtr(), callback)); 818 weak_ptr_factory_.GetWeakPtr(), callback));
820 } 819 }
821 820
822 void CacheStorageCache::MatchAllDidQueryCache( 821 void CacheStorageCache::MatchAllDidQueryCache(
823 const ResponsesCallback& callback, 822 const ResponsesCallback& callback,
824 CacheStorageError error, 823 CacheStorageError error,
825 std::unique_ptr<QueryCacheResults> query_cache_results) { 824 std::unique_ptr<QueryCacheResults> query_cache_results) {
826 if (error != CACHE_STORAGE_OK) { 825 if (error != CACHE_STORAGE_OK) {
827 callback.Run(error, std::unique_ptr<Responses>(), 826 callback.Run(error, std::unique_ptr<Responses>(),
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 base::Passed(std::move(put_context)))); 997 base::Passed(std::move(put_context))));
999 } 998 }
1000 999
1001 void CacheStorageCache::PutImpl(std::unique_ptr<PutContext> put_context) { 1000 void CacheStorageCache::PutImpl(std::unique_ptr<PutContext> put_context) {
1002 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1001 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1003 if (backend_state_ != BACKEND_OPEN) { 1002 if (backend_state_ != BACKEND_OPEN) {
1004 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 1003 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
1005 return; 1004 return;
1006 } 1005 }
1007 1006
1008 std::unique_ptr<ServiceWorkerFetchRequest> request_copy( 1007 std::string key = put_context->request->url.spec();
1009 new ServiceWorkerFetchRequest(*put_context->request));
1010 1008
1011 DeleteImpl(std::move(request_copy), CacheStorageCacheQueryParams(), 1009 net::CompletionCallback callback = base::Bind(
1012 base::Bind(&CacheStorageCache::PutDidDelete, 1010 &CacheStorageCache::PutDidDoomEntry, weak_ptr_factory_.GetWeakPtr(),
1013 weak_ptr_factory_.GetWeakPtr(), 1011 base::Passed(std::move(put_context)));
1014 base::Passed(std::move(put_context)))); 1012
1013 int rv = backend_->DoomEntry(key, callback);
1014 if (rv != net::ERR_IO_PENDING)
1015 callback.Run(rv);
1015 } 1016 }
1016 1017
1017 void CacheStorageCache::PutDidDelete(std::unique_ptr<PutContext> put_context, 1018 void CacheStorageCache::PutDidDoomEntry(std::unique_ptr<PutContext> put_context,
1018 CacheStorageError delete_error) { 1019 int rv) {
1019 if (backend_state_ != BACKEND_OPEN) { 1020 if (backend_state_ != BACKEND_OPEN) {
1020 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 1021 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
1021 return; 1022 return;
1022 } 1023 }
1023 1024
1025 // |rv| is ignored as doom entry can fail if the entry doesn't exist.
1026
1024 std::unique_ptr<disk_cache::Entry*> scoped_entry_ptr( 1027 std::unique_ptr<disk_cache::Entry*> scoped_entry_ptr(
1025 new disk_cache::Entry*()); 1028 new disk_cache::Entry*());
1026 disk_cache::Entry** entry_ptr = scoped_entry_ptr.get(); 1029 disk_cache::Entry** entry_ptr = scoped_entry_ptr.get();
1027 ServiceWorkerFetchRequest* request_ptr = put_context->request.get(); 1030 ServiceWorkerFetchRequest* request_ptr = put_context->request.get();
1028 disk_cache::Backend* backend_ptr = backend_.get(); 1031 disk_cache::Backend* backend_ptr = backend_.get();
1029 1032
1030 net::CompletionCallback create_entry_callback = base::Bind( 1033 net::CompletionCallback create_entry_callback = base::Bind(
1031 &CacheStorageCache::PutDidCreateEntry, weak_ptr_factory_.GetWeakPtr(), 1034 &CacheStorageCache::PutDidCreateEntry, weak_ptr_factory_.GetWeakPtr(),
1032 base::Passed(std::move(scoped_entry_ptr)), 1035 base::Passed(std::move(scoped_entry_ptr)),
1033 base::Passed(std::move(put_context))); 1036 base::Passed(std::move(put_context)));
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 void CacheStorageCache::DeleteImpl( 1217 void CacheStorageCache::DeleteImpl(
1215 std::unique_ptr<ServiceWorkerFetchRequest> request, 1218 std::unique_ptr<ServiceWorkerFetchRequest> request,
1216 const CacheStorageCacheQueryParams& match_params, 1219 const CacheStorageCacheQueryParams& match_params,
1217 const ErrorCallback& callback) { 1220 const ErrorCallback& callback) {
1218 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1221 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1219 if (backend_state_ != BACKEND_OPEN) { 1222 if (backend_state_ != BACKEND_OPEN) {
1220 callback.Run(CACHE_STORAGE_ERROR_STORAGE); 1223 callback.Run(CACHE_STORAGE_ERROR_STORAGE);
1221 return; 1224 return;
1222 } 1225 }
1223 1226
1224 if (match_params.ignore_search) { 1227 QueryCache(std::move(request), match_params, QueryCacheType::CACHE_ENTRIES,
1225 OpenAllEntries(base::Bind(&CacheStorageCache::DeleteDidOpenAllEntries, 1228 base::Bind(&CacheStorageCache::DeleteDidQueryCache,
1226 weak_ptr_factory_.GetWeakPtr(), 1229 weak_ptr_factory_.GetWeakPtr(), callback));
1227 base::Passed(std::move(request)), callback));
1228 return;
1229 }
1230
1231 std::unique_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*);
1232
1233 disk_cache::Entry** entry_ptr = entry.get();
1234
1235 ServiceWorkerFetchRequest* request_ptr = request.get();
1236
1237 net::CompletionCallback open_entry_callback = base::Bind(
1238 &CacheStorageCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(),
1239 origin_, base::Passed(std::move(request)), callback,
1240 base::Passed(std::move(entry)));
1241
1242 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr,
1243 open_entry_callback);
1244 if (rv != net::ERR_IO_PENDING)
1245 open_entry_callback.Run(rv);
1246 } 1230 }
1247 1231
1248 void CacheStorageCache::DeleteDidOpenAllEntries( 1232 void CacheStorageCache::DeleteDidQueryCache(
1249 std::unique_ptr<ServiceWorkerFetchRequest> request,
1250 const ErrorCallback& callback, 1233 const ErrorCallback& callback,
1251 std::unique_ptr<OpenAllEntriesContext> entries_context, 1234 CacheStorageError error,
1252 CacheStorageError error) { 1235 std::unique_ptr<QueryCacheResults> query_cache_results) {
1253 if (error != CACHE_STORAGE_OK) { 1236 if (error != CACHE_STORAGE_OK) {
1254 callback.Run(error); 1237 callback.Run(error);
1255 return; 1238 return;
1256 } 1239 }
1257 1240
1258 GURL request_url_without_query = RemoveQueryParam(request->url); 1241 if (query_cache_results->out_entries.empty()) {
1259 for (Entries::iterator iter = entries_context->entries.begin();
1260 iter != entries_context->entries.end(); iter++) {
1261 disk_cache::Entry* entry(*iter);
1262 if (request_url_without_query == RemoveQueryParam(GURL(entry->GetKey())))
1263 entry->Doom();
1264 }
1265
1266 entries_context.reset();
1267
1268 UpdateCacheSize();
1269 callback.Run(CACHE_STORAGE_OK);
1270 }
1271
1272 void CacheStorageCache::DeleteDidOpenEntry(
1273 const GURL& origin,
1274 std::unique_ptr<ServiceWorkerFetchRequest> request,
1275 const CacheStorageCache::ErrorCallback& callback,
1276 std::unique_ptr<disk_cache::Entry*> entry_ptr,
1277 int rv) {
1278 if (rv != net::OK) {
1279 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND); 1242 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND);
1280 return; 1243 return;
1281 } 1244 }
1282 1245
1283 DCHECK(entry_ptr); 1246 for (auto& entry : query_cache_results->out_entries) {
1284 disk_cache::ScopedEntryPtr entry(*entry_ptr); 1247 entry->Doom();
1285 1248 entry.reset();
1286 entry->Doom(); 1249 }
1287 entry.reset();
1288 1250
1289 UpdateCacheSize(); 1251 UpdateCacheSize();
1290 callback.Run(CACHE_STORAGE_OK); 1252 callback.Run(CACHE_STORAGE_OK);
1291 } 1253 }
1292 1254
1293 void CacheStorageCache::KeysImpl( 1255 void CacheStorageCache::KeysImpl(
1294 std::unique_ptr<ServiceWorkerFetchRequest> request, 1256 std::unique_ptr<ServiceWorkerFetchRequest> request,
1295 const CacheStorageCacheQueryParams& options, 1257 const CacheStorageCacheQueryParams& options,
1296 const RequestsCallback& callback) { 1258 const RequestsCallback& callback) {
1297 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1259 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1298 if (backend_state_ != BACKEND_OPEN) { 1260 if (backend_state_ != BACKEND_OPEN) {
1299 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>()); 1261 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>());
1300 return; 1262 return;
1301 } 1263 }
1302 1264
1303 QueryCache(std::move(request), options, 1265 QueryCache(std::move(request), options,
1266 QueryCacheType::REQUESTS_AND_RESPONSES,
1304 base::Bind(&CacheStorageCache::KeysDidQueryCache, 1267 base::Bind(&CacheStorageCache::KeysDidQueryCache,
1305 weak_ptr_factory_.GetWeakPtr(), callback)); 1268 weak_ptr_factory_.GetWeakPtr(), callback));
1306 } 1269 }
1307 1270
1308 void CacheStorageCache::KeysDidQueryCache( 1271 void CacheStorageCache::KeysDidQueryCache(
1309 const RequestsCallback& callback, 1272 const RequestsCallback& callback,
1310 CacheStorageError error, 1273 CacheStorageError error,
1311 std::unique_ptr<QueryCacheResults> query_cache_results) { 1274 std::unique_ptr<QueryCacheResults> query_cache_results) {
1312 if (error != CACHE_STORAGE_OK) { 1275 if (error != CACHE_STORAGE_OK) {
1313 callback.Run(error, std::unique_ptr<Requests>()); 1276 callback.Run(error, std::unique_ptr<Requests>());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); 1442 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA);
1480 return blob_storage_context_->AddFinishedBlob(&blob_data); 1443 return blob_storage_context_->AddFinishedBlob(&blob_data);
1481 } 1444 }
1482 1445
1483 std::unique_ptr<CacheStorageCacheHandle> 1446 std::unique_ptr<CacheStorageCacheHandle>
1484 CacheStorageCache::CreateCacheHandle() { 1447 CacheStorageCache::CreateCacheHandle() {
1485 return cache_storage_->CreateCacheHandle(this); 1448 return cache_storage_->CreateCacheHandle(this);
1486 } 1449 }
1487 1450
1488 } // namespace content 1451 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.h ('k') | content/browser/cache_storage/cache_storage_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698