| 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/service_worker/service_worker_cache.h" | 5 #include "content/browser/service_worker/service_worker_cache.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "content/browser/service_worker/service_worker_cache.pb.h" | 15 #include "content/browser/service_worker/service_worker_cache.pb.h" |
| 15 #include "content/browser/service_worker/service_worker_cache_scheduler.h" | 16 #include "content/browser/service_worker/service_worker_cache_scheduler.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/common/referrer.h" | 18 #include "content/public/common/referrer.h" |
| 18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 20 #include "net/disk_cache/disk_cache.h" | 21 #include "net/disk_cache/disk_cache.h" |
| 21 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 return weak_ptr_factory_.GetWeakPtr(); | 429 return weak_ptr_factory_.GetWeakPtr(); |
| 429 } | 430 } |
| 430 | 431 |
| 431 void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request, | 432 void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 432 scoped_ptr<ServiceWorkerResponse> response, | 433 scoped_ptr<ServiceWorkerResponse> response, |
| 433 const ResponseCallback& callback) { | 434 const ResponseCallback& callback) { |
| 434 scoped_ptr<storage::BlobDataHandle> blob_data_handle; | 435 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
| 435 | 436 |
| 436 if (!response->blob_uuid.empty()) { | 437 if (!response->blob_uuid.empty()) { |
| 437 if (!blob_storage_context_) { | 438 if (!blob_storage_context_) { |
| 438 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>(), | 439 callback.Run(ERROR_TYPE_STORAGE, scoped_ptr<ServiceWorkerResponse>(), |
| 439 scoped_ptr<storage::BlobDataHandle>()); | 440 scoped_ptr<storage::BlobDataHandle>()); |
| 440 return; | 441 return; |
| 441 } | 442 } |
| 442 blob_data_handle = | 443 blob_data_handle = |
| 443 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); | 444 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); |
| 444 if (!blob_data_handle) { | 445 if (!blob_data_handle) { |
| 445 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>(), | 446 callback.Run(ERROR_TYPE_STORAGE, scoped_ptr<ServiceWorkerResponse>(), |
| 446 scoped_ptr<storage::BlobDataHandle>()); | 447 scoped_ptr<storage::BlobDataHandle>()); |
| 447 return; | 448 return; |
| 448 } | 449 } |
| 449 } | 450 } |
| 450 | 451 |
| 451 ResponseCallback pending_callback = | 452 ResponseCallback pending_callback = |
| 452 base::Bind(&ServiceWorkerCache::PendingResponseCallback, | 453 base::Bind(&ServiceWorkerCache::PendingResponseCallback, |
| 453 weak_ptr_factory_.GetWeakPtr(), callback); | 454 weak_ptr_factory_.GetWeakPtr(), callback); |
| 454 | 455 |
| 455 scoped_ptr<PutContext> put_context(new PutContext( | 456 scoped_ptr<PutContext> put_context(new PutContext( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 471 base::Passed(put_context.Pass()))); | 472 base::Passed(put_context.Pass()))); |
| 472 } | 473 } |
| 473 | 474 |
| 474 void ServiceWorkerCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request, | 475 void ServiceWorkerCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 475 const ResponseCallback& callback) { | 476 const ResponseCallback& callback) { |
| 476 switch (backend_state_) { | 477 switch (backend_state_) { |
| 477 case BACKEND_UNINITIALIZED: | 478 case BACKEND_UNINITIALIZED: |
| 478 InitBackend(); | 479 InitBackend(); |
| 479 break; | 480 break; |
| 480 case BACKEND_CLOSED: | 481 case BACKEND_CLOSED: |
| 481 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>(), | 482 callback.Run(ERROR_TYPE_STORAGE, scoped_ptr<ServiceWorkerResponse>(), |
| 482 scoped_ptr<storage::BlobDataHandle>()); | 483 scoped_ptr<storage::BlobDataHandle>()); |
| 483 return; | 484 return; |
| 484 case BACKEND_OPEN: | 485 case BACKEND_OPEN: |
| 485 DCHECK(backend_); | 486 DCHECK(backend_); |
| 486 break; | 487 break; |
| 487 } | 488 } |
| 488 | 489 |
| 489 ResponseCallback pending_callback = | 490 ResponseCallback pending_callback = |
| 490 base::Bind(&ServiceWorkerCache::PendingResponseCallback, | 491 base::Bind(&ServiceWorkerCache::PendingResponseCallback, |
| 491 weak_ptr_factory_.GetWeakPtr(), callback); | 492 weak_ptr_factory_.GetWeakPtr(), callback); |
| 492 scheduler_->ScheduleOperation( | 493 scheduler_->ScheduleOperation( |
| 493 base::Bind(&ServiceWorkerCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), | 494 base::Bind(&ServiceWorkerCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), |
| 494 base::Passed(request.Pass()), pending_callback)); | 495 base::Passed(request.Pass()), pending_callback)); |
| 495 } | 496 } |
| 496 | 497 |
| 497 void ServiceWorkerCache::Delete(scoped_ptr<ServiceWorkerFetchRequest> request, | 498 void ServiceWorkerCache::Delete(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 498 const ErrorCallback& callback) { | 499 const ErrorCallback& callback) { |
| 499 switch (backend_state_) { | 500 switch (backend_state_) { |
| 500 case BACKEND_UNINITIALIZED: | 501 case BACKEND_UNINITIALIZED: |
| 501 InitBackend(); | 502 InitBackend(); |
| 502 break; | 503 break; |
| 503 case BACKEND_CLOSED: | 504 case BACKEND_CLOSED: |
| 504 callback.Run(ErrorTypeStorage); | 505 callback.Run(ERROR_TYPE_STORAGE); |
| 505 return; | 506 return; |
| 506 case BACKEND_OPEN: | 507 case BACKEND_OPEN: |
| 507 DCHECK(backend_); | 508 DCHECK(backend_); |
| 508 break; | 509 break; |
| 509 } | 510 } |
| 510 ErrorCallback pending_callback = | 511 ErrorCallback pending_callback = |
| 511 base::Bind(&ServiceWorkerCache::PendingErrorCallback, | 512 base::Bind(&ServiceWorkerCache::PendingErrorCallback, |
| 512 weak_ptr_factory_.GetWeakPtr(), callback); | 513 weak_ptr_factory_.GetWeakPtr(), callback); |
| 513 scheduler_->ScheduleOperation(base::Bind( | 514 scheduler_->ScheduleOperation(base::Bind( |
| 514 &ServiceWorkerCache::DeleteImpl, weak_ptr_factory_.GetWeakPtr(), | 515 &ServiceWorkerCache::DeleteImpl, weak_ptr_factory_.GetWeakPtr(), |
| 515 base::Passed(request.Pass()), pending_callback)); | 516 base::Passed(request.Pass()), pending_callback)); |
| 516 } | 517 } |
| 517 | 518 |
| 518 void ServiceWorkerCache::Keys(const RequestsCallback& callback) { | 519 void ServiceWorkerCache::Keys(const RequestsCallback& callback) { |
| 519 switch (backend_state_) { | 520 switch (backend_state_) { |
| 520 case BACKEND_UNINITIALIZED: | 521 case BACKEND_UNINITIALIZED: |
| 521 InitBackend(); | 522 InitBackend(); |
| 522 break; | 523 break; |
| 523 case BACKEND_CLOSED: | 524 case BACKEND_CLOSED: |
| 524 callback.Run(ErrorTypeStorage, scoped_ptr<Requests>()); | 525 callback.Run(ERROR_TYPE_STORAGE, scoped_ptr<Requests>()); |
| 525 return; | 526 return; |
| 526 case BACKEND_OPEN: | 527 case BACKEND_OPEN: |
| 527 DCHECK(backend_); | 528 DCHECK(backend_); |
| 528 break; | 529 break; |
| 529 } | 530 } |
| 530 | 531 |
| 531 RequestsCallback pending_callback = | 532 RequestsCallback pending_callback = |
| 532 base::Bind(&ServiceWorkerCache::PendingRequestsCallback, | 533 base::Bind(&ServiceWorkerCache::PendingRequestsCallback, |
| 533 weak_ptr_factory_.GetWeakPtr(), callback); | 534 weak_ptr_factory_.GetWeakPtr(), callback); |
| 534 scheduler_->ScheduleOperation(base::Bind(&ServiceWorkerCache::KeysImpl, | 535 scheduler_->ScheduleOperation(base::Bind(&ServiceWorkerCache::KeysImpl, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 initializing_(false), | 594 initializing_(false), |
| 594 memory_only_(path.empty()), | 595 memory_only_(path.empty()), |
| 595 weak_ptr_factory_(this) { | 596 weak_ptr_factory_(this) { |
| 596 } | 597 } |
| 597 | 598 |
| 598 void ServiceWorkerCache::MatchImpl( | 599 void ServiceWorkerCache::MatchImpl( |
| 599 scoped_ptr<ServiceWorkerFetchRequest> request, | 600 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 600 const ResponseCallback& callback) { | 601 const ResponseCallback& callback) { |
| 601 DCHECK(backend_state_ != BACKEND_UNINITIALIZED); | 602 DCHECK(backend_state_ != BACKEND_UNINITIALIZED); |
| 602 if (backend_state_ != BACKEND_OPEN) { | 603 if (backend_state_ != BACKEND_OPEN) { |
| 603 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>(), | 604 callback.Run(ERROR_TYPE_STORAGE, scoped_ptr<ServiceWorkerResponse>(), |
| 604 scoped_ptr<storage::BlobDataHandle>()); | 605 scoped_ptr<storage::BlobDataHandle>()); |
| 605 return; | 606 return; |
| 606 } | 607 } |
| 607 | 608 |
| 608 scoped_ptr<MatchContext> match_context( | 609 scoped_ptr<MatchContext> match_context( |
| 609 new MatchContext(request.Pass(), callback, blob_storage_context_)); | 610 new MatchContext(request.Pass(), callback, blob_storage_context_)); |
| 610 | 611 |
| 611 disk_cache::Entry** entry_ptr = &match_context->entry; | 612 disk_cache::Entry** entry_ptr = &match_context->entry; |
| 612 ServiceWorkerFetchRequest* request_ptr = match_context->request.get(); | 613 ServiceWorkerFetchRequest* request_ptr = match_context->request.get(); |
| 613 | 614 |
| 614 net::CompletionCallback open_entry_callback = base::Bind( | 615 net::CompletionCallback open_entry_callback = base::Bind( |
| 615 &ServiceWorkerCache::MatchDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), | 616 &ServiceWorkerCache::MatchDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), |
| 616 base::Passed(match_context.Pass())); | 617 base::Passed(match_context.Pass())); |
| 617 | 618 |
| 618 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, | 619 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, |
| 619 open_entry_callback); | 620 open_entry_callback); |
| 620 if (rv != net::ERR_IO_PENDING) | 621 if (rv != net::ERR_IO_PENDING) |
| 621 open_entry_callback.Run(rv); | 622 open_entry_callback.Run(rv); |
| 622 } | 623 } |
| 623 | 624 |
| 624 void ServiceWorkerCache::MatchDidOpenEntry( | 625 void ServiceWorkerCache::MatchDidOpenEntry( |
| 625 scoped_ptr<MatchContext> match_context, | 626 scoped_ptr<MatchContext> match_context, |
| 626 int rv) { | 627 int rv) { |
| 627 if (rv != net::OK) { | 628 if (rv != net::OK) { |
| 628 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeNotFound, | 629 match_context->original_callback.Run( |
| 629 scoped_ptr<ServiceWorkerResponse>(), | 630 ServiceWorkerCache::ERROR_TYPE_NOT_FOUND, |
| 630 scoped_ptr<storage::BlobDataHandle>()); | 631 scoped_ptr<ServiceWorkerResponse>(), |
| 632 scoped_ptr<storage::BlobDataHandle>()); |
| 631 return; | 633 return; |
| 632 } | 634 } |
| 633 | 635 |
| 634 // Copy the entry pointer before passing it in base::Bind. | 636 // Copy the entry pointer before passing it in base::Bind. |
| 635 disk_cache::Entry* tmp_entry_ptr = match_context->entry; | 637 disk_cache::Entry* tmp_entry_ptr = match_context->entry; |
| 636 DCHECK(tmp_entry_ptr); | 638 DCHECK(tmp_entry_ptr); |
| 637 | 639 |
| 638 MetadataCallback headers_callback = base::Bind( | 640 MetadataCallback headers_callback = base::Bind( |
| 639 &ServiceWorkerCache::MatchDidReadMetadata, weak_ptr_factory_.GetWeakPtr(), | 641 &ServiceWorkerCache::MatchDidReadMetadata, weak_ptr_factory_.GetWeakPtr(), |
| 640 base::Passed(match_context.Pass())); | 642 base::Passed(match_context.Pass())); |
| 641 | 643 |
| 642 ReadMetadata(tmp_entry_ptr, headers_callback); | 644 ReadMetadata(tmp_entry_ptr, headers_callback); |
| 643 } | 645 } |
| 644 | 646 |
| 645 void ServiceWorkerCache::MatchDidReadMetadata( | 647 void ServiceWorkerCache::MatchDidReadMetadata( |
| 646 scoped_ptr<MatchContext> match_context, | 648 scoped_ptr<MatchContext> match_context, |
| 647 scoped_ptr<ServiceWorkerCacheMetadata> metadata) { | 649 scoped_ptr<ServiceWorkerCacheMetadata> metadata) { |
| 648 if (!metadata) { | 650 if (!metadata) { |
| 649 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 651 match_context->original_callback.Run(ServiceWorkerCache::ERROR_TYPE_STORAGE, |
| 650 scoped_ptr<ServiceWorkerResponse>(), | 652 scoped_ptr<ServiceWorkerResponse>(), |
| 651 scoped_ptr<storage::BlobDataHandle>()); | 653 scoped_ptr<storage::BlobDataHandle>()); |
| 652 return; | 654 return; |
| 653 } | 655 } |
| 654 | 656 |
| 655 match_context->response.reset(new ServiceWorkerResponse( | 657 match_context->response.reset(new ServiceWorkerResponse( |
| 656 match_context->request->url, metadata->response().status_code(), | 658 match_context->request->url, metadata->response().status_code(), |
| 657 metadata->response().status_text(), | 659 metadata->response().status_text(), |
| 658 ProtoResponseTypeToWebResponseType(metadata->response().response_type()), | 660 ProtoResponseTypeToWebResponseType(metadata->response().response_type()), |
| 659 ServiceWorkerHeaderMap(), "", 0, GURL())); | 661 ServiceWorkerHeaderMap(), "", 0, GURL())); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 673 ServiceWorkerHeaderMap cached_request_headers; | 675 ServiceWorkerHeaderMap cached_request_headers; |
| 674 for (int i = 0; i < metadata->request().headers_size(); ++i) { | 676 for (int i = 0; i < metadata->request().headers_size(); ++i) { |
| 675 const ServiceWorkerCacheHeaderMap header = metadata->request().headers(i); | 677 const ServiceWorkerCacheHeaderMap header = metadata->request().headers(i); |
| 676 DCHECK(header.name().find('\0') == std::string::npos); | 678 DCHECK(header.name().find('\0') == std::string::npos); |
| 677 DCHECK(header.value().find('\0') == std::string::npos); | 679 DCHECK(header.value().find('\0') == std::string::npos); |
| 678 cached_request_headers[header.name()] = header.value(); | 680 cached_request_headers[header.name()] = header.value(); |
| 679 } | 681 } |
| 680 | 682 |
| 681 if (!VaryMatches(match_context->request->headers, cached_request_headers, | 683 if (!VaryMatches(match_context->request->headers, cached_request_headers, |
| 682 response->headers)) { | 684 response->headers)) { |
| 683 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeNotFound, | 685 match_context->original_callback.Run( |
| 684 scoped_ptr<ServiceWorkerResponse>(), | 686 ServiceWorkerCache::ERROR_TYPE_NOT_FOUND, |
| 685 scoped_ptr<storage::BlobDataHandle>()); | 687 scoped_ptr<ServiceWorkerResponse>(), |
| 688 scoped_ptr<storage::BlobDataHandle>()); |
| 686 return; | 689 return; |
| 687 } | 690 } |
| 688 | 691 |
| 689 if (match_context->entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) { | 692 if (match_context->entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) { |
| 690 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK, | 693 match_context->original_callback.Run(ServiceWorkerCache::ERROR_TYPE_OK, |
| 691 match_context->response.Pass(), | 694 match_context->response.Pass(), |
| 692 scoped_ptr<storage::BlobDataHandle>()); | 695 scoped_ptr<storage::BlobDataHandle>()); |
| 693 return; | 696 return; |
| 694 } | 697 } |
| 695 | 698 |
| 696 // Stream the response body into a blob. | 699 // Stream the response body into a blob. |
| 697 if (!match_context->blob_storage_context) { | 700 if (!match_context->blob_storage_context) { |
| 698 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 701 match_context->original_callback.Run(ServiceWorkerCache::ERROR_TYPE_STORAGE, |
| 699 scoped_ptr<ServiceWorkerResponse>(), | 702 scoped_ptr<ServiceWorkerResponse>(), |
| 700 scoped_ptr<storage::BlobDataHandle>()); | 703 scoped_ptr<storage::BlobDataHandle>()); |
| 701 return; | 704 return; |
| 702 } | 705 } |
| 703 | 706 |
| 704 response->blob_uuid = base::GenerateGUID(); | 707 response->blob_uuid = base::GenerateGUID(); |
| 705 | 708 |
| 706 match_context->blob_data.reset( | 709 match_context->blob_data.reset( |
| 707 new storage::BlobDataBuilder(response->blob_uuid)); | 710 new storage::BlobDataBuilder(response->blob_uuid)); |
| 708 match_context->response_body_buffer = new net::IOBufferWithSize(kBufferSize); | 711 match_context->response_body_buffer = new net::IOBufferWithSize(kBufferSize); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 725 | 728 |
| 726 void ServiceWorkerCache::MatchDidReadResponseBodyData( | 729 void ServiceWorkerCache::MatchDidReadResponseBodyData( |
| 727 scoped_ptr<MatchContext> match_context, | 730 scoped_ptr<MatchContext> match_context, |
| 728 int rv) { | 731 int rv) { |
| 729 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 732 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 730 tracked_objects::ScopedTracker tracking_profile( | 733 tracked_objects::ScopedTracker tracking_profile( |
| 731 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 734 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 732 "422516 ServiceWorkerCache::MatchDidReadResponseBodyData")); | 735 "422516 ServiceWorkerCache::MatchDidReadResponseBodyData")); |
| 733 | 736 |
| 734 if (rv < 0) { | 737 if (rv < 0) { |
| 735 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 738 match_context->original_callback.Run(ServiceWorkerCache::ERROR_TYPE_STORAGE, |
| 736 scoped_ptr<ServiceWorkerResponse>(), | 739 scoped_ptr<ServiceWorkerResponse>(), |
| 737 scoped_ptr<storage::BlobDataHandle>()); | 740 scoped_ptr<storage::BlobDataHandle>()); |
| 738 return; | 741 return; |
| 739 } | 742 } |
| 740 | 743 |
| 741 if (rv == 0) { | 744 if (rv == 0) { |
| 742 match_context->response->blob_uuid = match_context->blob_data->uuid(); | 745 match_context->response->blob_uuid = match_context->blob_data->uuid(); |
| 743 match_context->response->blob_size = match_context->total_bytes_read; | 746 match_context->response->blob_size = match_context->total_bytes_read; |
| 744 MatchDoneWithBody(match_context.Pass()); | 747 MatchDoneWithBody(match_context.Pass()); |
| 745 return; | 748 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 764 int read_rv = tmp_entry_ptr->ReadData(INDEX_RESPONSE_BODY, total_bytes_read, | 767 int read_rv = tmp_entry_ptr->ReadData(INDEX_RESPONSE_BODY, total_bytes_read, |
| 765 buffer, buffer->size(), read_callback); | 768 buffer, buffer->size(), read_callback); |
| 766 | 769 |
| 767 if (read_rv != net::ERR_IO_PENDING) | 770 if (read_rv != net::ERR_IO_PENDING) |
| 768 read_callback.Run(read_rv); | 771 read_callback.Run(read_rv); |
| 769 } | 772 } |
| 770 | 773 |
| 771 void ServiceWorkerCache::MatchDoneWithBody( | 774 void ServiceWorkerCache::MatchDoneWithBody( |
| 772 scoped_ptr<MatchContext> match_context) { | 775 scoped_ptr<MatchContext> match_context) { |
| 773 if (!match_context->blob_storage_context) { | 776 if (!match_context->blob_storage_context) { |
| 774 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 777 match_context->original_callback.Run(ServiceWorkerCache::ERROR_TYPE_STORAGE, |
| 775 scoped_ptr<ServiceWorkerResponse>(), | 778 scoped_ptr<ServiceWorkerResponse>(), |
| 776 scoped_ptr<storage::BlobDataHandle>()); | 779 scoped_ptr<storage::BlobDataHandle>()); |
| 777 return; | 780 return; |
| 778 } | 781 } |
| 779 | 782 |
| 780 scoped_ptr<storage::BlobDataHandle> blob_data_handle( | 783 scoped_ptr<storage::BlobDataHandle> blob_data_handle( |
| 781 match_context->blob_storage_context->AddFinishedBlob( | 784 match_context->blob_storage_context->AddFinishedBlob( |
| 782 match_context->blob_data.get())); | 785 match_context->blob_data.get())); |
| 783 | 786 |
| 784 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK, | 787 match_context->original_callback.Run(ServiceWorkerCache::ERROR_TYPE_OK, |
| 785 match_context->response.Pass(), | 788 match_context->response.Pass(), |
| 786 blob_data_handle.Pass()); | 789 blob_data_handle.Pass()); |
| 787 } | 790 } |
| 788 | 791 |
| 789 void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) { | 792 void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) { |
| 790 DCHECK(backend_state_ != BACKEND_UNINITIALIZED); | 793 DCHECK(backend_state_ != BACKEND_UNINITIALIZED); |
| 791 if (backend_state_ != BACKEND_OPEN) { | 794 if (backend_state_ != BACKEND_OPEN) { |
| 792 put_context->callback.Run(ErrorTypeStorage, | 795 put_context->callback.Run(ERROR_TYPE_STORAGE, |
| 793 scoped_ptr<ServiceWorkerResponse>(), | 796 scoped_ptr<ServiceWorkerResponse>(), |
| 794 scoped_ptr<storage::BlobDataHandle>()); | 797 scoped_ptr<storage::BlobDataHandle>()); |
| 795 return; | 798 return; |
| 796 } | 799 } |
| 797 | 800 |
| 798 scoped_ptr<ServiceWorkerFetchRequest> request_copy( | 801 scoped_ptr<ServiceWorkerFetchRequest> request_copy( |
| 799 new ServiceWorkerFetchRequest(*put_context->request)); | 802 new ServiceWorkerFetchRequest(*put_context->request)); |
| 800 | 803 |
| 801 DeleteImpl(request_copy.Pass(), base::Bind(&ServiceWorkerCache::PutDidDelete, | 804 DeleteImpl(request_copy.Pass(), base::Bind(&ServiceWorkerCache::PutDidDelete, |
| 802 weak_ptr_factory_.GetWeakPtr(), | 805 weak_ptr_factory_.GetWeakPtr(), |
| 803 base::Passed(put_context.Pass()))); | 806 base::Passed(put_context.Pass()))); |
| 804 } | 807 } |
| 805 | 808 |
| 806 void ServiceWorkerCache::PutDidDelete(scoped_ptr<PutContext> put_context, | 809 void ServiceWorkerCache::PutDidDelete(scoped_ptr<PutContext> put_context, |
| 807 ErrorType delete_error) { | 810 ErrorType delete_error) { |
| 808 if (backend_state_ != BACKEND_OPEN) { | 811 if (backend_state_ != BACKEND_OPEN) { |
| 809 put_context->callback.Run(ErrorTypeStorage, | 812 put_context->callback.Run(ERROR_TYPE_STORAGE, |
| 810 scoped_ptr<ServiceWorkerResponse>(), | 813 scoped_ptr<ServiceWorkerResponse>(), |
| 811 scoped_ptr<storage::BlobDataHandle>()); | 814 scoped_ptr<storage::BlobDataHandle>()); |
| 812 return; | 815 return; |
| 813 } | 816 } |
| 814 | 817 |
| 815 disk_cache::Entry** entry_ptr = &put_context->cache_entry; | 818 disk_cache::Entry** entry_ptr = &put_context->cache_entry; |
| 816 ServiceWorkerFetchRequest* request_ptr = put_context->request.get(); | 819 ServiceWorkerFetchRequest* request_ptr = put_context->request.get(); |
| 817 disk_cache::Backend* backend_ptr = backend_.get(); | 820 disk_cache::Backend* backend_ptr = backend_.get(); |
| 818 | 821 |
| 819 net::CompletionCallback create_entry_callback = base::Bind( | 822 net::CompletionCallback create_entry_callback = base::Bind( |
| 820 &ServiceWorkerCache::PutDidCreateEntry, weak_ptr_factory_.GetWeakPtr(), | 823 &ServiceWorkerCache::PutDidCreateEntry, weak_ptr_factory_.GetWeakPtr(), |
| 821 base::Passed(put_context.Pass())); | 824 base::Passed(put_context.Pass())); |
| 822 | 825 |
| 823 int create_rv = backend_ptr->CreateEntry( | 826 int create_rv = backend_ptr->CreateEntry( |
| 824 request_ptr->url.spec(), entry_ptr, create_entry_callback); | 827 request_ptr->url.spec(), entry_ptr, create_entry_callback); |
| 825 | 828 |
| 826 if (create_rv != net::ERR_IO_PENDING) | 829 if (create_rv != net::ERR_IO_PENDING) |
| 827 create_entry_callback.Run(create_rv); | 830 create_entry_callback.Run(create_rv); |
| 828 } | 831 } |
| 829 | 832 |
| 830 void ServiceWorkerCache::PutDidCreateEntry(scoped_ptr<PutContext> put_context, | 833 void ServiceWorkerCache::PutDidCreateEntry(scoped_ptr<PutContext> put_context, |
| 831 int rv) { | 834 int rv) { |
| 832 if (rv != net::OK) { | 835 if (rv != net::OK) { |
| 833 put_context->callback.Run(ServiceWorkerCache::ErrorTypeExists, | 836 put_context->callback.Run(ServiceWorkerCache::ERROR_TYPE_EXISTS, |
| 834 scoped_ptr<ServiceWorkerResponse>(), | 837 scoped_ptr<ServiceWorkerResponse>(), |
| 835 scoped_ptr<storage::BlobDataHandle>()); | 838 scoped_ptr<storage::BlobDataHandle>()); |
| 836 return; | 839 return; |
| 837 } | 840 } |
| 838 | 841 |
| 839 DCHECK(put_context->cache_entry); | 842 DCHECK(put_context->cache_entry); |
| 840 | 843 |
| 841 ServiceWorkerCacheMetadata metadata; | 844 ServiceWorkerCacheMetadata metadata; |
| 842 ServiceWorkerCacheRequest* request_metadata = metadata.mutable_request(); | 845 ServiceWorkerCacheRequest* request_metadata = metadata.mutable_request(); |
| 843 request_metadata->set_method(put_context->request->method); | 846 request_metadata->set_method(put_context->request->method); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 864 ++it) { | 867 ++it) { |
| 865 DCHECK(it->first.find('\0') == std::string::npos); | 868 DCHECK(it->first.find('\0') == std::string::npos); |
| 866 DCHECK(it->second.find('\0') == std::string::npos); | 869 DCHECK(it->second.find('\0') == std::string::npos); |
| 867 ServiceWorkerCacheHeaderMap* header_map = response_metadata->add_headers(); | 870 ServiceWorkerCacheHeaderMap* header_map = response_metadata->add_headers(); |
| 868 header_map->set_name(it->first); | 871 header_map->set_name(it->first); |
| 869 header_map->set_value(it->second); | 872 header_map->set_value(it->second); |
| 870 } | 873 } |
| 871 | 874 |
| 872 scoped_ptr<std::string> serialized(new std::string()); | 875 scoped_ptr<std::string> serialized(new std::string()); |
| 873 if (!metadata.SerializeToString(serialized.get())) { | 876 if (!metadata.SerializeToString(serialized.get())) { |
| 874 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 877 put_context->callback.Run(ServiceWorkerCache::ERROR_TYPE_STORAGE, |
| 875 scoped_ptr<ServiceWorkerResponse>(), | 878 scoped_ptr<ServiceWorkerResponse>(), |
| 876 scoped_ptr<storage::BlobDataHandle>()); | 879 scoped_ptr<storage::BlobDataHandle>()); |
| 877 return; | 880 return; |
| 878 } | 881 } |
| 879 | 882 |
| 880 scoped_refptr<net::StringIOBuffer> buffer( | 883 scoped_refptr<net::StringIOBuffer> buffer( |
| 881 new net::StringIOBuffer(serialized.Pass())); | 884 new net::StringIOBuffer(serialized.Pass())); |
| 882 | 885 |
| 883 // Get a temporary copy of the entry pointer before passing it in base::Bind. | 886 // Get a temporary copy of the entry pointer before passing it in base::Bind. |
| 884 disk_cache::Entry* tmp_entry_ptr = put_context->cache_entry; | 887 disk_cache::Entry* tmp_entry_ptr = put_context->cache_entry; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 896 | 899 |
| 897 if (rv != net::ERR_IO_PENDING) | 900 if (rv != net::ERR_IO_PENDING) |
| 898 write_headers_callback.Run(rv); | 901 write_headers_callback.Run(rv); |
| 899 } | 902 } |
| 900 | 903 |
| 901 void ServiceWorkerCache::PutDidWriteHeaders(scoped_ptr<PutContext> put_context, | 904 void ServiceWorkerCache::PutDidWriteHeaders(scoped_ptr<PutContext> put_context, |
| 902 int expected_bytes, | 905 int expected_bytes, |
| 903 int rv) { | 906 int rv) { |
| 904 if (rv != expected_bytes) { | 907 if (rv != expected_bytes) { |
| 905 put_context->cache_entry->Doom(); | 908 put_context->cache_entry->Doom(); |
| 906 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 909 put_context->callback.Run(ServiceWorkerCache::ERROR_TYPE_STORAGE, |
| 907 scoped_ptr<ServiceWorkerResponse>(), | 910 scoped_ptr<ServiceWorkerResponse>(), |
| 908 scoped_ptr<storage::BlobDataHandle>()); | 911 scoped_ptr<storage::BlobDataHandle>()); |
| 909 return; | 912 return; |
| 910 } | 913 } |
| 911 | 914 |
| 912 // The metadata is written, now for the response content. The data is streamed | 915 // The metadata is written, now for the response content. The data is streamed |
| 913 // from the blob into the cache entry. | 916 // from the blob into the cache entry. |
| 914 | 917 |
| 915 if (put_context->response->blob_uuid.empty()) { | 918 if (put_context->response->blob_uuid.empty()) { |
| 916 if (put_context->quota_manager_proxy.get()) { | 919 if (put_context->quota_manager_proxy.get()) { |
| 917 put_context->quota_manager_proxy->NotifyStorageModified( | 920 put_context->quota_manager_proxy->NotifyStorageModified( |
| 918 storage::QuotaClient::kServiceWorkerCache, | 921 storage::QuotaClient::kServiceWorkerCache, |
| 919 put_context->origin, | 922 put_context->origin, |
| 920 storage::kStorageTypeTemporary, | 923 storage::kStorageTypeTemporary, |
| 921 put_context->cache_entry->GetDataSize(INDEX_HEADERS)); | 924 put_context->cache_entry->GetDataSize(INDEX_HEADERS)); |
| 922 } | 925 } |
| 923 | 926 |
| 924 put_context->callback.Run(ServiceWorkerCache::ErrorTypeOK, | 927 put_context->callback.Run(ServiceWorkerCache::ERROR_TYPE_OK, |
| 925 put_context->response.Pass(), | 928 put_context->response.Pass(), |
| 926 scoped_ptr<storage::BlobDataHandle>()); | 929 scoped_ptr<storage::BlobDataHandle>()); |
| 927 return; | 930 return; |
| 928 } | 931 } |
| 929 | 932 |
| 930 DCHECK(put_context->blob_data_handle); | 933 DCHECK(put_context->blob_data_handle); |
| 931 | 934 |
| 932 disk_cache::ScopedEntryPtr entry(put_context->cache_entry); | 935 disk_cache::ScopedEntryPtr entry(put_context->cache_entry); |
| 933 put_context->cache_entry = NULL; | 936 put_context->cache_entry = NULL; |
| 934 scoped_ptr<BlobReader> reader(new BlobReader()); | 937 scoped_ptr<BlobReader> reader(new BlobReader()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 950 void ServiceWorkerCache::PutDidWriteBlobToCache( | 953 void ServiceWorkerCache::PutDidWriteBlobToCache( |
| 951 scoped_ptr<PutContext> put_context, | 954 scoped_ptr<PutContext> put_context, |
| 952 scoped_ptr<BlobReader> blob_reader, | 955 scoped_ptr<BlobReader> blob_reader, |
| 953 disk_cache::ScopedEntryPtr entry, | 956 disk_cache::ScopedEntryPtr entry, |
| 954 bool success) { | 957 bool success) { |
| 955 DCHECK(entry); | 958 DCHECK(entry); |
| 956 put_context->cache_entry = entry.release(); | 959 put_context->cache_entry = entry.release(); |
| 957 | 960 |
| 958 if (!success) { | 961 if (!success) { |
| 959 put_context->cache_entry->Doom(); | 962 put_context->cache_entry->Doom(); |
| 960 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 963 put_context->callback.Run(ServiceWorkerCache::ERROR_TYPE_STORAGE, |
| 961 scoped_ptr<ServiceWorkerResponse>(), | 964 scoped_ptr<ServiceWorkerResponse>(), |
| 962 scoped_ptr<storage::BlobDataHandle>()); | 965 scoped_ptr<storage::BlobDataHandle>()); |
| 963 return; | 966 return; |
| 964 } | 967 } |
| 965 | 968 |
| 966 if (put_context->quota_manager_proxy.get()) { | 969 if (put_context->quota_manager_proxy.get()) { |
| 967 put_context->quota_manager_proxy->NotifyStorageModified( | 970 put_context->quota_manager_proxy->NotifyStorageModified( |
| 968 storage::QuotaClient::kServiceWorkerCache, | 971 storage::QuotaClient::kServiceWorkerCache, |
| 969 put_context->origin, | 972 put_context->origin, |
| 970 storage::kStorageTypeTemporary, | 973 storage::kStorageTypeTemporary, |
| 971 put_context->cache_entry->GetDataSize(INDEX_HEADERS) + | 974 put_context->cache_entry->GetDataSize(INDEX_HEADERS) + |
| 972 put_context->cache_entry->GetDataSize(INDEX_RESPONSE_BODY)); | 975 put_context->cache_entry->GetDataSize(INDEX_RESPONSE_BODY)); |
| 973 } | 976 } |
| 974 | 977 |
| 975 put_context->callback.Run(ServiceWorkerCache::ErrorTypeOK, | 978 put_context->callback.Run(ServiceWorkerCache::ERROR_TYPE_OK, |
| 976 put_context->response.Pass(), | 979 put_context->response.Pass(), |
| 977 put_context->out_blob_data_handle.Pass()); | 980 put_context->out_blob_data_handle.Pass()); |
| 978 } | 981 } |
| 979 | 982 |
| 980 void ServiceWorkerCache::DeleteImpl( | 983 void ServiceWorkerCache::DeleteImpl( |
| 981 scoped_ptr<ServiceWorkerFetchRequest> request, | 984 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 982 const ErrorCallback& callback) { | 985 const ErrorCallback& callback) { |
| 983 DCHECK(backend_state_ != BACKEND_UNINITIALIZED); | 986 DCHECK(backend_state_ != BACKEND_UNINITIALIZED); |
| 984 if (backend_state_ != BACKEND_OPEN) { | 987 if (backend_state_ != BACKEND_OPEN) { |
| 985 callback.Run(ErrorTypeStorage); | 988 callback.Run(ERROR_TYPE_STORAGE); |
| 986 return; | 989 return; |
| 987 } | 990 } |
| 988 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 991 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); |
| 989 | 992 |
| 990 disk_cache::Entry** entry_ptr = entry.get(); | 993 disk_cache::Entry** entry_ptr = entry.get(); |
| 991 | 994 |
| 992 ServiceWorkerFetchRequest* request_ptr = request.get(); | 995 ServiceWorkerFetchRequest* request_ptr = request.get(); |
| 993 | 996 |
| 994 net::CompletionCallback open_entry_callback = base::Bind( | 997 net::CompletionCallback open_entry_callback = base::Bind( |
| 995 &ServiceWorkerCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), | 998 &ServiceWorkerCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), |
| 996 origin_, base::Passed(request.Pass()), callback, | 999 origin_, base::Passed(request.Pass()), callback, |
| 997 base::Passed(entry.Pass()), quota_manager_proxy_); | 1000 base::Passed(entry.Pass()), quota_manager_proxy_); |
| 998 | 1001 |
| 999 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, | 1002 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, |
| 1000 open_entry_callback); | 1003 open_entry_callback); |
| 1001 if (rv != net::ERR_IO_PENDING) | 1004 if (rv != net::ERR_IO_PENDING) |
| 1002 open_entry_callback.Run(rv); | 1005 open_entry_callback.Run(rv); |
| 1003 } | 1006 } |
| 1004 | 1007 |
| 1005 void ServiceWorkerCache::DeleteDidOpenEntry( | 1008 void ServiceWorkerCache::DeleteDidOpenEntry( |
| 1006 const GURL& origin, | 1009 const GURL& origin, |
| 1007 scoped_ptr<ServiceWorkerFetchRequest> request, | 1010 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 1008 const ServiceWorkerCache::ErrorCallback& callback, | 1011 const ServiceWorkerCache::ErrorCallback& callback, |
| 1009 scoped_ptr<disk_cache::Entry*> entry_ptr, | 1012 scoped_ptr<disk_cache::Entry*> entry_ptr, |
| 1010 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, | 1013 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, |
| 1011 int rv) { | 1014 int rv) { |
| 1012 if (rv != net::OK) { | 1015 if (rv != net::OK) { |
| 1013 callback.Run(ServiceWorkerCache::ErrorTypeNotFound); | 1016 callback.Run(ServiceWorkerCache::ERROR_TYPE_NOT_FOUND); |
| 1014 return; | 1017 return; |
| 1015 } | 1018 } |
| 1016 | 1019 |
| 1017 DCHECK(entry_ptr); | 1020 DCHECK(entry_ptr); |
| 1018 disk_cache::ScopedEntryPtr entry(*entry_ptr); | 1021 disk_cache::ScopedEntryPtr entry(*entry_ptr); |
| 1019 | 1022 |
| 1020 if (quota_manager_proxy.get()) { | 1023 if (quota_manager_proxy.get()) { |
| 1021 quota_manager_proxy->NotifyStorageModified( | 1024 quota_manager_proxy->NotifyStorageModified( |
| 1022 storage::QuotaClient::kServiceWorkerCache, origin, | 1025 storage::QuotaClient::kServiceWorkerCache, origin, |
| 1023 storage::kStorageTypeTemporary, | 1026 storage::kStorageTypeTemporary, |
| 1024 -1 * (entry->GetDataSize(INDEX_HEADERS) + | 1027 -1 * (entry->GetDataSize(INDEX_HEADERS) + |
| 1025 entry->GetDataSize(INDEX_RESPONSE_BODY))); | 1028 entry->GetDataSize(INDEX_RESPONSE_BODY))); |
| 1026 } | 1029 } |
| 1027 | 1030 |
| 1028 entry->Doom(); | 1031 entry->Doom(); |
| 1029 callback.Run(ServiceWorkerCache::ErrorTypeOK); | 1032 callback.Run(ServiceWorkerCache::ERROR_TYPE_OK); |
| 1030 } | 1033 } |
| 1031 | 1034 |
| 1032 void ServiceWorkerCache::KeysImpl(const RequestsCallback& callback) { | 1035 void ServiceWorkerCache::KeysImpl(const RequestsCallback& callback) { |
| 1033 DCHECK(backend_state_ != BACKEND_UNINITIALIZED); | 1036 DCHECK(backend_state_ != BACKEND_UNINITIALIZED); |
| 1034 if (backend_state_ != BACKEND_OPEN) { | 1037 if (backend_state_ != BACKEND_OPEN) { |
| 1035 callback.Run(ErrorTypeStorage, scoped_ptr<Requests>()); | 1038 callback.Run(ERROR_TYPE_STORAGE, scoped_ptr<Requests>()); |
| 1036 return; | 1039 return; |
| 1037 } | 1040 } |
| 1038 | 1041 |
| 1039 // 1. Iterate through all of the entries, open them, and add them to a vector. | 1042 // 1. Iterate through all of the entries, open them, and add them to a vector. |
| 1040 // 2. For each open entry: | 1043 // 2. For each open entry: |
| 1041 // 2.1. Read the headers into a protobuf. | 1044 // 2.1. Read the headers into a protobuf. |
| 1042 // 2.2. Copy the protobuf into a ServiceWorkerFetchRequest (a "key"). | 1045 // 2.2. Copy the protobuf into a ServiceWorkerFetchRequest (a "key"). |
| 1043 // 2.3. Push the response into a vector of requests to be returned. | 1046 // 2.3. Push the response into a vector of requests to be returned. |
| 1044 // 3. Return the vector of requests (keys). | 1047 // 3. Return the vector of requests (keys). |
| 1045 | 1048 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1067 int rv) { | 1070 int rv) { |
| 1068 if (rv == net::ERR_FAILED) { | 1071 if (rv == net::ERR_FAILED) { |
| 1069 DCHECK(!keys_context->enumerated_entry); | 1072 DCHECK(!keys_context->enumerated_entry); |
| 1070 // Enumeration is complete, extract the requests from the entries. | 1073 // Enumeration is complete, extract the requests from the entries. |
| 1071 Entries::iterator iter = keys_context->entries.begin(); | 1074 Entries::iterator iter = keys_context->entries.begin(); |
| 1072 KeysProcessNextEntry(keys_context.Pass(), iter); | 1075 KeysProcessNextEntry(keys_context.Pass(), iter); |
| 1073 return; | 1076 return; |
| 1074 } | 1077 } |
| 1075 | 1078 |
| 1076 if (rv < 0) { | 1079 if (rv < 0) { |
| 1077 keys_context->original_callback.Run(ErrorTypeStorage, | 1080 keys_context->original_callback.Run(ERROR_TYPE_STORAGE, |
| 1078 scoped_ptr<Requests>()); | 1081 scoped_ptr<Requests>()); |
| 1079 return; | 1082 return; |
| 1080 } | 1083 } |
| 1081 | 1084 |
| 1082 if (backend_state_ != BACKEND_OPEN) { | 1085 if (backend_state_ != BACKEND_OPEN) { |
| 1083 keys_context->original_callback.Run(ErrorTypeNotFound, | 1086 keys_context->original_callback.Run(ERROR_TYPE_NOT_FOUND, |
| 1084 scoped_ptr<Requests>()); | 1087 scoped_ptr<Requests>()); |
| 1085 return; | 1088 return; |
| 1086 } | 1089 } |
| 1087 | 1090 |
| 1088 // Store the entry. | 1091 // Store the entry. |
| 1089 keys_context->entries.push_back(keys_context->enumerated_entry); | 1092 keys_context->entries.push_back(keys_context->enumerated_entry); |
| 1090 keys_context->enumerated_entry = NULL; | 1093 keys_context->enumerated_entry = NULL; |
| 1091 | 1094 |
| 1092 // Enumerate the next entry. | 1095 // Enumerate the next entry. |
| 1093 disk_cache::Backend::Iterator& iterator = *keys_context->backend_iterator; | 1096 disk_cache::Backend::Iterator& iterator = *keys_context->backend_iterator; |
| 1094 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry; | 1097 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry; |
| 1095 net::CompletionCallback open_entry_callback = base::Bind( | 1098 net::CompletionCallback open_entry_callback = base::Bind( |
| 1096 &ServiceWorkerCache::KeysDidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(), | 1099 &ServiceWorkerCache::KeysDidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(), |
| 1097 base::Passed(keys_context.Pass())); | 1100 base::Passed(keys_context.Pass())); |
| 1098 | 1101 |
| 1099 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); | 1102 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); |
| 1100 | 1103 |
| 1101 if (rv != net::ERR_IO_PENDING) | 1104 if (rv != net::ERR_IO_PENDING) |
| 1102 open_entry_callback.Run(rv); | 1105 open_entry_callback.Run(rv); |
| 1103 } | 1106 } |
| 1104 | 1107 |
| 1105 void ServiceWorkerCache::KeysProcessNextEntry( | 1108 void ServiceWorkerCache::KeysProcessNextEntry( |
| 1106 scoped_ptr<KeysContext> keys_context, | 1109 scoped_ptr<KeysContext> keys_context, |
| 1107 const Entries::iterator& iter) { | 1110 const Entries::iterator& iter) { |
| 1108 if (iter == keys_context->entries.end()) { | 1111 if (iter == keys_context->entries.end()) { |
| 1109 // All done. Return all of the keys. | 1112 // All done. Return all of the keys. |
| 1110 keys_context->original_callback.Run(ErrorTypeOK, | 1113 keys_context->original_callback.Run(ERROR_TYPE_OK, |
| 1111 keys_context->out_keys.Pass()); | 1114 keys_context->out_keys.Pass()); |
| 1112 return; | 1115 return; |
| 1113 } | 1116 } |
| 1114 | 1117 |
| 1115 ReadMetadata(*iter, base::Bind(&ServiceWorkerCache::KeysDidReadMetadata, | 1118 ReadMetadata(*iter, base::Bind(&ServiceWorkerCache::KeysDidReadMetadata, |
| 1116 weak_ptr_factory_.GetWeakPtr(), | 1119 weak_ptr_factory_.GetWeakPtr(), |
| 1117 base::Passed(keys_context.Pass()), iter)); | 1120 base::Passed(keys_context.Pass()), iter)); |
| 1118 } | 1121 } |
| 1119 | 1122 |
| 1120 void ServiceWorkerCache::KeysDidReadMetadata( | 1123 void ServiceWorkerCache::KeysDidReadMetadata( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 create_cache_callback); | 1188 create_cache_callback); |
| 1186 if (rv != net::ERR_IO_PENDING) | 1189 if (rv != net::ERR_IO_PENDING) |
| 1187 create_cache_callback.Run(rv); | 1190 create_cache_callback.Run(rv); |
| 1188 } | 1191 } |
| 1189 | 1192 |
| 1190 void ServiceWorkerCache::CreateBackendDidCreate( | 1193 void ServiceWorkerCache::CreateBackendDidCreate( |
| 1191 const ServiceWorkerCache::ErrorCallback& callback, | 1194 const ServiceWorkerCache::ErrorCallback& callback, |
| 1192 scoped_ptr<ScopedBackendPtr> backend_ptr, | 1195 scoped_ptr<ScopedBackendPtr> backend_ptr, |
| 1193 int rv) { | 1196 int rv) { |
| 1194 if (rv != net::OK) { | 1197 if (rv != net::OK) { |
| 1195 callback.Run(ServiceWorkerCache::ErrorTypeStorage); | 1198 callback.Run(ServiceWorkerCache::ERROR_TYPE_STORAGE); |
| 1196 return; | 1199 return; |
| 1197 } | 1200 } |
| 1198 | 1201 |
| 1199 backend_ = backend_ptr->Pass(); | 1202 backend_ = backend_ptr->Pass(); |
| 1200 callback.Run(ServiceWorkerCache::ErrorTypeOK); | 1203 callback.Run(ServiceWorkerCache::ERROR_TYPE_OK); |
| 1201 } | 1204 } |
| 1202 | 1205 |
| 1203 void ServiceWorkerCache::InitBackend() { | 1206 void ServiceWorkerCache::InitBackend() { |
| 1204 DCHECK(backend_state_ == BACKEND_UNINITIALIZED); | 1207 DCHECK(backend_state_ == BACKEND_UNINITIALIZED); |
| 1205 | 1208 |
| 1206 if (initializing_) | 1209 if (initializing_) |
| 1207 return; | 1210 return; |
| 1208 | 1211 |
| 1209 DCHECK(!scheduler_->ScheduledOperations()); | 1212 DCHECK(!scheduler_->ScheduledOperations()); |
| 1210 initializing_ = true; | 1213 initializing_ = true; |
| 1211 | 1214 |
| 1212 scheduler_->ScheduleOperation(base::Bind( | 1215 scheduler_->ScheduleOperation(base::Bind( |
| 1213 &ServiceWorkerCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(), | 1216 &ServiceWorkerCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(), |
| 1214 base::Bind(&ServiceWorkerCache::InitDone, | 1217 base::Bind(&ServiceWorkerCache::InitDone, |
| 1215 weak_ptr_factory_.GetWeakPtr()))); | 1218 weak_ptr_factory_.GetWeakPtr()))); |
| 1216 } | 1219 } |
| 1217 | 1220 |
| 1218 void ServiceWorkerCache::InitDone(ErrorType error) { | 1221 void ServiceWorkerCache::InitDone(ErrorType error) { |
| 1219 initializing_ = false; | 1222 initializing_ = false; |
| 1220 backend_state_ = (error == ErrorTypeOK && backend_ && | 1223 backend_state_ = (error == ERROR_TYPE_OK && backend_ && |
| 1221 backend_state_ == BACKEND_UNINITIALIZED) | 1224 backend_state_ == BACKEND_UNINITIALIZED) |
| 1222 ? BACKEND_OPEN | 1225 ? BACKEND_OPEN |
| 1223 : BACKEND_CLOSED; | 1226 : BACKEND_CLOSED; |
| 1227 |
| 1228 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", error, |
| 1229 ErrorType::ERROR_TYPE_LAST + 1); |
| 1230 |
| 1224 scheduler_->CompleteOperationAndRunNext(); | 1231 scheduler_->CompleteOperationAndRunNext(); |
| 1225 } | 1232 } |
| 1226 | 1233 |
| 1227 void ServiceWorkerCache::PendingClosure(const base::Closure& callback) { | 1234 void ServiceWorkerCache::PendingClosure(const base::Closure& callback) { |
| 1228 base::WeakPtr<ServiceWorkerCache> cache = weak_ptr_factory_.GetWeakPtr(); | 1235 base::WeakPtr<ServiceWorkerCache> cache = weak_ptr_factory_.GetWeakPtr(); |
| 1229 | 1236 |
| 1230 callback.Run(); | 1237 callback.Run(); |
| 1231 if (cache) | 1238 if (cache) |
| 1232 scheduler_->CompleteOperationAndRunNext(); | 1239 scheduler_->CompleteOperationAndRunNext(); |
| 1233 } | 1240 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1258 ErrorType error, | 1265 ErrorType error, |
| 1259 scoped_ptr<Requests> requests) { | 1266 scoped_ptr<Requests> requests) { |
| 1260 base::WeakPtr<ServiceWorkerCache> cache = weak_ptr_factory_.GetWeakPtr(); | 1267 base::WeakPtr<ServiceWorkerCache> cache = weak_ptr_factory_.GetWeakPtr(); |
| 1261 | 1268 |
| 1262 callback.Run(error, requests.Pass()); | 1269 callback.Run(error, requests.Pass()); |
| 1263 if (cache) | 1270 if (cache) |
| 1264 scheduler_->CompleteOperationAndRunNext(); | 1271 scheduler_->CompleteOperationAndRunNext(); |
| 1265 } | 1272 } |
| 1266 | 1273 |
| 1267 } // namespace content | 1274 } // namespace content |
| OLD | NEW |