OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/browser/appcache/appcache_update_job.h" | 5 #include "webkit/browser/appcache/appcache_update_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 void SendProgressNotifications( | 69 void SendProgressNotifications( |
70 const GURL& url, int num_total, int num_complete) { | 70 const GURL& url, int num_total, int num_complete) { |
71 for (NotifyHostMap::iterator it = hosts_to_notify.begin(); | 71 for (NotifyHostMap::iterator it = hosts_to_notify.begin(); |
72 it != hosts_to_notify.end(); ++it) { | 72 it != hosts_to_notify.end(); ++it) { |
73 AppCacheFrontend* frontend = it->first; | 73 AppCacheFrontend* frontend = it->first; |
74 frontend->OnProgressEventRaised(it->second, url, | 74 frontend->OnProgressEventRaised(it->second, url, |
75 num_total, num_complete); | 75 num_total, num_complete); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void SendErrorNotifications(const std::string& error_message) { | 79 void SendErrorNotifications(const std::string& error_message, |
80 appcache::ErrorReason reason, | |
81 const GURL& url, | |
82 int status) { | |
80 DCHECK(!error_message.empty()); | 83 DCHECK(!error_message.empty()); |
81 for (NotifyHostMap::iterator it = hosts_to_notify.begin(); | 84 for (NotifyHostMap::iterator it = hosts_to_notify.begin(); |
82 it != hosts_to_notify.end(); ++it) { | 85 it != hosts_to_notify.end(); ++it) { |
83 AppCacheFrontend* frontend = it->first; | 86 AppCacheFrontend* frontend = it->first; |
84 frontend->OnErrorEventRaised(it->second, error_message); | 87 frontend->OnErrorEventRaised( |
88 it->second, error_message, reason, url, status); | |
85 } | 89 } |
86 } | 90 } |
87 | 91 |
88 private: | 92 private: |
89 NotifyHostMap hosts_to_notify; | 93 NotifyHostMap hosts_to_notify; |
90 }; | 94 }; |
91 | 95 |
92 AppCacheUpdateJob::UrlToFetch::UrlToFetch(const GURL& url, | 96 AppCacheUpdateJob::UrlToFetch::UrlToFetch(const GURL& url, |
93 bool checked, | 97 bool checked, |
94 AppCacheResponseInfo* info) | 98 AppCacheResponseInfo* info) |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 } | 417 } |
414 | 418 |
415 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { | 419 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { |
416 AppCacheResponseWriter* writer = | 420 AppCacheResponseWriter* writer = |
417 storage_->CreateResponseWriter(manifest_url_, | 421 storage_->CreateResponseWriter(manifest_url_, |
418 group_->group_id()); | 422 group_->group_id()); |
419 stored_response_ids_.push_back(writer->response_id()); | 423 stored_response_ids_.push_back(writer->response_id()); |
420 return writer; | 424 return writer; |
421 } | 425 } |
422 | 426 |
423 void AppCacheUpdateJob::HandleCacheFailure( | 427 void AppCacheUpdateJob::HandleCacheFailure(const std::string& error_message, |
424 const std::string& error_message, | 428 ErrorReason reason, |
425 ResultType result) { | 429 const GURL& resource_url, |
430 int resource_status, | |
431 ResultType result) { | |
426 // 6.9.4 cache failure steps 2-8. | 432 // 6.9.4 cache failure steps 2-8. |
427 DCHECK(internal_state_ != CACHE_FAILURE); | 433 DCHECK(internal_state_ != CACHE_FAILURE); |
428 DCHECK(!error_message.empty()); | 434 DCHECK(!error_message.empty()); |
429 DCHECK(result != UPDATE_OK); | 435 DCHECK(result != UPDATE_OK); |
430 internal_state_ = CACHE_FAILURE; | 436 internal_state_ = CACHE_FAILURE; |
431 CancelAllUrlFetches(); | 437 CancelAllUrlFetches(); |
432 CancelAllMasterEntryFetches(error_message); | 438 // TODO: Should both of these errors be generated? |
michaeln
2014/02/27 23:16:06
This should be ok, CancelAllMasterEntryFetches is
| |
433 NotifyAllError(error_message); | 439 CancelAllMasterEntryFetches( |
440 error_message, reason, resource_url, resource_status); | |
441 NotifyAllError(error_message, reason, resource_url, resource_status); | |
434 DiscardInprogressCache(); | 442 DiscardInprogressCache(); |
435 internal_state_ = COMPLETED; | 443 internal_state_ = COMPLETED; |
436 AppCacheHistograms::CountUpdateJobResult( | 444 AppCacheHistograms::CountUpdateJobResult( |
437 result, manifest_url_.GetOrigin()); | 445 result, manifest_url_.GetOrigin()); |
438 DeleteSoon(); // To unwind the stack prior to deletion. | 446 DeleteSoon(); // To unwind the stack prior to deletion. |
439 } | 447 } |
440 | 448 |
441 void AppCacheUpdateJob::FetchManifest(bool is_first_fetch) { | 449 void AppCacheUpdateJob::FetchManifest(bool is_first_fetch) { |
442 DCHECK(!manifest_fetcher_); | 450 DCHECK(!manifest_fetcher_); |
443 manifest_fetcher_ = new URLFetcher( | 451 manifest_fetcher_ = new URLFetcher( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 ContinueHandleManifestFetchCompleted(true); | 499 ContinueHandleManifestFetchCompleted(true); |
492 } else if (response_code == 304 && update_type_ == UPGRADE_ATTEMPT) { | 500 } else if (response_code == 304 && update_type_ == UPGRADE_ATTEMPT) { |
493 ContinueHandleManifestFetchCompleted(false); | 501 ContinueHandleManifestFetchCompleted(false); |
494 } else if ((response_code == 404 || response_code == 410) && | 502 } else if ((response_code == 404 || response_code == 410) && |
495 update_type_ == UPGRADE_ATTEMPT) { | 503 update_type_ == UPGRADE_ATTEMPT) { |
496 storage_->MakeGroupObsolete(group_, this); // async | 504 storage_->MakeGroupObsolete(group_, this); // async |
497 } else { | 505 } else { |
498 const char* kFormatString = "Manifest fetch failed (%d) %s"; | 506 const char* kFormatString = "Manifest fetch failed (%d) %s"; |
499 std::string message = FormatUrlErrorMessage( | 507 std::string message = FormatUrlErrorMessage( |
500 kFormatString, manifest_url_, fetcher->result(), response_code); | 508 kFormatString, manifest_url_, fetcher->result(), response_code); |
501 HandleCacheFailure(message, fetcher->result()); | 509 HandleCacheFailure(message, |
510 ERROR_MANIFEST_FETCH, | |
511 manifest_url_, | |
512 response_code, | |
513 fetcher->result()); | |
502 } | 514 } |
503 } | 515 } |
504 | 516 |
505 void AppCacheUpdateJob::OnGroupMadeObsolete(AppCacheGroup* group, | 517 void AppCacheUpdateJob::OnGroupMadeObsolete(AppCacheGroup* group, |
506 bool success) { | 518 bool success) { |
507 DCHECK(master_entry_fetches_.empty()); | 519 DCHECK(master_entry_fetches_.empty()); |
508 CancelAllMasterEntryFetches("The cache has been made obsolete, " | 520 CancelAllMasterEntryFetches( |
509 "the manifest file returned 404 or 410"); | 521 "The cache has been made obsolete, " |
522 "the manifest file returned 404 or 410", | |
523 ERROR_MANIFEST_FETCH, | |
michaeln
2014/02/27 23:16:06
s/b ERROR_MANIFEST_OBSOLETE?
This is another of t
jsbell
2014/02/28 22:46:00
Whoops, yes.
| |
524 // TODO: Can we populate these correctly? | |
525 GURL(), | |
michaeln
2014/02/27 23:16:06
Maybe we shouldn't populate the url attribute for
jsbell
2014/02/28 22:46:00
Agreed. Given that the message has "404 or 410" I
| |
526 0); | |
510 if (success) { | 527 if (success) { |
511 DCHECK(group->is_obsolete()); | 528 DCHECK(group->is_obsolete()); |
512 NotifyAllAssociatedHosts(OBSOLETE_EVENT); | 529 NotifyAllAssociatedHosts(OBSOLETE_EVENT); |
513 internal_state_ = COMPLETED; | 530 internal_state_ = COMPLETED; |
514 MaybeCompleteUpdate(); | 531 MaybeCompleteUpdate(); |
515 } else { | 532 } else { |
516 // Treat failure to mark group obsolete as a cache failure. | 533 // Treat failure to mark group obsolete as a cache failure. |
517 HandleCacheFailure("Failed to mark the cache as obsolete", DB_ERROR); | 534 HandleCacheFailure("Failed to mark the cache as obsolete", |
535 ERROR_INTERNAL, | |
536 GURL(), | |
537 0, | |
538 DB_ERROR); | |
518 } | 539 } |
519 } | 540 } |
520 | 541 |
521 void AppCacheUpdateJob::ContinueHandleManifestFetchCompleted(bool changed) { | 542 void AppCacheUpdateJob::ContinueHandleManifestFetchCompleted(bool changed) { |
522 DCHECK(internal_state_ == FETCH_MANIFEST); | 543 DCHECK(internal_state_ == FETCH_MANIFEST); |
523 | 544 |
524 if (!changed) { | 545 if (!changed) { |
525 DCHECK(update_type_ == UPGRADE_ATTEMPT); | 546 DCHECK(update_type_ == UPGRADE_ATTEMPT); |
526 internal_state_ = NO_UPDATE; | 547 internal_state_ = NO_UPDATE; |
527 | 548 |
528 // Wait for pending master entries to download. | 549 // Wait for pending master entries to download. |
529 FetchMasterEntries(); | 550 FetchMasterEntries(); |
530 MaybeCompleteUpdate(); // if not done, run async 6.9.4 step 7 substeps | 551 MaybeCompleteUpdate(); // if not done, run async 6.9.4 step 7 substeps |
531 return; | 552 return; |
532 } | 553 } |
533 | 554 |
534 Manifest manifest; | 555 Manifest manifest; |
535 if (!ParseManifest(manifest_url_, manifest_data_.data(), | 556 if (!ParseManifest(manifest_url_, manifest_data_.data(), |
536 manifest_data_.length(), manifest)) { | 557 manifest_data_.length(), manifest)) { |
537 const char* kFormatString = "Failed to parse manifest %s"; | 558 const char* kFormatString = "Failed to parse manifest %s"; |
538 const std::string message = base::StringPrintf(kFormatString, | 559 const std::string message = base::StringPrintf(kFormatString, |
539 manifest_url_.spec().c_str()); | 560 manifest_url_.spec().c_str()); |
540 HandleCacheFailure(message, MANIFEST_ERROR); | 561 HandleCacheFailure( |
562 message, ERROR_MANIFEST_INVALID, manifest_url_, 0, MANIFEST_ERROR); | |
541 VLOG(1) << message; | 563 VLOG(1) << message; |
542 return; | 564 return; |
543 } | 565 } |
544 | 566 |
545 // Proceed with update process. Section 6.9.4 steps 8-20. | 567 // Proceed with update process. Section 6.9.4 steps 8-20. |
546 internal_state_ = DOWNLOADING; | 568 internal_state_ = DOWNLOADING; |
547 inprogress_cache_ = new AppCache(storage_, storage_->NewCacheId()); | 569 inprogress_cache_ = new AppCache(storage_, storage_->NewCacheId()); |
548 BuildUrlFileList(manifest); | 570 BuildUrlFileList(manifest); |
549 inprogress_cache_->InitializeWithManifest(&manifest); | 571 inprogress_cache_->InitializeWithManifest(&manifest); |
550 | 572 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 if (entry.IsExplicit() || entry.IsFallback() || entry.IsIntercept()) { | 626 if (entry.IsExplicit() || entry.IsFallback() || entry.IsIntercept()) { |
605 if (response_code == 304 && fetcher->existing_entry().has_response_id()) { | 627 if (response_code == 304 && fetcher->existing_entry().has_response_id()) { |
606 // Keep the existing response. | 628 // Keep the existing response. |
607 entry.set_response_id(fetcher->existing_entry().response_id()); | 629 entry.set_response_id(fetcher->existing_entry().response_id()); |
608 entry.set_response_size(fetcher->existing_entry().response_size()); | 630 entry.set_response_size(fetcher->existing_entry().response_size()); |
609 inprogress_cache_->AddOrModifyEntry(url, entry); | 631 inprogress_cache_->AddOrModifyEntry(url, entry); |
610 } else { | 632 } else { |
611 const char* kFormatString = "Resource fetch failed (%d) %s"; | 633 const char* kFormatString = "Resource fetch failed (%d) %s"; |
612 std::string message = FormatUrlErrorMessage( | 634 std::string message = FormatUrlErrorMessage( |
613 kFormatString, url, fetcher->result(), response_code); | 635 kFormatString, url, fetcher->result(), response_code); |
614 HandleCacheFailure(message, fetcher->result()); | 636 HandleCacheFailure(message, |
michaeln
2014/02/27 23:16:06
There are a handful of reasons a fetcher could hav
jsbell
2014/02/28 22:46:00
^^^ combined with response_code, I think a single
| |
637 ERROR_RESOURCE_FETCH, | |
638 url, | |
639 response_code, | |
640 fetcher->result()); | |
615 return; | 641 return; |
616 } | 642 } |
617 } else if (response_code == 404 || response_code == 410) { | 643 } else if (response_code == 404 || response_code == 410) { |
618 // Entry is skipped. They are dropped from the cache. | 644 // Entry is skipped. They are dropped from the cache. |
619 } else if (update_type_ == UPGRADE_ATTEMPT && | 645 } else if (update_type_ == UPGRADE_ATTEMPT && |
620 fetcher->existing_entry().has_response_id()) { | 646 fetcher->existing_entry().has_response_id()) { |
621 // Keep the existing response. | 647 // Keep the existing response. |
622 // TODO(michaeln): Not sure this is a good idea. This is spec compliant | 648 // TODO(michaeln): Not sure this is a good idea. This is spec compliant |
623 // but the old resource may or may not be compatible with the new contents | 649 // but the old resource may or may not be compatible with the new contents |
624 // of the cache. Impossible to know one way or the other. | 650 // of the cache. Impossible to know one way or the other. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 if (inprogress_cache_.get()) | 715 if (inprogress_cache_.get()) |
690 host->AssociateNoCache(GURL()); | 716 host->AssociateNoCache(GURL()); |
691 | 717 |
692 host->RemoveObserver(this); | 718 host->RemoveObserver(this); |
693 } | 719 } |
694 hosts.clear(); | 720 hosts.clear(); |
695 | 721 |
696 const char* kFormatString = "Manifest fetch failed (%d) %s"; | 722 const char* kFormatString = "Manifest fetch failed (%d) %s"; |
697 std::string message = FormatUrlErrorMessage( | 723 std::string message = FormatUrlErrorMessage( |
698 kFormatString, request->url(), fetcher->result(), response_code); | 724 kFormatString, request->url(), fetcher->result(), response_code); |
699 host_notifier.SendErrorNotifications(message); | 725 host_notifier.SendErrorNotifications( |
726 message, ERROR_MANIFEST_FETCH, request->url(), response_code); | |
700 | 727 |
701 // In downloading case, update result is different if all master entries | 728 // In downloading case, update result is different if all master entries |
702 // failed vs. only some failing. | 729 // failed vs. only some failing. |
703 if (inprogress_cache_.get()) { | 730 if (inprogress_cache_.get()) { |
704 // Only count successful downloads to know if all master entries failed. | 731 // Only count successful downloads to know if all master entries failed. |
705 pending_master_entries_.erase(found); | 732 pending_master_entries_.erase(found); |
706 --master_entries_completed_; | 733 --master_entries_completed_; |
707 | 734 |
708 // Section 6.9.4, step 22.3. | 735 // Section 6.9.4, step 22.3. |
709 if (update_type_ == CACHE_ATTEMPT && pending_master_entries_.empty()) { | 736 if (update_type_ == CACHE_ATTEMPT && pending_master_entries_.empty()) { |
710 HandleCacheFailure(message, fetcher->result()); | 737 // TODO: Is this a duplicate error? |
738 HandleCacheFailure(message, | |
739 ERROR_MANIFEST_FETCH, | |
740 request->url(), | |
741 response_code, | |
742 fetcher->result()); | |
711 return; | 743 return; |
712 } | 744 } |
713 } | 745 } |
714 } | 746 } |
715 | 747 |
716 DCHECK(internal_state_ != CACHE_FAILURE); | 748 DCHECK(internal_state_ != CACHE_FAILURE); |
717 FetchMasterEntries(); | 749 FetchMasterEntries(); |
718 MaybeCompleteUpdate(); | 750 MaybeCompleteUpdate(); |
719 } | 751 } |
720 | 752 |
(...skipping 21 matching lines...) Expand all Loading... | |
742 io_buffer.get(), | 774 io_buffer.get(), |
743 base::Bind(&AppCacheUpdateJob::OnManifestInfoWriteComplete, | 775 base::Bind(&AppCacheUpdateJob::OnManifestInfoWriteComplete, |
744 base::Unretained(this))); | 776 base::Unretained(this))); |
745 } | 777 } |
746 } else { | 778 } else { |
747 VLOG(1) << "Request status: " << request->status().status() | 779 VLOG(1) << "Request status: " << request->status().status() |
748 << " error: " << request->status().error() | 780 << " error: " << request->status().error() |
749 << " response code: " << response_code; | 781 << " response code: " << response_code; |
750 ScheduleUpdateRetry(kRerunDelayMs); | 782 ScheduleUpdateRetry(kRerunDelayMs); |
751 if (response_code == 200) { | 783 if (response_code == 200) { |
752 HandleCacheFailure("Manifest changed during update", MANIFEST_ERROR); | 784 HandleCacheFailure("Manifest changed during update", |
785 ERROR_MANIFEST_CHANGED, | |
786 manifest_url_, | |
787 response_code, | |
788 MANIFEST_ERROR); | |
753 } else { | 789 } else { |
754 const char* kFormatString = "Manifest re-fetch failed (%d) %s"; | 790 const char* kFormatString = "Manifest re-fetch failed (%d) %s"; |
755 std::string message = FormatUrlErrorMessage( | 791 std::string message = FormatUrlErrorMessage( |
756 kFormatString, manifest_url_, fetcher->result(), response_code); | 792 kFormatString, manifest_url_, fetcher->result(), response_code); |
757 HandleCacheFailure(message, fetcher->result()); | 793 HandleCacheFailure(message, |
794 ERROR_MANIFEST_FETCH, | |
795 manifest_url_, | |
796 response_code, | |
797 fetcher->result()); | |
758 } | 798 } |
759 } | 799 } |
760 } | 800 } |
761 | 801 |
762 void AppCacheUpdateJob::OnManifestInfoWriteComplete(int result) { | 802 void AppCacheUpdateJob::OnManifestInfoWriteComplete(int result) { |
763 if (result > 0) { | 803 if (result > 0) { |
764 scoped_refptr<net::StringIOBuffer> io_buffer( | 804 scoped_refptr<net::StringIOBuffer> io_buffer( |
765 new net::StringIOBuffer(manifest_data_)); | 805 new net::StringIOBuffer(manifest_data_)); |
766 manifest_response_writer_->WriteData( | 806 manifest_response_writer_->WriteData( |
767 io_buffer.get(), | 807 io_buffer.get(), |
768 manifest_data_.length(), | 808 manifest_data_.length(), |
769 base::Bind(&AppCacheUpdateJob::OnManifestDataWriteComplete, | 809 base::Bind(&AppCacheUpdateJob::OnManifestDataWriteComplete, |
770 base::Unretained(this))); | 810 base::Unretained(this))); |
771 } else { | 811 } else { |
772 HandleCacheFailure("Failed to write the manifest headers to storage", | 812 HandleCacheFailure("Failed to write the manifest headers to storage", |
813 ERROR_INTERNAL, | |
814 GURL(), | |
815 0, | |
773 DISKCACHE_ERROR); | 816 DISKCACHE_ERROR); |
774 } | 817 } |
775 } | 818 } |
776 | 819 |
777 void AppCacheUpdateJob::OnManifestDataWriteComplete(int result) { | 820 void AppCacheUpdateJob::OnManifestDataWriteComplete(int result) { |
778 if (result > 0) { | 821 if (result > 0) { |
779 AppCacheEntry entry(AppCacheEntry::MANIFEST, | 822 AppCacheEntry entry(AppCacheEntry::MANIFEST, |
780 manifest_response_writer_->response_id(), | 823 manifest_response_writer_->response_id(), |
781 manifest_response_writer_->amount_written()); | 824 manifest_response_writer_->amount_written()); |
782 if (!inprogress_cache_->AddOrModifyEntry(manifest_url_, entry)) | 825 if (!inprogress_cache_->AddOrModifyEntry(manifest_url_, entry)) |
783 duplicate_response_ids_.push_back(entry.response_id()); | 826 duplicate_response_ids_.push_back(entry.response_id()); |
784 StoreGroupAndCache(); | 827 StoreGroupAndCache(); |
785 } else { | 828 } else { |
786 HandleCacheFailure("Failed to write the manifest data to storage", | 829 HandleCacheFailure("Failed to write the manifest data to storage", |
830 ERROR_INTERNAL, | |
831 GURL(), | |
832 0, | |
787 DISKCACHE_ERROR); | 833 DISKCACHE_ERROR); |
788 } | 834 } |
789 } | 835 } |
790 | 836 |
791 void AppCacheUpdateJob::StoreGroupAndCache() { | 837 void AppCacheUpdateJob::StoreGroupAndCache() { |
792 DCHECK(stored_state_ == UNSTORED); | 838 DCHECK(stored_state_ == UNSTORED); |
793 stored_state_ = STORING; | 839 stored_state_ = STORING; |
794 scoped_refptr<AppCache> newest_cache; | 840 scoped_refptr<AppCache> newest_cache; |
795 if (inprogress_cache_.get()) | 841 if (inprogress_cache_.get()) |
796 newest_cache.swap(inprogress_cache_); | 842 newest_cache.swap(inprogress_cache_); |
(...skipping 21 matching lines...) Expand all Loading... | |
818 // and the proper cleanup to occur. | 864 // and the proper cleanup to occur. |
819 if (newest_cache != group->newest_complete_cache()) | 865 if (newest_cache != group->newest_complete_cache()) |
820 inprogress_cache_ = newest_cache; | 866 inprogress_cache_ = newest_cache; |
821 | 867 |
822 ResultType result = DB_ERROR; | 868 ResultType result = DB_ERROR; |
823 std::string message("Failed to commit new cache to storage"); | 869 std::string message("Failed to commit new cache to storage"); |
824 if (would_exceed_quota) { | 870 if (would_exceed_quota) { |
825 message.append(", would exceed quota"); | 871 message.append(", would exceed quota"); |
826 result = QUOTA_ERROR; | 872 result = QUOTA_ERROR; |
827 } | 873 } |
828 HandleCacheFailure(message, result); | 874 HandleCacheFailure( |
875 message, | |
876 would_exceed_quota ? ERROR_QUOTA_EXCEEDED : ERROR_INTERNAL, | |
877 GURL(), | |
878 0, | |
879 result); | |
829 } | 880 } |
830 } | 881 } |
831 | 882 |
832 void AppCacheUpdateJob::NotifySingleHost(AppCacheHost* host, | 883 void AppCacheUpdateJob::NotifySingleHost(AppCacheHost* host, |
833 EventID event_id) { | 884 EventID event_id) { |
834 std::vector<int> ids(1, host->host_id()); | 885 std::vector<int> ids(1, host->host_id()); |
835 host->frontend()->OnEventRaised(ids, event_id); | 886 host->frontend()->OnEventRaised(ids, event_id); |
836 } | 887 } |
837 | 888 |
838 void AppCacheUpdateJob::NotifyAllAssociatedHosts(EventID event_id) { | 889 void AppCacheUpdateJob::NotifyAllAssociatedHosts(EventID event_id) { |
839 HostNotifier host_notifier; | 890 HostNotifier host_notifier; |
840 AddAllAssociatedHostsToNotifier(&host_notifier); | 891 AddAllAssociatedHostsToNotifier(&host_notifier); |
841 host_notifier.SendNotifications(event_id); | 892 host_notifier.SendNotifications(event_id); |
842 } | 893 } |
843 | 894 |
844 void AppCacheUpdateJob::NotifyAllProgress(const GURL& url) { | 895 void AppCacheUpdateJob::NotifyAllProgress(const GURL& url) { |
845 HostNotifier host_notifier; | 896 HostNotifier host_notifier; |
846 AddAllAssociatedHostsToNotifier(&host_notifier); | 897 AddAllAssociatedHostsToNotifier(&host_notifier); |
847 host_notifier.SendProgressNotifications( | 898 host_notifier.SendProgressNotifications( |
848 url, url_file_list_.size(), url_fetches_completed_); | 899 url, url_file_list_.size(), url_fetches_completed_); |
849 } | 900 } |
850 | 901 |
851 void AppCacheUpdateJob::NotifyAllFinalProgress() { | 902 void AppCacheUpdateJob::NotifyAllFinalProgress() { |
852 DCHECK(url_file_list_.size() == url_fetches_completed_); | 903 DCHECK(url_file_list_.size() == url_fetches_completed_); |
853 NotifyAllProgress(GURL()); | 904 NotifyAllProgress(GURL()); |
854 } | 905 } |
855 | 906 |
856 void AppCacheUpdateJob::NotifyAllError(const std::string& error_message) { | 907 void AppCacheUpdateJob::NotifyAllError(const std::string& error_message, |
908 ErrorReason reason, | |
909 const GURL& resource_url, | |
910 int resource_status) { | |
857 HostNotifier host_notifier; | 911 HostNotifier host_notifier; |
858 AddAllAssociatedHostsToNotifier(&host_notifier); | 912 AddAllAssociatedHostsToNotifier(&host_notifier); |
859 host_notifier.SendErrorNotifications(error_message); | 913 host_notifier.SendErrorNotifications( |
914 error_message, reason, resource_url, resource_status); | |
860 } | 915 } |
861 | 916 |
862 void AppCacheUpdateJob::AddAllAssociatedHostsToNotifier( | 917 void AppCacheUpdateJob::AddAllAssociatedHostsToNotifier( |
863 HostNotifier* host_notifier) { | 918 HostNotifier* host_notifier) { |
864 // Collect hosts so we only send one notification per frontend. | 919 // Collect hosts so we only send one notification per frontend. |
865 // A host can only be associated with a single cache so no need to worry | 920 // A host can only be associated with a single cache so no need to worry |
866 // about duplicate hosts being added to the notifier. | 921 // about duplicate hosts being added to the notifier. |
867 if (inprogress_cache_.get()) { | 922 if (inprogress_cache_.get()) { |
868 DCHECK(internal_state_ == DOWNLOADING || internal_state_ == CACHE_FAILURE); | 923 DCHECK(internal_state_ == DOWNLOADING || internal_state_ == CACHE_FAILURE); |
869 host_notifier->AddHosts(inprogress_cache_->associated_hosts()); | 924 host_notifier->AddHosts(inprogress_cache_->associated_hosts()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 AppCacheEntry* entry = NULL; | 959 AppCacheEntry* entry = NULL; |
905 if (group_->newest_complete_cache()) | 960 if (group_->newest_complete_cache()) |
906 entry = group_->newest_complete_cache()->GetEntry(manifest_url_); | 961 entry = group_->newest_complete_cache()->GetEntry(manifest_url_); |
907 if (!entry) { | 962 if (!entry) { |
908 // TODO(michaeln): This is just a bandaid to avoid a crash. | 963 // TODO(michaeln): This is just a bandaid to avoid a crash. |
909 // http://code.google.com/p/chromium/issues/detail?id=95101 | 964 // http://code.google.com/p/chromium/issues/detail?id=95101 |
910 if (service_->storage() == storage_) { | 965 if (service_->storage() == storage_) { |
911 // Use a local variable because service_ is reset in HandleCacheFailure. | 966 // Use a local variable because service_ is reset in HandleCacheFailure. |
912 AppCacheService* service = service_; | 967 AppCacheService* service = service_; |
913 HandleCacheFailure("Manifest entry not found in existing cache", | 968 HandleCacheFailure("Manifest entry not found in existing cache", |
969 ERROR_INTERNAL, | |
970 GURL(), | |
971 0, | |
914 DB_ERROR); | 972 DB_ERROR); |
915 AppCacheHistograms::AddMissingManifestEntrySample(); | 973 AppCacheHistograms::AddMissingManifestEntrySample(); |
916 service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); | 974 service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); |
917 } | 975 } |
918 return; | 976 return; |
919 } | 977 } |
920 | 978 |
921 // Load manifest data from storage to compare against fetched manifest. | 979 // Load manifest data from storage to compare against fetched manifest. |
922 manifest_response_reader_.reset( | 980 manifest_response_reader_.reset( |
923 storage_->CreateResponseReader(manifest_url_, | 981 storage_->CreateResponseReader(manifest_url_, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 url, URLFetcher::MASTER_ENTRY_FETCH, this); | 1203 url, URLFetcher::MASTER_ENTRY_FETCH, this); |
1146 fetcher->Start(); | 1204 fetcher->Start(); |
1147 master_entry_fetches_.insert(PendingUrlFetches::value_type(url, fetcher)); | 1205 master_entry_fetches_.insert(PendingUrlFetches::value_type(url, fetcher)); |
1148 } | 1206 } |
1149 | 1207 |
1150 master_entries_to_fetch_.erase(master_entries_to_fetch_.begin()); | 1208 master_entries_to_fetch_.erase(master_entries_to_fetch_.begin()); |
1151 } | 1209 } |
1152 } | 1210 } |
1153 | 1211 |
1154 void AppCacheUpdateJob::CancelAllMasterEntryFetches( | 1212 void AppCacheUpdateJob::CancelAllMasterEntryFetches( |
1155 const std::string& error_message) { | 1213 const std::string& error_message, |
1214 ErrorReason reason, | |
1215 const GURL& resource_url, | |
1216 int resource_status) { | |
1156 // For now, cancel all in-progress fetches for master entries and pretend | 1217 // For now, cancel all in-progress fetches for master entries and pretend |
1157 // all master entries fetches have completed. | 1218 // all master entries fetches have completed. |
1158 // TODO(jennb): Delete this when update no longer fetches master entries | 1219 // TODO(jennb): Delete this when update no longer fetches master entries |
1159 // directly. | 1220 // directly. |
1160 | 1221 |
1161 // Cancel all in-progress fetches. | 1222 // Cancel all in-progress fetches. |
1162 for (PendingUrlFetches::iterator it = master_entry_fetches_.begin(); | 1223 for (PendingUrlFetches::iterator it = master_entry_fetches_.begin(); |
1163 it != master_entry_fetches_.end(); ++it) { | 1224 it != master_entry_fetches_.end(); ++it) { |
1164 delete it->second; | 1225 delete it->second; |
1165 master_entries_to_fetch_.insert(it->first); // back in unfetched list | 1226 master_entries_to_fetch_.insert(it->first); // back in unfetched list |
(...skipping 15 matching lines...) Expand all Loading... | |
1181 host_it != hosts.end(); ++host_it) { | 1242 host_it != hosts.end(); ++host_it) { |
1182 AppCacheHost* host = *host_it; | 1243 AppCacheHost* host = *host_it; |
1183 host->AssociateNoCache(GURL()); | 1244 host->AssociateNoCache(GURL()); |
1184 host_notifier.AddHost(host); | 1245 host_notifier.AddHost(host); |
1185 host->RemoveObserver(this); | 1246 host->RemoveObserver(this); |
1186 } | 1247 } |
1187 hosts.clear(); | 1248 hosts.clear(); |
1188 | 1249 |
1189 master_entries_to_fetch_.erase(master_entries_to_fetch_.begin()); | 1250 master_entries_to_fetch_.erase(master_entries_to_fetch_.begin()); |
1190 } | 1251 } |
1191 host_notifier.SendErrorNotifications(error_message); | 1252 host_notifier.SendErrorNotifications( |
1253 error_message, reason, resource_url, resource_status); | |
1192 } | 1254 } |
1193 | 1255 |
1194 bool AppCacheUpdateJob::MaybeLoadFromNewestCache(const GURL& url, | 1256 bool AppCacheUpdateJob::MaybeLoadFromNewestCache(const GURL& url, |
1195 AppCacheEntry& entry) { | 1257 AppCacheEntry& entry) { |
1196 if (update_type_ != UPGRADE_ATTEMPT) | 1258 if (update_type_ != UPGRADE_ATTEMPT) |
1197 return false; | 1259 return false; |
1198 | 1260 |
1199 AppCache* newest = group_->newest_complete_cache(); | 1261 AppCache* newest = group_->newest_complete_cache(); |
1200 AppCacheEntry* copy_me = newest->GetEntry(url); | 1262 AppCacheEntry* copy_me = newest->GetEntry(url); |
1201 if (!copy_me || !copy_me->has_response_id()) | 1263 if (!copy_me || !copy_me->has_response_id()) |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1425 | 1487 |
1426 // Break the connection with the group so the group cannot call delete | 1488 // Break the connection with the group so the group cannot call delete |
1427 // on this object after we've posted a task to delete ourselves. | 1489 // on this object after we've posted a task to delete ourselves. |
1428 group_->SetUpdateStatus(AppCacheGroup::IDLE); | 1490 group_->SetUpdateStatus(AppCacheGroup::IDLE); |
1429 group_ = NULL; | 1491 group_ = NULL; |
1430 | 1492 |
1431 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1493 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1432 } | 1494 } |
1433 | 1495 |
1434 } // namespace appcache | 1496 } // namespace appcache |
OLD | NEW |