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

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

Issue 1248003004: CacheStorage: Implement Cache.matchAll() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: replace ScopedVector<BlobDataHandle> with scoped_ptr<std::vector<BlobDataHandle>> Created 5 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 <string> 7 #include <string>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (!metadata->ParseFromArray(buffer->data(), buffer->size())) { 175 if (!metadata->ParseFromArray(buffer->data(), buffer->size())) {
176 callback.Run(scoped_ptr<CacheMetadata>()); 176 callback.Run(scoped_ptr<CacheMetadata>());
177 return; 177 return;
178 } 178 }
179 179
180 callback.Run(metadata.Pass()); 180 callback.Run(metadata.Pass());
181 } 181 }
182 182
183 } // namespace 183 } // namespace
184 184
185 // The state needed to pass between CacheStorageCache::Keys callbacks. 185 // The state needed to iterate all entries in the cache.
186 struct CacheStorageCache::KeysContext { 186 struct CacheStorageCache::OpenAllEntriesContext {
187 explicit KeysContext(const CacheStorageCache::RequestsCallback& callback) 187 OpenAllEntriesContext() : enumerated_entry(nullptr) {}
188 : original_callback(callback), 188 ~OpenAllEntriesContext() {
189 out_keys(new CacheStorageCache::Requests()), 189 for (size_t i = 0, max = entries.size(); i < max; ++i) {
190 enumerated_entry(NULL) {} 190 if (entries[i])
191 191 entries[i]->Close();
192 ~KeysContext() { 192 }
193 for (size_t i = 0, max = entries.size(); i < max; ++i)
194 entries[i]->Close();
195 if (enumerated_entry) 193 if (enumerated_entry)
196 enumerated_entry->Close(); 194 enumerated_entry->Close();
197 } 195 }
198 196
199 // The callback passed to the Keys() function.
200 CacheStorageCache::RequestsCallback original_callback;
201
202 // The vector of open entries in the backend. 197 // The vector of open entries in the backend.
203 Entries entries; 198 Entries entries;
204 199
205 // The output of the Keys function.
206 scoped_ptr<CacheStorageCache::Requests> out_keys;
207
208 // Used for enumerating cache entries. 200 // Used for enumerating cache entries.
209 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator; 201 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator;
210 disk_cache::Entry* enumerated_entry; 202 disk_cache::Entry* enumerated_entry;
211 203
212 private: 204 private:
205 DISALLOW_COPY_AND_ASSIGN(OpenAllEntriesContext);
206 };
207
208 // The state needed to pass between CacheStorageCache::MatchAll callbacks.
209 struct CacheStorageCache::MatchAllContext {
210 explicit MatchAllContext(const CacheStorageCache::ResponsesCallback& callback)
211 : original_callback(callback),
212 out_responses(new Responses),
213 out_blob_data_handles(new BlobDataHandles) {}
214 ~MatchAllContext() {}
215
216 // The callback passed to the MatchAll() function.
217 ResponsesCallback original_callback;
218
219 // The outputs of the MatchAll function.
220 scoped_ptr<Responses> out_responses;
221 scoped_ptr<BlobDataHandles> out_blob_data_handles;
222
223 // The context holding open entries.
224 scoped_ptr<OpenAllEntriesContext> entries_context;
225
226 private:
227 DISALLOW_COPY_AND_ASSIGN(MatchAllContext);
228 };
229
230 // The state needed to pass between CacheStorageCache::Keys callbacks.
231 struct CacheStorageCache::KeysContext {
232 explicit KeysContext(const CacheStorageCache::RequestsCallback& callback)
233 : original_callback(callback), out_keys(new Requests()) {}
234 ~KeysContext() {}
235
236 // The callback passed to the Keys() function.
237 RequestsCallback original_callback;
238
239 // The output of the Keys function.
240 scoped_ptr<Requests> out_keys;
241
242 // The context holding open entries.
243 scoped_ptr<OpenAllEntriesContext> entries_context;
244
245 private:
213 DISALLOW_COPY_AND_ASSIGN(KeysContext); 246 DISALLOW_COPY_AND_ASSIGN(KeysContext);
214 }; 247 };
215 248
216 // The state needed to pass between CacheStorageCache::Put callbacks. 249 // The state needed to pass between CacheStorageCache::Put callbacks.
217 struct CacheStorageCache::PutContext { 250 struct CacheStorageCache::PutContext {
218 PutContext( 251 PutContext(
219 const GURL& origin, 252 const GURL& origin,
220 scoped_ptr<ServiceWorkerFetchRequest> request, 253 scoped_ptr<ServiceWorkerFetchRequest> request,
221 scoped_ptr<ServiceWorkerResponse> response, 254 scoped_ptr<ServiceWorkerResponse> response,
222 scoped_ptr<storage::BlobDataHandle> blob_data_handle, 255 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 317 }
285 318
286 ResponseCallback pending_callback = 319 ResponseCallback pending_callback =
287 base::Bind(&CacheStorageCache::PendingResponseCallback, 320 base::Bind(&CacheStorageCache::PendingResponseCallback,
288 weak_ptr_factory_.GetWeakPtr(), callback); 321 weak_ptr_factory_.GetWeakPtr(), callback);
289 scheduler_->ScheduleOperation( 322 scheduler_->ScheduleOperation(
290 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), 323 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(),
291 base::Passed(request.Pass()), pending_callback)); 324 base::Passed(request.Pass()), pending_callback));
292 } 325 }
293 326
327 void CacheStorageCache::MatchAll(const ResponsesCallback& callback) {
328 if (!LazyInitialize()) {
329 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(),
330 scoped_ptr<BlobDataHandles>());
331 return;
332 }
333
334 ResponsesCallback pending_callback =
335 base::Bind(&CacheStorageCache::PendingResponsesCallback,
336 weak_ptr_factory_.GetWeakPtr(), callback);
337 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl,
338 weak_ptr_factory_.GetWeakPtr(),
339 pending_callback));
340 }
341
294 void CacheStorageCache::BatchOperation( 342 void CacheStorageCache::BatchOperation(
295 const std::vector<CacheStorageBatchOperation>& operations, 343 const std::vector<CacheStorageBatchOperation>& operations,
296 const ErrorCallback& callback) { 344 const ErrorCallback& callback) {
297 if (!LazyInitialize()) { 345 if (!LazyInitialize()) {
298 callback.Run(CACHE_STORAGE_ERROR_STORAGE); 346 callback.Run(CACHE_STORAGE_ERROR_STORAGE);
299 return; 347 return;
300 } 348 }
301 349
302 scoped_ptr<ErrorCallback> callback_copy(new ErrorCallback(callback)); 350 scoped_ptr<ErrorCallback> callback_copy(new ErrorCallback(callback));
303 ErrorCallback* callback_ptr = callback_copy.get(); 351 ErrorCallback* callback_ptr = callback_copy.get();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 case BACKEND_CLOSED: 477 case BACKEND_CLOSED:
430 return false; 478 return false;
431 case BACKEND_OPEN: 479 case BACKEND_OPEN:
432 DCHECK(backend_); 480 DCHECK(backend_);
433 return true; 481 return true;
434 } 482 }
435 NOTREACHED(); 483 NOTREACHED();
436 return false; 484 return false;
437 } 485 }
438 486
487 void CacheStorageCache::OpenAllEntries(const OpenAllEntriesCallback& callback) {
488 scoped_ptr<OpenAllEntriesContext> entries_context(new OpenAllEntriesContext);
489 entries_context->backend_iterator = backend_->CreateIterator();
490 disk_cache::Backend::Iterator& iterator = *entries_context->backend_iterator;
491 disk_cache::Entry** enumerated_entry = &entries_context->enumerated_entry;
492
493 net::CompletionCallback open_entry_callback = base::Bind(
494 &CacheStorageCache::DidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(),
495 base::Passed(entries_context.Pass()), callback);
496
497 int rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback);
498
499 if (rv != net::ERR_IO_PENDING)
500 open_entry_callback.Run(rv);
501 }
502
503 void CacheStorageCache::DidOpenNextEntry(
504 scoped_ptr<OpenAllEntriesContext> entries_context,
505 const OpenAllEntriesCallback& callback,
506 int rv) {
507 if (rv == net::ERR_FAILED) {
508 DCHECK(!entries_context->enumerated_entry);
509 // Enumeration is complete, extract the requests from the entries.
510 callback.Run(entries_context.Pass(), CACHE_STORAGE_OK);
511 return;
512 }
513
514 if (rv < 0) {
515 callback.Run(entries_context.Pass(), CACHE_STORAGE_ERROR_STORAGE);
516 return;
517 }
518
519 if (backend_state_ != BACKEND_OPEN) {
520 callback.Run(entries_context.Pass(), CACHE_STORAGE_ERROR_NOT_FOUND);
521 return;
522 }
523
524 // Store the entry.
525 entries_context->entries.push_back(entries_context->enumerated_entry);
526 entries_context->enumerated_entry = nullptr;
527
528 // Enumerate the next entry.
529 disk_cache::Backend::Iterator& iterator = *entries_context->backend_iterator;
530 disk_cache::Entry** enumerated_entry = &entries_context->enumerated_entry;
531 net::CompletionCallback open_entry_callback = base::Bind(
532 &CacheStorageCache::DidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(),
533 base::Passed(entries_context.Pass()), callback);
534
535 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback);
536
537 if (rv != net::ERR_IO_PENDING)
538 open_entry_callback.Run(rv);
539 }
540
439 void CacheStorageCache::MatchImpl(scoped_ptr<ServiceWorkerFetchRequest> request, 541 void CacheStorageCache::MatchImpl(scoped_ptr<ServiceWorkerFetchRequest> request,
440 const ResponseCallback& callback) { 542 const ResponseCallback& callback) {
441 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 543 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
442 if (backend_state_ != BACKEND_OPEN) { 544 if (backend_state_ != BACKEND_OPEN) {
443 callback.Run(CACHE_STORAGE_ERROR_STORAGE, 545 callback.Run(CACHE_STORAGE_ERROR_STORAGE,
444 scoped_ptr<ServiceWorkerResponse>(), 546 scoped_ptr<ServiceWorkerResponse>(),
445 scoped_ptr<storage::BlobDataHandle>()); 547 scoped_ptr<storage::BlobDataHandle>());
446 return; 548 return;
447 } 549 }
448 550
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 const ResponseCallback& callback, 588 const ResponseCallback& callback,
487 disk_cache::ScopedEntryPtr entry, 589 disk_cache::ScopedEntryPtr entry,
488 scoped_ptr<CacheMetadata> metadata) { 590 scoped_ptr<CacheMetadata> metadata) {
489 if (!metadata) { 591 if (!metadata) {
490 callback.Run(CACHE_STORAGE_ERROR_STORAGE, 592 callback.Run(CACHE_STORAGE_ERROR_STORAGE,
491 scoped_ptr<ServiceWorkerResponse>(), 593 scoped_ptr<ServiceWorkerResponse>(),
492 scoped_ptr<storage::BlobDataHandle>()); 594 scoped_ptr<storage::BlobDataHandle>());
493 return; 595 return;
494 } 596 }
495 597
496 scoped_ptr<ServiceWorkerResponse> response(new ServiceWorkerResponse( 598 scoped_ptr<ServiceWorkerResponse> response(new ServiceWorkerResponse);
497 request->url, metadata->response().status_code(), 599 PopulateResponseMetadata(*metadata, response.get());
498 metadata->response().status_text(),
499 ProtoResponseTypeToWebResponseType(metadata->response().response_type()),
500 ServiceWorkerHeaderMap(), "", 0, GURL(),
501 blink::WebServiceWorkerResponseErrorUnknown));
502
503 if (metadata->response().has_url())
504 response->url = GURL(metadata->response().url());
505
506 for (int i = 0; i < metadata->response().headers_size(); ++i) {
507 const CacheHeaderMap header = metadata->response().headers(i);
508 DCHECK_EQ(std::string::npos, header.name().find('\0'));
509 DCHECK_EQ(std::string::npos, header.value().find('\0'));
510 response->headers.insert(std::make_pair(header.name(), header.value()));
511 }
512 600
513 ServiceWorkerHeaderMap cached_request_headers; 601 ServiceWorkerHeaderMap cached_request_headers;
514 for (int i = 0; i < metadata->request().headers_size(); ++i) { 602 for (int i = 0; i < metadata->request().headers_size(); ++i) {
515 const CacheHeaderMap header = metadata->request().headers(i); 603 const CacheHeaderMap header = metadata->request().headers(i);
516 DCHECK_EQ(std::string::npos, header.name().find('\0')); 604 DCHECK_EQ(std::string::npos, header.name().find('\0'));
517 DCHECK_EQ(std::string::npos, header.value().find('\0')); 605 DCHECK_EQ(std::string::npos, header.value().find('\0'));
518 cached_request_headers[header.name()] = header.value(); 606 cached_request_headers[header.name()] = header.value();
519 } 607 }
520 608
521 if (!VaryMatches(request->headers, cached_request_headers, 609 if (!VaryMatches(request->headers, cached_request_headers,
(...skipping 10 matching lines...) Expand all
532 return; 620 return;
533 } 621 }
534 622
535 if (!blob_storage_context_) { 623 if (!blob_storage_context_) {
536 callback.Run(CACHE_STORAGE_ERROR_STORAGE, 624 callback.Run(CACHE_STORAGE_ERROR_STORAGE,
537 scoped_ptr<ServiceWorkerResponse>(), 625 scoped_ptr<ServiceWorkerResponse>(),
538 scoped_ptr<storage::BlobDataHandle>()); 626 scoped_ptr<storage::BlobDataHandle>());
539 return; 627 return;
540 } 628 }
541 629
542 // Create a blob with the response body data. 630 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
543 response->blob_size = entry->GetDataSize(INDEX_RESPONSE_BODY); 631 PopulateResponseBody(entry.Pass(), response.get());
544 response->blob_uuid = base::GenerateGUID(); 632 callback.Run(CACHE_STORAGE_OK, response.Pass(), blob_data_handle.Pass());
545 storage::BlobDataBuilder blob_data(response->blob_uuid); 633 }
546 634
547 disk_cache::Entry* temp_entry = entry.get(); 635 void CacheStorageCache::MatchAllImpl(const ResponsesCallback& callback) {
548 blob_data.AppendDiskCacheEntry( 636 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
549 new CacheStorageCacheDataHandle(this, entry.Pass()), temp_entry, 637 if (backend_state_ != BACKEND_OPEN) {
550 INDEX_RESPONSE_BODY); 638 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(),
551 scoped_ptr<storage::BlobDataHandle> blob_data_handle( 639 scoped_ptr<BlobDataHandles>());
552 blob_storage_context_->AddFinishedBlob(&blob_data)); 640 return;
553 callback.Run(CACHE_STORAGE_OK, response.Pass(), blob_data_handle.Pass()); 641 }
642
643 OpenAllEntries(base::Bind(&CacheStorageCache::MatchAllDidOpenAllEntries,
644 weak_ptr_factory_.GetWeakPtr(), callback));
645 }
646
647 void CacheStorageCache::MatchAllDidOpenAllEntries(
648 const ResponsesCallback& callback,
649 scoped_ptr<OpenAllEntriesContext> entries_context,
650 CacheStorageError error) {
651 if (error != CACHE_STORAGE_OK) {
652 callback.Run(error, scoped_ptr<Responses>(), scoped_ptr<BlobDataHandles>());
653 return;
654 }
655
656 scoped_ptr<MatchAllContext> context(new MatchAllContext(callback));
657 context->entries_context.swap(entries_context);
658 Entries::iterator iter = context->entries_context->entries.begin();
659 MatchAllProcessNextEntry(context.Pass(), iter);
660 }
661
662 void CacheStorageCache::MatchAllProcessNextEntry(
663 scoped_ptr<MatchAllContext> context,
664 const Entries::iterator& iter) {
665 if (iter == context->entries_context->entries.end()) {
666 // All done. Return all of the responses.
667 context->original_callback.Run(CACHE_STORAGE_OK,
668 context->out_responses.Pass(),
669 context->out_blob_data_handles.Pass());
670 return;
671 }
672
673 ReadMetadata(*iter, base::Bind(&CacheStorageCache::MatchAllDidReadMetadata,
674 weak_ptr_factory_.GetWeakPtr(),
675 base::Passed(context.Pass()), iter));
676 }
677
678 void CacheStorageCache::MatchAllDidReadMetadata(
679 scoped_ptr<MatchAllContext> context,
680 const Entries::iterator& iter,
681 scoped_ptr<CacheMetadata> metadata) {
682 // Move ownership of the entry from the context.
683 disk_cache::ScopedEntryPtr entry(*iter);
684 *iter = nullptr;
685
686 if (!metadata) {
687 entry->Doom();
688 MatchAllProcessNextEntry(context.Pass(), iter + 1);
689 return;
690 }
691
692 ServiceWorkerResponse response;
693 PopulateResponseMetadata(*metadata, &response);
694
695 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) {
696 context->out_responses->push_back(response);
697 MatchAllProcessNextEntry(context.Pass(), iter + 1);
698 return;
699 }
700
701 if (!blob_storage_context_) {
702 context->original_callback.Run(CACHE_STORAGE_ERROR_STORAGE,
703 scoped_ptr<Responses>(),
704 scoped_ptr<BlobDataHandles>());
705 return;
706 }
707
708 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
709 PopulateResponseBody(entry.Pass(), &response);
710
711 context->out_responses->push_back(response);
712 context->out_blob_data_handles->push_back(*blob_data_handle);
713 MatchAllProcessNextEntry(context.Pass(), iter + 1);
554 } 714 }
555 715
556 void CacheStorageCache::Put(const CacheStorageBatchOperation& operation, 716 void CacheStorageCache::Put(const CacheStorageBatchOperation& operation,
557 const ErrorCallback& callback) { 717 const ErrorCallback& callback) {
558 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); 718 DCHECK(BACKEND_OPEN == backend_state_ || initializing_);
559 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT, operation.operation_type); 719 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT, operation.operation_type);
560 720
561 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( 721 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest(
562 operation.request.url, operation.request.method, 722 operation.request.url, operation.request.method,
563 operation.request.headers, operation.request.referrer, 723 operation.request.headers, operation.request.referrer,
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 // 1. Iterate through all of the entries, open them, and add them to a vector. 1017 // 1. Iterate through all of the entries, open them, and add them to a vector.
858 // 2. For each open entry: 1018 // 2. For each open entry:
859 // 2.1. Read the headers into a protobuf. 1019 // 2.1. Read the headers into a protobuf.
860 // 2.2. Copy the protobuf into a ServiceWorkerFetchRequest (a "key"). 1020 // 2.2. Copy the protobuf into a ServiceWorkerFetchRequest (a "key").
861 // 2.3. Push the response into a vector of requests to be returned. 1021 // 2.3. Push the response into a vector of requests to be returned.
862 // 3. Return the vector of requests (keys). 1022 // 3. Return the vector of requests (keys).
863 1023
864 // The entries have to be loaded into a vector first because enumeration loops 1024 // The entries have to be loaded into a vector first because enumeration loops
865 // forever if you read data from a cache entry while enumerating. 1025 // forever if you read data from a cache entry while enumerating.
866 1026
867 scoped_ptr<KeysContext> keys_context(new KeysContext(callback)); 1027 OpenAllEntries(base::Bind(&CacheStorageCache::KeysDidOpenAllEntries,
868 1028 weak_ptr_factory_.GetWeakPtr(), callback));
869 keys_context->backend_iterator = backend_->CreateIterator();
870 disk_cache::Backend::Iterator& iterator = *keys_context->backend_iterator;
871 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry;
872
873 net::CompletionCallback open_entry_callback = base::Bind(
874 &CacheStorageCache::KeysDidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(),
875 base::Passed(keys_context.Pass()));
876
877 int rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback);
878
879 if (rv != net::ERR_IO_PENDING)
880 open_entry_callback.Run(rv);
881 } 1029 }
882 1030
883 void CacheStorageCache::KeysDidOpenNextEntry( 1031 void CacheStorageCache::KeysDidOpenAllEntries(
884 scoped_ptr<KeysContext> keys_context, 1032 const RequestsCallback& callback,
885 int rv) { 1033 scoped_ptr<OpenAllEntriesContext> entries_context,
886 if (rv == net::ERR_FAILED) { 1034 CacheStorageError error) {
887 DCHECK(!keys_context->enumerated_entry); 1035 if (error != CACHE_STORAGE_OK) {
888 // Enumeration is complete, extract the requests from the entries. 1036 callback.Run(error, scoped_ptr<Requests>());
889 Entries::iterator iter = keys_context->entries.begin();
890 KeysProcessNextEntry(keys_context.Pass(), iter);
891 return; 1037 return;
892 } 1038 }
893 1039
894 if (rv < 0) { 1040 scoped_ptr<KeysContext> keys_context(new KeysContext(callback));
895 keys_context->original_callback.Run(CACHE_STORAGE_ERROR_STORAGE, 1041 keys_context->entries_context.swap(entries_context);
896 scoped_ptr<Requests>()); 1042 Entries::iterator iter = keys_context->entries_context->entries.begin();
897 return; 1043 KeysProcessNextEntry(keys_context.Pass(), iter);
898 }
899
900 if (backend_state_ != BACKEND_OPEN) {
901 keys_context->original_callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND,
902 scoped_ptr<Requests>());
903 return;
904 }
905
906 // Store the entry.
907 keys_context->entries.push_back(keys_context->enumerated_entry);
908 keys_context->enumerated_entry = NULL;
909
910 // Enumerate the next entry.
911 disk_cache::Backend::Iterator& iterator = *keys_context->backend_iterator;
912 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry;
913 net::CompletionCallback open_entry_callback = base::Bind(
914 &CacheStorageCache::KeysDidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(),
915 base::Passed(keys_context.Pass()));
916
917 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback);
918
919 if (rv != net::ERR_IO_PENDING)
920 open_entry_callback.Run(rv);
921 } 1044 }
922 1045
923 void CacheStorageCache::KeysProcessNextEntry( 1046 void CacheStorageCache::KeysProcessNextEntry(
924 scoped_ptr<KeysContext> keys_context, 1047 scoped_ptr<KeysContext> keys_context,
925 const Entries::iterator& iter) { 1048 const Entries::iterator& iter) {
926 if (iter == keys_context->entries.end()) { 1049 if (iter == keys_context->entries_context->entries.end()) {
927 // All done. Return all of the keys. 1050 // All done. Return all of the keys.
928 keys_context->original_callback.Run(CACHE_STORAGE_OK, 1051 keys_context->original_callback.Run(CACHE_STORAGE_OK,
929 keys_context->out_keys.Pass()); 1052 keys_context->out_keys.Pass());
930 return; 1053 return;
931 } 1054 }
932 1055
933 ReadMetadata(*iter, base::Bind(&CacheStorageCache::KeysDidReadMetadata, 1056 ReadMetadata(*iter, base::Bind(&CacheStorageCache::KeysDidReadMetadata,
934 weak_ptr_factory_.GetWeakPtr(), 1057 weak_ptr_factory_.GetWeakPtr(),
935 base::Passed(keys_context.Pass()), iter)); 1058 base::Passed(keys_context.Pass()), iter));
936 } 1059 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 CacheStorageError error, 1183 CacheStorageError error,
1061 scoped_ptr<ServiceWorkerResponse> response, 1184 scoped_ptr<ServiceWorkerResponse> response,
1062 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 1185 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
1063 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); 1186 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1064 1187
1065 callback.Run(error, response.Pass(), blob_data_handle.Pass()); 1188 callback.Run(error, response.Pass(), blob_data_handle.Pass());
1066 if (cache) 1189 if (cache)
1067 scheduler_->CompleteOperationAndRunNext(); 1190 scheduler_->CompleteOperationAndRunNext();
1068 } 1191 }
1069 1192
1193 void CacheStorageCache::PendingResponsesCallback(
1194 const ResponsesCallback& callback,
1195 CacheStorageError error,
1196 scoped_ptr<Responses> responses,
1197 scoped_ptr<BlobDataHandles> blob_data_handles) {
1198 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1199
1200 callback.Run(error, responses.Pass(), blob_data_handles.Pass());
1201 if (cache)
1202 scheduler_->CompleteOperationAndRunNext();
1203 }
1204
1070 void CacheStorageCache::PendingRequestsCallback( 1205 void CacheStorageCache::PendingRequestsCallback(
1071 const RequestsCallback& callback, 1206 const RequestsCallback& callback,
1072 CacheStorageError error, 1207 CacheStorageError error,
1073 scoped_ptr<Requests> requests) { 1208 scoped_ptr<Requests> requests) {
1074 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); 1209 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1075 1210
1076 callback.Run(error, requests.Pass()); 1211 callback.Run(error, requests.Pass());
1077 if (cache) 1212 if (cache)
1078 scheduler_->CompleteOperationAndRunNext(); 1213 scheduler_->CompleteOperationAndRunNext();
1079 } 1214 }
1080 1215
1216 void CacheStorageCache::PopulateResponseMetadata(
1217 const CacheMetadata& metadata,
1218 ServiceWorkerResponse* response) {
1219 *response = ServiceWorkerResponse(
1220 GURL(metadata.response().url()), metadata.response().status_code(),
1221 metadata.response().status_text(),
1222 ProtoResponseTypeToWebResponseType(metadata.response().response_type()),
1223 ServiceWorkerHeaderMap(), "", 0, GURL(),
1224 blink::WebServiceWorkerResponseErrorUnknown);
1225
1226 for (int i = 0; i < metadata.response().headers_size(); ++i) {
1227 const CacheHeaderMap header = metadata.response().headers(i);
1228 DCHECK_EQ(std::string::npos, header.name().find('\0'));
1229 DCHECK_EQ(std::string::npos, header.value().find('\0'));
1230 response->headers.insert(std::make_pair(header.name(), header.value()));
1231 }
1232 }
1233
1234 scoped_ptr<storage::BlobDataHandle> CacheStorageCache::PopulateResponseBody(
1235 disk_cache::ScopedEntryPtr entry,
1236 ServiceWorkerResponse* response) {
1237 DCHECK(blob_storage_context_);
1238
1239 // Create a blob with the response body data.
1240 response->blob_size = entry->GetDataSize(INDEX_RESPONSE_BODY);
1241 response->blob_uuid = base::GenerateGUID();
1242 storage::BlobDataBuilder blob_data(response->blob_uuid);
1243
1244 disk_cache::Entry* temp_entry = entry.get();
1245 blob_data.AppendDiskCacheEntry(
1246 new CacheStorageCacheDataHandle(this, entry.Pass()), temp_entry,
1247 INDEX_RESPONSE_BODY);
1248 return blob_storage_context_->AddFinishedBlob(&blob_data);
1249 }
1250
1081 } // namespace content 1251 } // 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