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

Side by Side Diff: webkit/browser/appcache/appcache_update_job.cc

Issue 164933002: Expose details for appcache error events [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-up Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 const std::string& 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
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 const std::string& 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?
jsbell 2014/02/21 23:48:23 The code here will result in two errors - CancelAl
michaeln 2014/02/22 00:19:39 Like everything... not as simple as it should be.
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
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 "ManifestFetchFailed",
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 "CacheObsolete",
524 // TODO: Can we populate these correctly?
525 GURL(),
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 "FailedToMarkObsolete",
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, "InvalidManifest", 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
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,
637 "ResourceFetchFailed",
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
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, "ManifestFetchFailed", 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?
michaeln 2014/02/22 01:18:50 No duplicates, the recipients of the error sent by
738 HandleCacheFailure(message,
739 "ManifestFetchFailed",
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
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 "ManifestChanged",
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 "ManifestFetchFailed",
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 "InternalStorageError",
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 "InternalStorageError",
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 11 matching lines...) Expand all
808 bool success, 854 bool success,
809 bool would_exceed_quota) { 855 bool would_exceed_quota) {
810 DCHECK(stored_state_ == STORING); 856 DCHECK(stored_state_ == STORING);
811 if (success) { 857 if (success) {
812 stored_state_ = STORED; 858 stored_state_ = STORED;
813 MaybeCompleteUpdate(); // will definitely complete 859 MaybeCompleteUpdate(); // will definitely complete
814 } else { 860 } else {
815 // Restore inprogress_cache_ to get the proper events delivered 861 // Restore inprogress_cache_ to get the proper events delivered
816 // and the proper cleanup to occur. 862 // and the proper cleanup to occur.
817 if (newest_cache != group->newest_complete_cache()) 863 if (newest_cache != group->newest_complete_cache())
818 inprogress_cache_ = newest_cache; 864 inprogress_cache_ = newest_cache;
michaeln 2014/02/22 01:18:50 Hmmm... unrelated to this CL, but you know the Dis
819 865
820 ResultType result = DB_ERROR; 866 ResultType result = DB_ERROR;
821 std::string message("Failed to commit new cache to storage"); 867 std::string message("Failed to commit new cache to storage");
822 if (would_exceed_quota) { 868 if (would_exceed_quota) {
823 message.append(", would exceed quota"); 869 message.append(", would exceed quota");
824 result = QUOTA_ERROR; 870 result = QUOTA_ERROR;
825 } 871 }
826 HandleCacheFailure(message, result); 872 HandleCacheFailure(
873 message,
874 would_exceed_quota ? "QuotaError" : "InternalStorageError",
875 GURL(),
876 0,
877 result);
827 } 878 }
828 } 879 }
829 880
830 void AppCacheUpdateJob::NotifySingleHost(AppCacheHost* host, 881 void AppCacheUpdateJob::NotifySingleHost(AppCacheHost* host,
831 EventID event_id) { 882 EventID event_id) {
832 std::vector<int> ids(1, host->host_id()); 883 std::vector<int> ids(1, host->host_id());
833 host->frontend()->OnEventRaised(ids, event_id); 884 host->frontend()->OnEventRaised(ids, event_id);
834 } 885 }
835 886
836 void AppCacheUpdateJob::NotifyAllAssociatedHosts(EventID event_id) { 887 void AppCacheUpdateJob::NotifyAllAssociatedHosts(EventID event_id) {
837 HostNotifier host_notifier; 888 HostNotifier host_notifier;
838 AddAllAssociatedHostsToNotifier(&host_notifier); 889 AddAllAssociatedHostsToNotifier(&host_notifier);
839 host_notifier.SendNotifications(event_id); 890 host_notifier.SendNotifications(event_id);
840 } 891 }
841 892
842 void AppCacheUpdateJob::NotifyAllProgress(const GURL& url) { 893 void AppCacheUpdateJob::NotifyAllProgress(const GURL& url) {
843 HostNotifier host_notifier; 894 HostNotifier host_notifier;
844 AddAllAssociatedHostsToNotifier(&host_notifier); 895 AddAllAssociatedHostsToNotifier(&host_notifier);
845 host_notifier.SendProgressNotifications( 896 host_notifier.SendProgressNotifications(
846 url, url_file_list_.size(), url_fetches_completed_); 897 url, url_file_list_.size(), url_fetches_completed_);
847 } 898 }
848 899
849 void AppCacheUpdateJob::NotifyAllFinalProgress() { 900 void AppCacheUpdateJob::NotifyAllFinalProgress() {
850 DCHECK(url_file_list_.size() == url_fetches_completed_); 901 DCHECK(url_file_list_.size() == url_fetches_completed_);
851 NotifyAllProgress(GURL()); 902 NotifyAllProgress(GURL());
852 } 903 }
853 904
854 void AppCacheUpdateJob::NotifyAllError(const std::string& error_message) { 905 void AppCacheUpdateJob::NotifyAllError(const std::string& error_message,
906 const std::string& reason,
907 const GURL& resource_url,
908 int resource_status) {
855 HostNotifier host_notifier; 909 HostNotifier host_notifier;
856 AddAllAssociatedHostsToNotifier(&host_notifier); 910 AddAllAssociatedHostsToNotifier(&host_notifier);
857 host_notifier.SendErrorNotifications(error_message); 911 host_notifier.SendErrorNotifications(
912 error_message, reason, resource_url, resource_status);
858 } 913 }
859 914
860 void AppCacheUpdateJob::AddAllAssociatedHostsToNotifier( 915 void AppCacheUpdateJob::AddAllAssociatedHostsToNotifier(
861 HostNotifier* host_notifier) { 916 HostNotifier* host_notifier) {
862 // Collect hosts so we only send one notification per frontend. 917 // Collect hosts so we only send one notification per frontend.
863 // A host can only be associated with a single cache so no need to worry 918 // A host can only be associated with a single cache so no need to worry
864 // about duplicate hosts being added to the notifier. 919 // about duplicate hosts being added to the notifier.
865 if (inprogress_cache_.get()) { 920 if (inprogress_cache_.get()) {
866 DCHECK(internal_state_ == DOWNLOADING || internal_state_ == CACHE_FAILURE); 921 DCHECK(internal_state_ == DOWNLOADING || internal_state_ == CACHE_FAILURE);
867 host_notifier->AddHosts(inprogress_cache_->associated_hosts()); 922 host_notifier->AddHosts(inprogress_cache_->associated_hosts());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 AppCacheEntry* entry = NULL; 957 AppCacheEntry* entry = NULL;
903 if (group_->newest_complete_cache()) 958 if (group_->newest_complete_cache())
904 entry = group_->newest_complete_cache()->GetEntry(manifest_url_); 959 entry = group_->newest_complete_cache()->GetEntry(manifest_url_);
905 if (!entry) { 960 if (!entry) {
906 // TODO(michaeln): This is just a bandaid to avoid a crash. 961 // TODO(michaeln): This is just a bandaid to avoid a crash.
907 // http://code.google.com/p/chromium/issues/detail?id=95101 962 // http://code.google.com/p/chromium/issues/detail?id=95101
908 if (service_->storage() == storage_) { 963 if (service_->storage() == storage_) {
909 // Use a local variable because service_ is reset in HandleCacheFailure. 964 // Use a local variable because service_ is reset in HandleCacheFailure.
910 AppCacheService* service = service_; 965 AppCacheService* service = service_;
911 HandleCacheFailure("Manifest entry not found in existing cache", 966 HandleCacheFailure("Manifest entry not found in existing cache",
967 "InternalStorageError",
968 GURL(),
969 0,
912 DB_ERROR); 970 DB_ERROR);
913 AppCacheHistograms::AddMissingManifestEntrySample(); 971 AppCacheHistograms::AddMissingManifestEntrySample();
914 service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); 972 service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback());
915 } 973 }
916 return; 974 return;
917 } 975 }
918 976
919 // Load manifest data from storage to compare against fetched manifest. 977 // Load manifest data from storage to compare against fetched manifest.
920 manifest_response_reader_.reset( 978 manifest_response_reader_.reset(
921 storage_->CreateResponseReader(manifest_url_, 979 storage_->CreateResponseReader(manifest_url_,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 url, URLFetcher::MASTER_ENTRY_FETCH, this); 1201 url, URLFetcher::MASTER_ENTRY_FETCH, this);
1144 fetcher->Start(); 1202 fetcher->Start();
1145 master_entry_fetches_.insert(PendingUrlFetches::value_type(url, fetcher)); 1203 master_entry_fetches_.insert(PendingUrlFetches::value_type(url, fetcher));
1146 } 1204 }
1147 1205
1148 master_entries_to_fetch_.erase(master_entries_to_fetch_.begin()); 1206 master_entries_to_fetch_.erase(master_entries_to_fetch_.begin());
1149 } 1207 }
1150 } 1208 }
1151 1209
1152 void AppCacheUpdateJob::CancelAllMasterEntryFetches( 1210 void AppCacheUpdateJob::CancelAllMasterEntryFetches(
1153 const std::string& error_message) { 1211 const std::string& error_message,
1212 const std::string& reason,
1213 const GURL& resource_url,
1214 int resource_status) {
1154 // For now, cancel all in-progress fetches for master entries and pretend 1215 // For now, cancel all in-progress fetches for master entries and pretend
1155 // all master entries fetches have completed. 1216 // all master entries fetches have completed.
1156 // TODO(jennb): Delete this when update no longer fetches master entries 1217 // TODO(jennb): Delete this when update no longer fetches master entries
1157 // directly. 1218 // directly.
1158 1219
1159 // Cancel all in-progress fetches. 1220 // Cancel all in-progress fetches.
1160 for (PendingUrlFetches::iterator it = master_entry_fetches_.begin(); 1221 for (PendingUrlFetches::iterator it = master_entry_fetches_.begin();
1161 it != master_entry_fetches_.end(); ++it) { 1222 it != master_entry_fetches_.end(); ++it) {
1162 delete it->second; 1223 delete it->second;
1163 master_entries_to_fetch_.insert(it->first); // back in unfetched list 1224 master_entries_to_fetch_.insert(it->first); // back in unfetched list
(...skipping 15 matching lines...) Expand all
1179 host_it != hosts.end(); ++host_it) { 1240 host_it != hosts.end(); ++host_it) {
1180 AppCacheHost* host = *host_it; 1241 AppCacheHost* host = *host_it;
1181 host->AssociateNoCache(GURL()); 1242 host->AssociateNoCache(GURL());
1182 host_notifier.AddHost(host); 1243 host_notifier.AddHost(host);
1183 host->RemoveObserver(this); 1244 host->RemoveObserver(this);
1184 } 1245 }
1185 hosts.clear(); 1246 hosts.clear();
1186 1247
1187 master_entries_to_fetch_.erase(master_entries_to_fetch_.begin()); 1248 master_entries_to_fetch_.erase(master_entries_to_fetch_.begin());
1188 } 1249 }
1189 host_notifier.SendErrorNotifications(error_message); 1250 host_notifier.SendErrorNotifications(
1251 error_message, reason, resource_url, resource_status);
1190 } 1252 }
1191 1253
1192 bool AppCacheUpdateJob::MaybeLoadFromNewestCache(const GURL& url, 1254 bool AppCacheUpdateJob::MaybeLoadFromNewestCache(const GURL& url,
1193 AppCacheEntry& entry) { 1255 AppCacheEntry& entry) {
1194 if (update_type_ != UPGRADE_ATTEMPT) 1256 if (update_type_ != UPGRADE_ATTEMPT)
1195 return false; 1257 return false;
1196 1258
1197 AppCache* newest = group_->newest_complete_cache(); 1259 AppCache* newest = group_->newest_complete_cache();
1198 AppCacheEntry* copy_me = newest->GetEntry(url); 1260 AppCacheEntry* copy_me = newest->GetEntry(url);
1199 if (!copy_me || !copy_me->has_response_id()) 1261 if (!copy_me || !copy_me->has_response_id())
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 1473
1412 // Break the connection with the group so the group cannot call delete 1474 // Break the connection with the group so the group cannot call delete
1413 // on this object after we've posted a task to delete ourselves. 1475 // on this object after we've posted a task to delete ourselves.
1414 group_->SetUpdateStatus(AppCacheGroup::IDLE); 1476 group_->SetUpdateStatus(AppCacheGroup::IDLE);
1415 group_ = NULL; 1477 group_ = NULL;
1416 1478
1417 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1479 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1418 } 1480 }
1419 1481
1420 } // namespace appcache 1482 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698