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 "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 | |
9 #include <string> | 8 #include <string> |
| 9 #include <utility> |
10 | 10 |
11 #include "base/barrier_closure.h" | 11 #include "base/barrier_closure.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/guid.h" | 13 #include "base/guid.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "content/browser/cache_storage/cache_storage.pb.h" | 18 #include "content/browser/cache_storage/cache_storage.pb.h" |
19 #include "content/browser/cache_storage/cache_storage_blob_to_disk_cache.h" | 19 #include "content/browser/cache_storage/cache_storage_blob_to_disk_cache.h" |
(...skipping 16 matching lines...) Expand all Loading... |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // This class ensures that the cache and the entry have a lifetime as long as | 39 // This class ensures that the cache and the entry have a lifetime as long as |
40 // the blob that is created to contain them. | 40 // the blob that is created to contain them. |
41 class CacheStorageCacheDataHandle | 41 class CacheStorageCacheDataHandle |
42 : public storage::BlobDataBuilder::DataHandle { | 42 : public storage::BlobDataBuilder::DataHandle { |
43 public: | 43 public: |
44 CacheStorageCacheDataHandle(const scoped_refptr<CacheStorageCache>& cache, | 44 CacheStorageCacheDataHandle(const scoped_refptr<CacheStorageCache>& cache, |
45 disk_cache::ScopedEntryPtr entry) | 45 disk_cache::ScopedEntryPtr entry) |
46 : cache_(cache), entry_(entry.Pass()) {} | 46 : cache_(cache), entry_(std::move(entry)) {} |
47 | 47 |
48 private: | 48 private: |
49 ~CacheStorageCacheDataHandle() override {} | 49 ~CacheStorageCacheDataHandle() override {} |
50 | 50 |
51 scoped_refptr<CacheStorageCache> cache_; | 51 scoped_refptr<CacheStorageCache> cache_; |
52 disk_cache::ScopedEntryPtr entry_; | 52 disk_cache::ScopedEntryPtr entry_; |
53 | 53 |
54 DISALLOW_COPY_AND_ASSIGN(CacheStorageCacheDataHandle); | 54 DISALLOW_COPY_AND_ASSIGN(CacheStorageCacheDataHandle); |
55 }; | 55 }; |
56 | 56 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 return; | 173 return; |
174 } | 174 } |
175 | 175 |
176 scoped_ptr<CacheMetadata> metadata(new CacheMetadata()); | 176 scoped_ptr<CacheMetadata> metadata(new CacheMetadata()); |
177 | 177 |
178 if (!metadata->ParseFromArray(buffer->data(), buffer->size())) { | 178 if (!metadata->ParseFromArray(buffer->data(), buffer->size())) { |
179 callback.Run(scoped_ptr<CacheMetadata>()); | 179 callback.Run(scoped_ptr<CacheMetadata>()); |
180 return; | 180 return; |
181 } | 181 } |
182 | 182 |
183 callback.Run(metadata.Pass()); | 183 callback.Run(std::move(metadata)); |
184 } | 184 } |
185 | 185 |
186 } // namespace | 186 } // namespace |
187 | 187 |
188 // The state needed to iterate all entries in the cache. | 188 // The state needed to iterate all entries in the cache. |
189 struct CacheStorageCache::OpenAllEntriesContext { | 189 struct CacheStorageCache::OpenAllEntriesContext { |
190 OpenAllEntriesContext() : enumerated_entry(nullptr) {} | 190 OpenAllEntriesContext() : enumerated_entry(nullptr) {} |
191 ~OpenAllEntriesContext() { | 191 ~OpenAllEntriesContext() { |
192 for (size_t i = 0, max = entries.size(); i < max; ++i) { | 192 for (size_t i = 0, max = entries.size(); i < max; ++i) { |
193 if (entries[i]) | 193 if (entries[i]) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 struct CacheStorageCache::PutContext { | 253 struct CacheStorageCache::PutContext { |
254 PutContext( | 254 PutContext( |
255 const GURL& origin, | 255 const GURL& origin, |
256 scoped_ptr<ServiceWorkerFetchRequest> request, | 256 scoped_ptr<ServiceWorkerFetchRequest> request, |
257 scoped_ptr<ServiceWorkerResponse> response, | 257 scoped_ptr<ServiceWorkerResponse> response, |
258 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 258 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
259 const CacheStorageCache::ErrorCallback& callback, | 259 const CacheStorageCache::ErrorCallback& callback, |
260 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 260 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
261 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy) | 261 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy) |
262 : origin(origin), | 262 : origin(origin), |
263 request(request.Pass()), | 263 request(std::move(request)), |
264 response(response.Pass()), | 264 response(std::move(response)), |
265 blob_data_handle(blob_data_handle.Pass()), | 265 blob_data_handle(std::move(blob_data_handle)), |
266 callback(callback), | 266 callback(callback), |
267 request_context_getter(request_context_getter), | 267 request_context_getter(request_context_getter), |
268 quota_manager_proxy(quota_manager_proxy) {} | 268 quota_manager_proxy(quota_manager_proxy) {} |
269 | 269 |
270 // Input parameters to the Put function. | 270 // Input parameters to the Put function. |
271 GURL origin; | 271 GURL origin; |
272 scoped_ptr<ServiceWorkerFetchRequest> request; | 272 scoped_ptr<ServiceWorkerFetchRequest> request; |
273 scoped_ptr<ServiceWorkerResponse> response; | 273 scoped_ptr<ServiceWorkerResponse> response; |
274 scoped_ptr<storage::BlobDataHandle> blob_data_handle; | 274 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
275 CacheStorageCache::ErrorCallback callback; | 275 CacheStorageCache::ErrorCallback callback; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 scoped_ptr<ServiceWorkerResponse>(), | 317 scoped_ptr<ServiceWorkerResponse>(), |
318 scoped_ptr<storage::BlobDataHandle>()); | 318 scoped_ptr<storage::BlobDataHandle>()); |
319 return; | 319 return; |
320 } | 320 } |
321 | 321 |
322 ResponseCallback pending_callback = | 322 ResponseCallback pending_callback = |
323 base::Bind(&CacheStorageCache::PendingResponseCallback, | 323 base::Bind(&CacheStorageCache::PendingResponseCallback, |
324 weak_ptr_factory_.GetWeakPtr(), callback); | 324 weak_ptr_factory_.GetWeakPtr(), callback); |
325 scheduler_->ScheduleOperation( | 325 scheduler_->ScheduleOperation( |
326 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), | 326 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), |
327 base::Passed(request.Pass()), pending_callback)); | 327 base::Passed(std::move(request)), pending_callback)); |
328 } | 328 } |
329 | 329 |
330 void CacheStorageCache::MatchAll(const ResponsesCallback& callback) { | 330 void CacheStorageCache::MatchAll(const ResponsesCallback& callback) { |
331 if (!LazyInitialize()) { | 331 if (!LazyInitialize()) { |
332 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), | 332 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), |
333 scoped_ptr<BlobDataHandles>()); | 333 scoped_ptr<BlobDataHandles>()); |
334 return; | 334 return; |
335 } | 335 } |
336 | 336 |
337 ResponsesCallback pending_callback = | 337 ResponsesCallback pending_callback = |
338 base::Bind(&CacheStorageCache::PendingResponsesCallback, | 338 base::Bind(&CacheStorageCache::PendingResponsesCallback, |
339 weak_ptr_factory_.GetWeakPtr(), callback); | 339 weak_ptr_factory_.GetWeakPtr(), callback); |
340 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, | 340 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, |
341 weak_ptr_factory_.GetWeakPtr(), | 341 weak_ptr_factory_.GetWeakPtr(), |
342 pending_callback)); | 342 pending_callback)); |
343 } | 343 } |
344 | 344 |
345 void CacheStorageCache::BatchOperation( | 345 void CacheStorageCache::BatchOperation( |
346 const std::vector<CacheStorageBatchOperation>& operations, | 346 const std::vector<CacheStorageBatchOperation>& operations, |
347 const ErrorCallback& callback) { | 347 const ErrorCallback& callback) { |
348 if (!LazyInitialize()) { | 348 if (!LazyInitialize()) { |
349 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 349 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
350 return; | 350 return; |
351 } | 351 } |
352 | 352 |
353 scoped_ptr<ErrorCallback> callback_copy(new ErrorCallback(callback)); | 353 scoped_ptr<ErrorCallback> callback_copy(new ErrorCallback(callback)); |
354 ErrorCallback* callback_ptr = callback_copy.get(); | 354 ErrorCallback* callback_ptr = callback_copy.get(); |
355 base::Closure barrier_closure = base::BarrierClosure( | 355 base::Closure barrier_closure = base::BarrierClosure( |
356 operations.size(), base::Bind(&CacheStorageCache::BatchDidAllOperations, | 356 operations.size(), |
357 this, base::Passed(callback_copy.Pass()))); | 357 base::Bind(&CacheStorageCache::BatchDidAllOperations, this, |
| 358 base::Passed(std::move(callback_copy)))); |
358 ErrorCallback completion_callback = | 359 ErrorCallback completion_callback = |
359 base::Bind(&CacheStorageCache::BatchDidOneOperation, this, | 360 base::Bind(&CacheStorageCache::BatchDidOneOperation, this, |
360 barrier_closure, callback_ptr); | 361 barrier_closure, callback_ptr); |
361 | 362 |
362 for (const auto& operation : operations) { | 363 for (const auto& operation : operations) { |
363 switch (operation.operation_type) { | 364 switch (operation.operation_type) { |
364 case CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT: | 365 case CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT: |
365 Put(operation, completion_callback); | 366 Put(operation, completion_callback); |
366 break; | 367 break; |
367 case CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE: | 368 case CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE: |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 } | 489 } |
489 | 490 |
490 void CacheStorageCache::OpenAllEntries(const OpenAllEntriesCallback& callback) { | 491 void CacheStorageCache::OpenAllEntries(const OpenAllEntriesCallback& callback) { |
491 scoped_ptr<OpenAllEntriesContext> entries_context(new OpenAllEntriesContext); | 492 scoped_ptr<OpenAllEntriesContext> entries_context(new OpenAllEntriesContext); |
492 entries_context->backend_iterator = backend_->CreateIterator(); | 493 entries_context->backend_iterator = backend_->CreateIterator(); |
493 disk_cache::Backend::Iterator& iterator = *entries_context->backend_iterator; | 494 disk_cache::Backend::Iterator& iterator = *entries_context->backend_iterator; |
494 disk_cache::Entry** enumerated_entry = &entries_context->enumerated_entry; | 495 disk_cache::Entry** enumerated_entry = &entries_context->enumerated_entry; |
495 | 496 |
496 net::CompletionCallback open_entry_callback = base::Bind( | 497 net::CompletionCallback open_entry_callback = base::Bind( |
497 &CacheStorageCache::DidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(), | 498 &CacheStorageCache::DidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(), |
498 base::Passed(entries_context.Pass()), callback); | 499 base::Passed(std::move(entries_context)), callback); |
499 | 500 |
500 int rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); | 501 int rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); |
501 | 502 |
502 if (rv != net::ERR_IO_PENDING) | 503 if (rv != net::ERR_IO_PENDING) |
503 open_entry_callback.Run(rv); | 504 open_entry_callback.Run(rv); |
504 } | 505 } |
505 | 506 |
506 void CacheStorageCache::DidOpenNextEntry( | 507 void CacheStorageCache::DidOpenNextEntry( |
507 scoped_ptr<OpenAllEntriesContext> entries_context, | 508 scoped_ptr<OpenAllEntriesContext> entries_context, |
508 const OpenAllEntriesCallback& callback, | 509 const OpenAllEntriesCallback& callback, |
509 int rv) { | 510 int rv) { |
510 if (rv == net::ERR_FAILED) { | 511 if (rv == net::ERR_FAILED) { |
511 DCHECK(!entries_context->enumerated_entry); | 512 DCHECK(!entries_context->enumerated_entry); |
512 // Enumeration is complete, extract the requests from the entries. | 513 // Enumeration is complete, extract the requests from the entries. |
513 callback.Run(entries_context.Pass(), CACHE_STORAGE_OK); | 514 callback.Run(std::move(entries_context), CACHE_STORAGE_OK); |
514 return; | 515 return; |
515 } | 516 } |
516 | 517 |
517 if (rv < 0) { | 518 if (rv < 0) { |
518 callback.Run(entries_context.Pass(), CACHE_STORAGE_ERROR_STORAGE); | 519 callback.Run(std::move(entries_context), CACHE_STORAGE_ERROR_STORAGE); |
519 return; | 520 return; |
520 } | 521 } |
521 | 522 |
522 if (backend_state_ != BACKEND_OPEN) { | 523 if (backend_state_ != BACKEND_OPEN) { |
523 callback.Run(entries_context.Pass(), CACHE_STORAGE_ERROR_NOT_FOUND); | 524 callback.Run(std::move(entries_context), CACHE_STORAGE_ERROR_NOT_FOUND); |
524 return; | 525 return; |
525 } | 526 } |
526 | 527 |
527 // Store the entry. | 528 // Store the entry. |
528 entries_context->entries.push_back(entries_context->enumerated_entry); | 529 entries_context->entries.push_back(entries_context->enumerated_entry); |
529 entries_context->enumerated_entry = nullptr; | 530 entries_context->enumerated_entry = nullptr; |
530 | 531 |
531 // Enumerate the next entry. | 532 // Enumerate the next entry. |
532 disk_cache::Backend::Iterator& iterator = *entries_context->backend_iterator; | 533 disk_cache::Backend::Iterator& iterator = *entries_context->backend_iterator; |
533 disk_cache::Entry** enumerated_entry = &entries_context->enumerated_entry; | 534 disk_cache::Entry** enumerated_entry = &entries_context->enumerated_entry; |
534 net::CompletionCallback open_entry_callback = base::Bind( | 535 net::CompletionCallback open_entry_callback = base::Bind( |
535 &CacheStorageCache::DidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(), | 536 &CacheStorageCache::DidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(), |
536 base::Passed(entries_context.Pass()), callback); | 537 base::Passed(std::move(entries_context)), callback); |
537 | 538 |
538 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); | 539 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); |
539 | 540 |
540 if (rv != net::ERR_IO_PENDING) | 541 if (rv != net::ERR_IO_PENDING) |
541 open_entry_callback.Run(rv); | 542 open_entry_callback.Run(rv); |
542 } | 543 } |
543 | 544 |
544 void CacheStorageCache::MatchImpl(scoped_ptr<ServiceWorkerFetchRequest> request, | 545 void CacheStorageCache::MatchImpl(scoped_ptr<ServiceWorkerFetchRequest> request, |
545 const ResponseCallback& callback) { | 546 const ResponseCallback& callback) { |
546 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 547 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
547 if (backend_state_ != BACKEND_OPEN) { | 548 if (backend_state_ != BACKEND_OPEN) { |
548 callback.Run(CACHE_STORAGE_ERROR_STORAGE, | 549 callback.Run(CACHE_STORAGE_ERROR_STORAGE, |
549 scoped_ptr<ServiceWorkerResponse>(), | 550 scoped_ptr<ServiceWorkerResponse>(), |
550 scoped_ptr<storage::BlobDataHandle>()); | 551 scoped_ptr<storage::BlobDataHandle>()); |
551 return; | 552 return; |
552 } | 553 } |
553 | 554 |
554 scoped_ptr<disk_cache::Entry*> scoped_entry_ptr(new disk_cache::Entry*()); | 555 scoped_ptr<disk_cache::Entry*> scoped_entry_ptr(new disk_cache::Entry*()); |
555 disk_cache::Entry** entry_ptr = scoped_entry_ptr.get(); | 556 disk_cache::Entry** entry_ptr = scoped_entry_ptr.get(); |
556 ServiceWorkerFetchRequest* request_ptr = request.get(); | 557 ServiceWorkerFetchRequest* request_ptr = request.get(); |
557 | 558 |
558 net::CompletionCallback open_entry_callback = | 559 net::CompletionCallback open_entry_callback = base::Bind( |
559 base::Bind(&CacheStorageCache::MatchDidOpenEntry, | 560 &CacheStorageCache::MatchDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), |
560 weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()), | 561 base::Passed(std::move(request)), callback, |
561 callback, base::Passed(scoped_entry_ptr.Pass())); | 562 base::Passed(std::move(scoped_entry_ptr))); |
562 | 563 |
563 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, | 564 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, |
564 open_entry_callback); | 565 open_entry_callback); |
565 if (rv != net::ERR_IO_PENDING) | 566 if (rv != net::ERR_IO_PENDING) |
566 open_entry_callback.Run(rv); | 567 open_entry_callback.Run(rv); |
567 } | 568 } |
568 | 569 |
569 void CacheStorageCache::MatchDidOpenEntry( | 570 void CacheStorageCache::MatchDidOpenEntry( |
570 scoped_ptr<ServiceWorkerFetchRequest> request, | 571 scoped_ptr<ServiceWorkerFetchRequest> request, |
571 const ResponseCallback& callback, | 572 const ResponseCallback& callback, |
572 scoped_ptr<disk_cache::Entry*> entry_ptr, | 573 scoped_ptr<disk_cache::Entry*> entry_ptr, |
573 int rv) { | 574 int rv) { |
574 if (rv != net::OK) { | 575 if (rv != net::OK) { |
575 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND, | 576 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND, |
576 scoped_ptr<ServiceWorkerResponse>(), | 577 scoped_ptr<ServiceWorkerResponse>(), |
577 scoped_ptr<storage::BlobDataHandle>()); | 578 scoped_ptr<storage::BlobDataHandle>()); |
578 return; | 579 return; |
579 } | 580 } |
580 disk_cache::ScopedEntryPtr entry(*entry_ptr); | 581 disk_cache::ScopedEntryPtr entry(*entry_ptr); |
581 | 582 |
582 MetadataCallback headers_callback = base::Bind( | 583 MetadataCallback headers_callback = base::Bind( |
583 &CacheStorageCache::MatchDidReadMetadata, weak_ptr_factory_.GetWeakPtr(), | 584 &CacheStorageCache::MatchDidReadMetadata, weak_ptr_factory_.GetWeakPtr(), |
584 base::Passed(request.Pass()), callback, base::Passed(entry.Pass())); | 585 base::Passed(std::move(request)), callback, |
| 586 base::Passed(std::move(entry))); |
585 | 587 |
586 ReadMetadata(*entry_ptr, headers_callback); | 588 ReadMetadata(*entry_ptr, headers_callback); |
587 } | 589 } |
588 | 590 |
589 void CacheStorageCache::MatchDidReadMetadata( | 591 void CacheStorageCache::MatchDidReadMetadata( |
590 scoped_ptr<ServiceWorkerFetchRequest> request, | 592 scoped_ptr<ServiceWorkerFetchRequest> request, |
591 const ResponseCallback& callback, | 593 const ResponseCallback& callback, |
592 disk_cache::ScopedEntryPtr entry, | 594 disk_cache::ScopedEntryPtr entry, |
593 scoped_ptr<CacheMetadata> metadata) { | 595 scoped_ptr<CacheMetadata> metadata) { |
594 if (!metadata) { | 596 if (!metadata) { |
(...skipping 16 matching lines...) Expand all Loading... |
611 | 613 |
612 if (!VaryMatches(request->headers, cached_request_headers, | 614 if (!VaryMatches(request->headers, cached_request_headers, |
613 response->headers)) { | 615 response->headers)) { |
614 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND, | 616 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND, |
615 scoped_ptr<ServiceWorkerResponse>(), | 617 scoped_ptr<ServiceWorkerResponse>(), |
616 scoped_ptr<storage::BlobDataHandle>()); | 618 scoped_ptr<storage::BlobDataHandle>()); |
617 return; | 619 return; |
618 } | 620 } |
619 | 621 |
620 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) { | 622 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) { |
621 callback.Run(CACHE_STORAGE_OK, response.Pass(), | 623 callback.Run(CACHE_STORAGE_OK, std::move(response), |
622 scoped_ptr<storage::BlobDataHandle>()); | 624 scoped_ptr<storage::BlobDataHandle>()); |
623 return; | 625 return; |
624 } | 626 } |
625 | 627 |
626 if (!blob_storage_context_) { | 628 if (!blob_storage_context_) { |
627 callback.Run(CACHE_STORAGE_ERROR_STORAGE, | 629 callback.Run(CACHE_STORAGE_ERROR_STORAGE, |
628 scoped_ptr<ServiceWorkerResponse>(), | 630 scoped_ptr<ServiceWorkerResponse>(), |
629 scoped_ptr<storage::BlobDataHandle>()); | 631 scoped_ptr<storage::BlobDataHandle>()); |
630 return; | 632 return; |
631 } | 633 } |
632 | 634 |
633 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 635 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
634 PopulateResponseBody(entry.Pass(), response.get()); | 636 PopulateResponseBody(std::move(entry), response.get()); |
635 callback.Run(CACHE_STORAGE_OK, response.Pass(), blob_data_handle.Pass()); | 637 callback.Run(CACHE_STORAGE_OK, std::move(response), |
| 638 std::move(blob_data_handle)); |
636 } | 639 } |
637 | 640 |
638 void CacheStorageCache::MatchAllImpl(const ResponsesCallback& callback) { | 641 void CacheStorageCache::MatchAllImpl(const ResponsesCallback& callback) { |
639 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 642 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
640 if (backend_state_ != BACKEND_OPEN) { | 643 if (backend_state_ != BACKEND_OPEN) { |
641 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), | 644 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), |
642 scoped_ptr<BlobDataHandles>()); | 645 scoped_ptr<BlobDataHandles>()); |
643 return; | 646 return; |
644 } | 647 } |
645 | 648 |
646 OpenAllEntries(base::Bind(&CacheStorageCache::MatchAllDidOpenAllEntries, | 649 OpenAllEntries(base::Bind(&CacheStorageCache::MatchAllDidOpenAllEntries, |
647 weak_ptr_factory_.GetWeakPtr(), callback)); | 650 weak_ptr_factory_.GetWeakPtr(), callback)); |
648 } | 651 } |
649 | 652 |
650 void CacheStorageCache::MatchAllDidOpenAllEntries( | 653 void CacheStorageCache::MatchAllDidOpenAllEntries( |
651 const ResponsesCallback& callback, | 654 const ResponsesCallback& callback, |
652 scoped_ptr<OpenAllEntriesContext> entries_context, | 655 scoped_ptr<OpenAllEntriesContext> entries_context, |
653 CacheStorageError error) { | 656 CacheStorageError error) { |
654 if (error != CACHE_STORAGE_OK) { | 657 if (error != CACHE_STORAGE_OK) { |
655 callback.Run(error, scoped_ptr<Responses>(), scoped_ptr<BlobDataHandles>()); | 658 callback.Run(error, scoped_ptr<Responses>(), scoped_ptr<BlobDataHandles>()); |
656 return; | 659 return; |
657 } | 660 } |
658 | 661 |
659 scoped_ptr<MatchAllContext> context(new MatchAllContext(callback)); | 662 scoped_ptr<MatchAllContext> context(new MatchAllContext(callback)); |
660 context->entries_context.swap(entries_context); | 663 context->entries_context.swap(entries_context); |
661 Entries::iterator iter = context->entries_context->entries.begin(); | 664 Entries::iterator iter = context->entries_context->entries.begin(); |
662 MatchAllProcessNextEntry(context.Pass(), iter); | 665 MatchAllProcessNextEntry(std::move(context), iter); |
663 } | 666 } |
664 | 667 |
665 void CacheStorageCache::MatchAllProcessNextEntry( | 668 void CacheStorageCache::MatchAllProcessNextEntry( |
666 scoped_ptr<MatchAllContext> context, | 669 scoped_ptr<MatchAllContext> context, |
667 const Entries::iterator& iter) { | 670 const Entries::iterator& iter) { |
668 if (iter == context->entries_context->entries.end()) { | 671 if (iter == context->entries_context->entries.end()) { |
669 // All done. Return all of the responses. | 672 // All done. Return all of the responses. |
670 context->original_callback.Run(CACHE_STORAGE_OK, | 673 context->original_callback.Run(CACHE_STORAGE_OK, |
671 context->out_responses.Pass(), | 674 std::move(context->out_responses), |
672 context->out_blob_data_handles.Pass()); | 675 std::move(context->out_blob_data_handles)); |
673 return; | 676 return; |
674 } | 677 } |
675 | 678 |
676 ReadMetadata(*iter, base::Bind(&CacheStorageCache::MatchAllDidReadMetadata, | 679 ReadMetadata(*iter, base::Bind(&CacheStorageCache::MatchAllDidReadMetadata, |
677 weak_ptr_factory_.GetWeakPtr(), | 680 weak_ptr_factory_.GetWeakPtr(), |
678 base::Passed(context.Pass()), iter)); | 681 base::Passed(std::move(context)), iter)); |
679 } | 682 } |
680 | 683 |
681 void CacheStorageCache::MatchAllDidReadMetadata( | 684 void CacheStorageCache::MatchAllDidReadMetadata( |
682 scoped_ptr<MatchAllContext> context, | 685 scoped_ptr<MatchAllContext> context, |
683 const Entries::iterator& iter, | 686 const Entries::iterator& iter, |
684 scoped_ptr<CacheMetadata> metadata) { | 687 scoped_ptr<CacheMetadata> metadata) { |
685 // Move ownership of the entry from the context. | 688 // Move ownership of the entry from the context. |
686 disk_cache::ScopedEntryPtr entry(*iter); | 689 disk_cache::ScopedEntryPtr entry(*iter); |
687 *iter = nullptr; | 690 *iter = nullptr; |
688 | 691 |
689 if (!metadata) { | 692 if (!metadata) { |
690 entry->Doom(); | 693 entry->Doom(); |
691 MatchAllProcessNextEntry(context.Pass(), iter + 1); | 694 MatchAllProcessNextEntry(std::move(context), iter + 1); |
692 return; | 695 return; |
693 } | 696 } |
694 | 697 |
695 ServiceWorkerResponse response; | 698 ServiceWorkerResponse response; |
696 PopulateResponseMetadata(*metadata, &response); | 699 PopulateResponseMetadata(*metadata, &response); |
697 | 700 |
698 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) { | 701 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) { |
699 context->out_responses->push_back(response); | 702 context->out_responses->push_back(response); |
700 MatchAllProcessNextEntry(context.Pass(), iter + 1); | 703 MatchAllProcessNextEntry(std::move(context), iter + 1); |
701 return; | 704 return; |
702 } | 705 } |
703 | 706 |
704 if (!blob_storage_context_) { | 707 if (!blob_storage_context_) { |
705 context->original_callback.Run(CACHE_STORAGE_ERROR_STORAGE, | 708 context->original_callback.Run(CACHE_STORAGE_ERROR_STORAGE, |
706 scoped_ptr<Responses>(), | 709 scoped_ptr<Responses>(), |
707 scoped_ptr<BlobDataHandles>()); | 710 scoped_ptr<BlobDataHandles>()); |
708 return; | 711 return; |
709 } | 712 } |
710 | 713 |
711 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 714 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
712 PopulateResponseBody(entry.Pass(), &response); | 715 PopulateResponseBody(std::move(entry), &response); |
713 | 716 |
714 context->out_responses->push_back(response); | 717 context->out_responses->push_back(response); |
715 context->out_blob_data_handles->push_back(*blob_data_handle); | 718 context->out_blob_data_handles->push_back(*blob_data_handle); |
716 MatchAllProcessNextEntry(context.Pass(), iter + 1); | 719 MatchAllProcessNextEntry(std::move(context), iter + 1); |
717 } | 720 } |
718 | 721 |
719 void CacheStorageCache::Put(const CacheStorageBatchOperation& operation, | 722 void CacheStorageCache::Put(const CacheStorageBatchOperation& operation, |
720 const ErrorCallback& callback) { | 723 const ErrorCallback& callback) { |
721 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); | 724 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); |
722 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT, operation.operation_type); | 725 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT, operation.operation_type); |
723 | 726 |
724 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( | 727 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( |
725 operation.request.url, operation.request.method, | 728 operation.request.url, operation.request.method, |
726 operation.request.headers, operation.request.referrer, | 729 operation.request.headers, operation.request.referrer, |
(...skipping 24 matching lines...) Expand all Loading... |
751 if (!blob_data_handle) { | 754 if (!blob_data_handle) { |
752 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 755 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
753 return; | 756 return; |
754 } | 757 } |
755 } | 758 } |
756 | 759 |
757 ErrorCallback pending_callback = | 760 ErrorCallback pending_callback = |
758 base::Bind(&CacheStorageCache::PendingErrorCallback, | 761 base::Bind(&CacheStorageCache::PendingErrorCallback, |
759 weak_ptr_factory_.GetWeakPtr(), callback); | 762 weak_ptr_factory_.GetWeakPtr(), callback); |
760 | 763 |
761 scoped_ptr<PutContext> put_context(new PutContext( | 764 scoped_ptr<PutContext> put_context( |
762 origin_, request.Pass(), response.Pass(), blob_data_handle.Pass(), | 765 new PutContext(origin_, std::move(request), std::move(response), |
763 pending_callback, request_context_getter_, quota_manager_proxy_)); | 766 std::move(blob_data_handle), pending_callback, |
| 767 request_context_getter_, quota_manager_proxy_)); |
764 | 768 |
765 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::PutImpl, | 769 scheduler_->ScheduleOperation( |
766 weak_ptr_factory_.GetWeakPtr(), | 770 base::Bind(&CacheStorageCache::PutImpl, weak_ptr_factory_.GetWeakPtr(), |
767 base::Passed(put_context.Pass()))); | 771 base::Passed(std::move(put_context)))); |
768 } | 772 } |
769 | 773 |
770 void CacheStorageCache::PutImpl(scoped_ptr<PutContext> put_context) { | 774 void CacheStorageCache::PutImpl(scoped_ptr<PutContext> put_context) { |
771 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 775 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
772 if (backend_state_ != BACKEND_OPEN) { | 776 if (backend_state_ != BACKEND_OPEN) { |
773 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 777 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
774 return; | 778 return; |
775 } | 779 } |
776 | 780 |
777 scoped_ptr<ServiceWorkerFetchRequest> request_copy( | 781 scoped_ptr<ServiceWorkerFetchRequest> request_copy( |
778 new ServiceWorkerFetchRequest(*put_context->request)); | 782 new ServiceWorkerFetchRequest(*put_context->request)); |
779 | 783 |
780 DeleteImpl(request_copy.Pass(), base::Bind(&CacheStorageCache::PutDidDelete, | 784 DeleteImpl(std::move(request_copy), |
781 weak_ptr_factory_.GetWeakPtr(), | 785 base::Bind(&CacheStorageCache::PutDidDelete, |
782 base::Passed(put_context.Pass()))); | 786 weak_ptr_factory_.GetWeakPtr(), |
| 787 base::Passed(std::move(put_context)))); |
783 } | 788 } |
784 | 789 |
785 void CacheStorageCache::PutDidDelete(scoped_ptr<PutContext> put_context, | 790 void CacheStorageCache::PutDidDelete(scoped_ptr<PutContext> put_context, |
786 CacheStorageError delete_error) { | 791 CacheStorageError delete_error) { |
787 if (backend_state_ != BACKEND_OPEN) { | 792 if (backend_state_ != BACKEND_OPEN) { |
788 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 793 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
789 return; | 794 return; |
790 } | 795 } |
791 | 796 |
792 scoped_ptr<disk_cache::Entry*> scoped_entry_ptr(new disk_cache::Entry*()); | 797 scoped_ptr<disk_cache::Entry*> scoped_entry_ptr(new disk_cache::Entry*()); |
793 disk_cache::Entry** entry_ptr = scoped_entry_ptr.get(); | 798 disk_cache::Entry** entry_ptr = scoped_entry_ptr.get(); |
794 ServiceWorkerFetchRequest* request_ptr = put_context->request.get(); | 799 ServiceWorkerFetchRequest* request_ptr = put_context->request.get(); |
795 disk_cache::Backend* backend_ptr = backend_.get(); | 800 disk_cache::Backend* backend_ptr = backend_.get(); |
796 | 801 |
797 net::CompletionCallback create_entry_callback = base::Bind( | 802 net::CompletionCallback create_entry_callback = base::Bind( |
798 &CacheStorageCache::PutDidCreateEntry, weak_ptr_factory_.GetWeakPtr(), | 803 &CacheStorageCache::PutDidCreateEntry, weak_ptr_factory_.GetWeakPtr(), |
799 base::Passed(scoped_entry_ptr.Pass()), base::Passed(put_context.Pass())); | 804 base::Passed(std::move(scoped_entry_ptr)), |
| 805 base::Passed(std::move(put_context))); |
800 | 806 |
801 int create_rv = backend_ptr->CreateEntry(request_ptr->url.spec(), entry_ptr, | 807 int create_rv = backend_ptr->CreateEntry(request_ptr->url.spec(), entry_ptr, |
802 create_entry_callback); | 808 create_entry_callback); |
803 | 809 |
804 if (create_rv != net::ERR_IO_PENDING) | 810 if (create_rv != net::ERR_IO_PENDING) |
805 create_entry_callback.Run(create_rv); | 811 create_entry_callback.Run(create_rv); |
806 } | 812 } |
807 | 813 |
808 void CacheStorageCache::PutDidCreateEntry( | 814 void CacheStorageCache::PutDidCreateEntry( |
809 scoped_ptr<disk_cache::Entry*> entry_ptr, | 815 scoped_ptr<disk_cache::Entry*> entry_ptr, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 header_map->set_value(it->second); | 850 header_map->set_value(it->second); |
845 } | 851 } |
846 | 852 |
847 scoped_ptr<std::string> serialized(new std::string()); | 853 scoped_ptr<std::string> serialized(new std::string()); |
848 if (!metadata.SerializeToString(serialized.get())) { | 854 if (!metadata.SerializeToString(serialized.get())) { |
849 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 855 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
850 return; | 856 return; |
851 } | 857 } |
852 | 858 |
853 scoped_refptr<net::StringIOBuffer> buffer( | 859 scoped_refptr<net::StringIOBuffer> buffer( |
854 new net::StringIOBuffer(serialized.Pass())); | 860 new net::StringIOBuffer(std::move(serialized))); |
855 | 861 |
856 // Get a temporary copy of the entry pointer before passing it in base::Bind. | 862 // Get a temporary copy of the entry pointer before passing it in base::Bind. |
857 disk_cache::Entry* temp_entry_ptr = put_context->cache_entry.get(); | 863 disk_cache::Entry* temp_entry_ptr = put_context->cache_entry.get(); |
858 | 864 |
859 net::CompletionCallback write_headers_callback = base::Bind( | 865 net::CompletionCallback write_headers_callback = base::Bind( |
860 &CacheStorageCache::PutDidWriteHeaders, weak_ptr_factory_.GetWeakPtr(), | 866 &CacheStorageCache::PutDidWriteHeaders, weak_ptr_factory_.GetWeakPtr(), |
861 base::Passed(put_context.Pass()), buffer->size()); | 867 base::Passed(std::move(put_context)), buffer->size()); |
862 | 868 |
863 rv = temp_entry_ptr->WriteData(INDEX_HEADERS, 0 /* offset */, buffer.get(), | 869 rv = temp_entry_ptr->WriteData(INDEX_HEADERS, 0 /* offset */, buffer.get(), |
864 buffer->size(), write_headers_callback, | 870 buffer->size(), write_headers_callback, |
865 true /* truncate */); | 871 true /* truncate */); |
866 | 872 |
867 if (rv != net::ERR_IO_PENDING) | 873 if (rv != net::ERR_IO_PENDING) |
868 write_headers_callback.Run(rv); | 874 write_headers_callback.Run(rv); |
869 } | 875 } |
870 | 876 |
871 void CacheStorageCache::PutDidWriteHeaders(scoped_ptr<PutContext> put_context, | 877 void CacheStorageCache::PutDidWriteHeaders(scoped_ptr<PutContext> put_context, |
(...skipping 15 matching lines...) Expand all Loading... |
887 storage::kStorageTypeTemporary, | 893 storage::kStorageTypeTemporary, |
888 put_context->cache_entry->GetDataSize(INDEX_HEADERS)); | 894 put_context->cache_entry->GetDataSize(INDEX_HEADERS)); |
889 } | 895 } |
890 | 896 |
891 put_context->callback.Run(CACHE_STORAGE_OK); | 897 put_context->callback.Run(CACHE_STORAGE_OK); |
892 return; | 898 return; |
893 } | 899 } |
894 | 900 |
895 DCHECK(put_context->blob_data_handle); | 901 DCHECK(put_context->blob_data_handle); |
896 | 902 |
897 disk_cache::ScopedEntryPtr entry(put_context->cache_entry.Pass()); | 903 disk_cache::ScopedEntryPtr entry(std::move(put_context->cache_entry)); |
898 put_context->cache_entry = NULL; | 904 put_context->cache_entry = NULL; |
899 | 905 |
900 CacheStorageBlobToDiskCache* blob_to_cache = | 906 CacheStorageBlobToDiskCache* blob_to_cache = |
901 new CacheStorageBlobToDiskCache(); | 907 new CacheStorageBlobToDiskCache(); |
902 BlobToDiskCacheIDMap::KeyType blob_to_cache_key = | 908 BlobToDiskCacheIDMap::KeyType blob_to_cache_key = |
903 active_blob_to_disk_cache_writers_.Add(blob_to_cache); | 909 active_blob_to_disk_cache_writers_.Add(blob_to_cache); |
904 | 910 |
905 // Grab some pointers before passing put_context in Bind. | 911 // Grab some pointers before passing put_context in Bind. |
906 scoped_refptr<net::URLRequestContextGetter> request_context_getter = | 912 scoped_refptr<net::URLRequestContextGetter> request_context_getter = |
907 put_context->request_context_getter; | 913 put_context->request_context_getter; |
908 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 914 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
909 put_context->blob_data_handle.Pass(); | 915 std::move(put_context->blob_data_handle); |
910 | 916 |
911 blob_to_cache->StreamBlobToCache( | 917 blob_to_cache->StreamBlobToCache( |
912 entry.Pass(), INDEX_RESPONSE_BODY, request_context_getter, | 918 std::move(entry), INDEX_RESPONSE_BODY, request_context_getter, |
913 blob_data_handle.Pass(), | 919 std::move(blob_data_handle), |
914 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache, | 920 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache, |
915 weak_ptr_factory_.GetWeakPtr(), | 921 weak_ptr_factory_.GetWeakPtr(), |
916 base::Passed(put_context.Pass()), blob_to_cache_key)); | 922 base::Passed(std::move(put_context)), blob_to_cache_key)); |
917 } | 923 } |
918 | 924 |
919 void CacheStorageCache::PutDidWriteBlobToCache( | 925 void CacheStorageCache::PutDidWriteBlobToCache( |
920 scoped_ptr<PutContext> put_context, | 926 scoped_ptr<PutContext> put_context, |
921 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, | 927 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, |
922 disk_cache::ScopedEntryPtr entry, | 928 disk_cache::ScopedEntryPtr entry, |
923 bool success) { | 929 bool success) { |
924 DCHECK(entry); | 930 DCHECK(entry); |
925 put_context->cache_entry = entry.Pass(); | 931 put_context->cache_entry = std::move(entry); |
926 | 932 |
927 active_blob_to_disk_cache_writers_.Remove(blob_to_cache_key); | 933 active_blob_to_disk_cache_writers_.Remove(blob_to_cache_key); |
928 | 934 |
929 if (!success) { | 935 if (!success) { |
930 put_context->cache_entry->Doom(); | 936 put_context->cache_entry->Doom(); |
931 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 937 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
932 return; | 938 return; |
933 } | 939 } |
934 | 940 |
935 if (put_context->quota_manager_proxy.get()) { | 941 if (put_context->quota_manager_proxy.get()) { |
(...skipping 16 matching lines...) Expand all Loading... |
952 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( | 958 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( |
953 operation.request.url, operation.request.method, | 959 operation.request.url, operation.request.method, |
954 operation.request.headers, operation.request.referrer, | 960 operation.request.headers, operation.request.referrer, |
955 operation.request.is_reload)); | 961 operation.request.is_reload)); |
956 | 962 |
957 ErrorCallback pending_callback = | 963 ErrorCallback pending_callback = |
958 base::Bind(&CacheStorageCache::PendingErrorCallback, | 964 base::Bind(&CacheStorageCache::PendingErrorCallback, |
959 weak_ptr_factory_.GetWeakPtr(), callback); | 965 weak_ptr_factory_.GetWeakPtr(), callback); |
960 scheduler_->ScheduleOperation( | 966 scheduler_->ScheduleOperation( |
961 base::Bind(&CacheStorageCache::DeleteImpl, weak_ptr_factory_.GetWeakPtr(), | 967 base::Bind(&CacheStorageCache::DeleteImpl, weak_ptr_factory_.GetWeakPtr(), |
962 base::Passed(request.Pass()), pending_callback)); | 968 base::Passed(std::move(request)), pending_callback)); |
963 } | 969 } |
964 | 970 |
965 void CacheStorageCache::DeleteImpl( | 971 void CacheStorageCache::DeleteImpl( |
966 scoped_ptr<ServiceWorkerFetchRequest> request, | 972 scoped_ptr<ServiceWorkerFetchRequest> request, |
967 const ErrorCallback& callback) { | 973 const ErrorCallback& callback) { |
968 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 974 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
969 if (backend_state_ != BACKEND_OPEN) { | 975 if (backend_state_ != BACKEND_OPEN) { |
970 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 976 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
971 return; | 977 return; |
972 } | 978 } |
973 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 979 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); |
974 | 980 |
975 disk_cache::Entry** entry_ptr = entry.get(); | 981 disk_cache::Entry** entry_ptr = entry.get(); |
976 | 982 |
977 ServiceWorkerFetchRequest* request_ptr = request.get(); | 983 ServiceWorkerFetchRequest* request_ptr = request.get(); |
978 | 984 |
979 net::CompletionCallback open_entry_callback = base::Bind( | 985 net::CompletionCallback open_entry_callback = base::Bind( |
980 &CacheStorageCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), | 986 &CacheStorageCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), |
981 origin_, base::Passed(request.Pass()), callback, | 987 origin_, base::Passed(std::move(request)), callback, |
982 base::Passed(entry.Pass()), quota_manager_proxy_); | 988 base::Passed(std::move(entry)), quota_manager_proxy_); |
983 | 989 |
984 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, | 990 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, |
985 open_entry_callback); | 991 open_entry_callback); |
986 if (rv != net::ERR_IO_PENDING) | 992 if (rv != net::ERR_IO_PENDING) |
987 open_entry_callback.Run(rv); | 993 open_entry_callback.Run(rv); |
988 } | 994 } |
989 | 995 |
990 void CacheStorageCache::DeleteDidOpenEntry( | 996 void CacheStorageCache::DeleteDidOpenEntry( |
991 const GURL& origin, | 997 const GURL& origin, |
992 scoped_ptr<ServiceWorkerFetchRequest> request, | 998 scoped_ptr<ServiceWorkerFetchRequest> request, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 scoped_ptr<OpenAllEntriesContext> entries_context, | 1046 scoped_ptr<OpenAllEntriesContext> entries_context, |
1041 CacheStorageError error) { | 1047 CacheStorageError error) { |
1042 if (error != CACHE_STORAGE_OK) { | 1048 if (error != CACHE_STORAGE_OK) { |
1043 callback.Run(error, scoped_ptr<Requests>()); | 1049 callback.Run(error, scoped_ptr<Requests>()); |
1044 return; | 1050 return; |
1045 } | 1051 } |
1046 | 1052 |
1047 scoped_ptr<KeysContext> keys_context(new KeysContext(callback)); | 1053 scoped_ptr<KeysContext> keys_context(new KeysContext(callback)); |
1048 keys_context->entries_context.swap(entries_context); | 1054 keys_context->entries_context.swap(entries_context); |
1049 Entries::iterator iter = keys_context->entries_context->entries.begin(); | 1055 Entries::iterator iter = keys_context->entries_context->entries.begin(); |
1050 KeysProcessNextEntry(keys_context.Pass(), iter); | 1056 KeysProcessNextEntry(std::move(keys_context), iter); |
1051 } | 1057 } |
1052 | 1058 |
1053 void CacheStorageCache::KeysProcessNextEntry( | 1059 void CacheStorageCache::KeysProcessNextEntry( |
1054 scoped_ptr<KeysContext> keys_context, | 1060 scoped_ptr<KeysContext> keys_context, |
1055 const Entries::iterator& iter) { | 1061 const Entries::iterator& iter) { |
1056 if (iter == keys_context->entries_context->entries.end()) { | 1062 if (iter == keys_context->entries_context->entries.end()) { |
1057 // All done. Return all of the keys. | 1063 // All done. Return all of the keys. |
1058 keys_context->original_callback.Run(CACHE_STORAGE_OK, | 1064 keys_context->original_callback.Run(CACHE_STORAGE_OK, |
1059 keys_context->out_keys.Pass()); | 1065 std::move(keys_context->out_keys)); |
1060 return; | 1066 return; |
1061 } | 1067 } |
1062 | 1068 |
1063 ReadMetadata(*iter, base::Bind(&CacheStorageCache::KeysDidReadMetadata, | 1069 ReadMetadata(*iter, base::Bind(&CacheStorageCache::KeysDidReadMetadata, |
1064 weak_ptr_factory_.GetWeakPtr(), | 1070 weak_ptr_factory_.GetWeakPtr(), |
1065 base::Passed(keys_context.Pass()), iter)); | 1071 base::Passed(std::move(keys_context)), iter)); |
1066 } | 1072 } |
1067 | 1073 |
1068 void CacheStorageCache::KeysDidReadMetadata( | 1074 void CacheStorageCache::KeysDidReadMetadata( |
1069 scoped_ptr<KeysContext> keys_context, | 1075 scoped_ptr<KeysContext> keys_context, |
1070 const Entries::iterator& iter, | 1076 const Entries::iterator& iter, |
1071 scoped_ptr<CacheMetadata> metadata) { | 1077 scoped_ptr<CacheMetadata> metadata) { |
1072 disk_cache::Entry* entry = *iter; | 1078 disk_cache::Entry* entry = *iter; |
1073 | 1079 |
1074 if (metadata) { | 1080 if (metadata) { |
1075 keys_context->out_keys->push_back(ServiceWorkerFetchRequest( | 1081 keys_context->out_keys->push_back(ServiceWorkerFetchRequest( |
1076 GURL(entry->GetKey()), metadata->request().method(), | 1082 GURL(entry->GetKey()), metadata->request().method(), |
1077 ServiceWorkerHeaderMap(), Referrer(), false)); | 1083 ServiceWorkerHeaderMap(), Referrer(), false)); |
1078 | 1084 |
1079 ServiceWorkerHeaderMap& req_headers = | 1085 ServiceWorkerHeaderMap& req_headers = |
1080 keys_context->out_keys->back().headers; | 1086 keys_context->out_keys->back().headers; |
1081 | 1087 |
1082 for (int i = 0; i < metadata->request().headers_size(); ++i) { | 1088 for (int i = 0; i < metadata->request().headers_size(); ++i) { |
1083 const CacheHeaderMap header = metadata->request().headers(i); | 1089 const CacheHeaderMap header = metadata->request().headers(i); |
1084 DCHECK_EQ(std::string::npos, header.name().find('\0')); | 1090 DCHECK_EQ(std::string::npos, header.name().find('\0')); |
1085 DCHECK_EQ(std::string::npos, header.value().find('\0')); | 1091 DCHECK_EQ(std::string::npos, header.value().find('\0')); |
1086 req_headers.insert(std::make_pair(header.name(), header.value())); | 1092 req_headers.insert(std::make_pair(header.name(), header.value())); |
1087 } | 1093 } |
1088 } else { | 1094 } else { |
1089 entry->Doom(); | 1095 entry->Doom(); |
1090 } | 1096 } |
1091 | 1097 |
1092 KeysProcessNextEntry(keys_context.Pass(), iter + 1); | 1098 KeysProcessNextEntry(std::move(keys_context), iter + 1); |
1093 } | 1099 } |
1094 | 1100 |
1095 void CacheStorageCache::CloseImpl(const base::Closure& callback) { | 1101 void CacheStorageCache::CloseImpl(const base::Closure& callback) { |
1096 DCHECK_NE(BACKEND_CLOSED, backend_state_); | 1102 DCHECK_NE(BACKEND_CLOSED, backend_state_); |
1097 | 1103 |
1098 backend_state_ = BACKEND_CLOSED; | 1104 backend_state_ = BACKEND_CLOSED; |
1099 backend_.reset(); | 1105 backend_.reset(); |
1100 callback.Run(); | 1106 callback.Run(); |
1101 } | 1107 } |
1102 | 1108 |
1103 void CacheStorageCache::CreateBackend(const ErrorCallback& callback) { | 1109 void CacheStorageCache::CreateBackend(const ErrorCallback& callback) { |
1104 DCHECK(!backend_); | 1110 DCHECK(!backend_); |
1105 | 1111 |
1106 // Use APP_CACHE as opposed to DISK_CACHE to prevent cache eviction. | 1112 // Use APP_CACHE as opposed to DISK_CACHE to prevent cache eviction. |
1107 net::CacheType cache_type = memory_only_ ? net::MEMORY_CACHE : net::APP_CACHE; | 1113 net::CacheType cache_type = memory_only_ ? net::MEMORY_CACHE : net::APP_CACHE; |
1108 | 1114 |
1109 scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr()); | 1115 scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr()); |
1110 | 1116 |
1111 // Temporary pointer so that backend_ptr can be Pass()'d in Bind below. | 1117 // Temporary pointer so that backend_ptr can be Pass()'d in Bind below. |
1112 ScopedBackendPtr* backend = backend_ptr.get(); | 1118 ScopedBackendPtr* backend = backend_ptr.get(); |
1113 | 1119 |
1114 net::CompletionCallback create_cache_callback = | 1120 net::CompletionCallback create_cache_callback = |
1115 base::Bind(&CacheStorageCache::CreateBackendDidCreate, | 1121 base::Bind(&CacheStorageCache::CreateBackendDidCreate, |
1116 weak_ptr_factory_.GetWeakPtr(), callback, | 1122 weak_ptr_factory_.GetWeakPtr(), callback, |
1117 base::Passed(backend_ptr.Pass())); | 1123 base::Passed(std::move(backend_ptr))); |
1118 | 1124 |
1119 // TODO(jkarlin): Use the cache task runner that ServiceWorkerCacheCore | 1125 // TODO(jkarlin): Use the cache task runner that ServiceWorkerCacheCore |
1120 // has for disk caches. | 1126 // has for disk caches. |
1121 int rv = disk_cache::CreateCacheBackend( | 1127 int rv = disk_cache::CreateCacheBackend( |
1122 cache_type, net::CACHE_BACKEND_SIMPLE, path_, kMaxCacheBytes, | 1128 cache_type, net::CACHE_BACKEND_SIMPLE, path_, kMaxCacheBytes, |
1123 false, /* force */ | 1129 false, /* force */ |
1124 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), | 1130 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), |
1125 NULL, backend, create_cache_callback); | 1131 NULL, backend, create_cache_callback); |
1126 if (rv != net::ERR_IO_PENDING) | 1132 if (rv != net::ERR_IO_PENDING) |
1127 create_cache_callback.Run(rv); | 1133 create_cache_callback.Run(rv); |
1128 } | 1134 } |
1129 | 1135 |
1130 void CacheStorageCache::CreateBackendDidCreate( | 1136 void CacheStorageCache::CreateBackendDidCreate( |
1131 const CacheStorageCache::ErrorCallback& callback, | 1137 const CacheStorageCache::ErrorCallback& callback, |
1132 scoped_ptr<ScopedBackendPtr> backend_ptr, | 1138 scoped_ptr<ScopedBackendPtr> backend_ptr, |
1133 int rv) { | 1139 int rv) { |
1134 if (rv != net::OK) { | 1140 if (rv != net::OK) { |
1135 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 1141 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
1136 return; | 1142 return; |
1137 } | 1143 } |
1138 | 1144 |
1139 backend_ = backend_ptr->Pass(); | 1145 backend_ = std::move(*backend_ptr); |
1140 callback.Run(CACHE_STORAGE_OK); | 1146 callback.Run(CACHE_STORAGE_OK); |
1141 } | 1147 } |
1142 | 1148 |
1143 void CacheStorageCache::InitBackend() { | 1149 void CacheStorageCache::InitBackend() { |
1144 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_); | 1150 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_); |
1145 | 1151 |
1146 if (initializing_) | 1152 if (initializing_) |
1147 return; | 1153 return; |
1148 | 1154 |
1149 DCHECK(!scheduler_->ScheduledOperations()); | 1155 DCHECK(!scheduler_->ScheduledOperations()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 scheduler_->CompleteOperationAndRunNext(); | 1191 scheduler_->CompleteOperationAndRunNext(); |
1186 } | 1192 } |
1187 | 1193 |
1188 void CacheStorageCache::PendingResponseCallback( | 1194 void CacheStorageCache::PendingResponseCallback( |
1189 const ResponseCallback& callback, | 1195 const ResponseCallback& callback, |
1190 CacheStorageError error, | 1196 CacheStorageError error, |
1191 scoped_ptr<ServiceWorkerResponse> response, | 1197 scoped_ptr<ServiceWorkerResponse> response, |
1192 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 1198 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
1193 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | 1199 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); |
1194 | 1200 |
1195 callback.Run(error, response.Pass(), blob_data_handle.Pass()); | 1201 callback.Run(error, std::move(response), std::move(blob_data_handle)); |
1196 if (cache) | 1202 if (cache) |
1197 scheduler_->CompleteOperationAndRunNext(); | 1203 scheduler_->CompleteOperationAndRunNext(); |
1198 } | 1204 } |
1199 | 1205 |
1200 void CacheStorageCache::PendingResponsesCallback( | 1206 void CacheStorageCache::PendingResponsesCallback( |
1201 const ResponsesCallback& callback, | 1207 const ResponsesCallback& callback, |
1202 CacheStorageError error, | 1208 CacheStorageError error, |
1203 scoped_ptr<Responses> responses, | 1209 scoped_ptr<Responses> responses, |
1204 scoped_ptr<BlobDataHandles> blob_data_handles) { | 1210 scoped_ptr<BlobDataHandles> blob_data_handles) { |
1205 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | 1211 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); |
1206 | 1212 |
1207 callback.Run(error, responses.Pass(), blob_data_handles.Pass()); | 1213 callback.Run(error, std::move(responses), std::move(blob_data_handles)); |
1208 if (cache) | 1214 if (cache) |
1209 scheduler_->CompleteOperationAndRunNext(); | 1215 scheduler_->CompleteOperationAndRunNext(); |
1210 } | 1216 } |
1211 | 1217 |
1212 void CacheStorageCache::PendingRequestsCallback( | 1218 void CacheStorageCache::PendingRequestsCallback( |
1213 const RequestsCallback& callback, | 1219 const RequestsCallback& callback, |
1214 CacheStorageError error, | 1220 CacheStorageError error, |
1215 scoped_ptr<Requests> requests) { | 1221 scoped_ptr<Requests> requests) { |
1216 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | 1222 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); |
1217 | 1223 |
1218 callback.Run(error, requests.Pass()); | 1224 callback.Run(error, std::move(requests)); |
1219 if (cache) | 1225 if (cache) |
1220 scheduler_->CompleteOperationAndRunNext(); | 1226 scheduler_->CompleteOperationAndRunNext(); |
1221 } | 1227 } |
1222 | 1228 |
1223 void CacheStorageCache::PopulateResponseMetadata( | 1229 void CacheStorageCache::PopulateResponseMetadata( |
1224 const CacheMetadata& metadata, | 1230 const CacheMetadata& metadata, |
1225 ServiceWorkerResponse* response) { | 1231 ServiceWorkerResponse* response) { |
1226 *response = ServiceWorkerResponse( | 1232 *response = ServiceWorkerResponse( |
1227 GURL(metadata.response().url()), metadata.response().status_code(), | 1233 GURL(metadata.response().url()), metadata.response().status_code(), |
1228 metadata.response().status_text(), | 1234 metadata.response().status_text(), |
(...skipping 14 matching lines...) Expand all Loading... |
1243 ServiceWorkerResponse* response) { | 1249 ServiceWorkerResponse* response) { |
1244 DCHECK(blob_storage_context_); | 1250 DCHECK(blob_storage_context_); |
1245 | 1251 |
1246 // Create a blob with the response body data. | 1252 // Create a blob with the response body data. |
1247 response->blob_size = entry->GetDataSize(INDEX_RESPONSE_BODY); | 1253 response->blob_size = entry->GetDataSize(INDEX_RESPONSE_BODY); |
1248 response->blob_uuid = base::GenerateGUID(); | 1254 response->blob_uuid = base::GenerateGUID(); |
1249 storage::BlobDataBuilder blob_data(response->blob_uuid); | 1255 storage::BlobDataBuilder blob_data(response->blob_uuid); |
1250 | 1256 |
1251 disk_cache::Entry* temp_entry = entry.get(); | 1257 disk_cache::Entry* temp_entry = entry.get(); |
1252 blob_data.AppendDiskCacheEntry( | 1258 blob_data.AppendDiskCacheEntry( |
1253 new CacheStorageCacheDataHandle(this, entry.Pass()), temp_entry, | 1259 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, |
1254 INDEX_RESPONSE_BODY); | 1260 INDEX_RESPONSE_BODY); |
1255 return blob_storage_context_->AddFinishedBlob(&blob_data); | 1261 return blob_storage_context_->AddFinishedBlob(&blob_data); |
1256 } | 1262 } |
1257 | 1263 |
1258 } // namespace content | 1264 } // namespace content |
OLD | NEW |