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

Side by Side Diff: content/browser/download/download_item_impl.cc

Issue 74523002: [Downloads] Update origin info after each response. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better descriptions. Created 7 years 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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 case DOWNLOAD_INTERRUPT_REASON_USER_CANCELED: 889 case DOWNLOAD_INTERRUPT_REASON_USER_CANCELED:
890 case DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED: 890 case DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED:
891 case DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED: 891 case DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED:
892 mode = RESUME_MODE_INVALID; 892 mode = RESUME_MODE_INVALID;
893 break; 893 break;
894 } 894 }
895 895
896 return mode; 896 return mode;
897 } 897 }
898 898
899 void DownloadItemImpl::MergeOriginInfoOnResume(
900 const DownloadCreateInfo& new_create_info) {
901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
902 DCHECK_EQ(RESUMING_INTERNAL, state_);
903 DCHECK(!new_create_info.url_chain.empty());
904
905 // We are going to tack on any new redirects to our list of redirects.
906 // When a download is resumed, the URL used for the resumption request is the
907 // one at the end of the previous redirect chain. Tacking additional redirects
908 // to the end of this chain ensures that:
909 // - If the download needs to be resumed again, the ETag/Last-Modified headers
910 // will be used with the last server that sent them to us.
911 // - The redirect chain contains all the servers that were involved in this
912 // download since the initial request, in order.
913 std::vector<GURL>::const_iterator chain_iter =
914 new_create_info.url_chain.begin();
915 if (*chain_iter == url_chain_.back())
916 ++chain_iter;
917
918 // Record some stats. If the precondition failed (the server returned
919 // HTTP_PRECONDITION_FAILED), then the download will automatically retried as
920 // a full request rather than a partial. Full restarts clobber validators.
921 int origin_state = 0;
922 if (chain_iter != new_create_info.url_chain.end())
923 origin_state |= ORIGIN_STATE_ON_RESUMPTION_ADDITIONAL_REDIRECTS;
924 if (etag_ != new_create_info.etag ||
925 last_modified_time_ != new_create_info.last_modified)
926 origin_state |= ORIGIN_STATE_ON_RESUMPTION_VALIDATORS_CHANGED;
927 if (content_disposition_ != new_create_info.content_disposition)
928 origin_state |= ORIGIN_STATE_ON_RESUMPTION_CONTENT_DISPOSITION_CHANGED;
929 RecordOriginStateOnResumption(new_create_info.save_info->offset != 0,
930 origin_state);
931
932 url_chain_.insert(
933 url_chain_.end(), chain_iter, new_create_info.url_chain.end());
934 etag_ = new_create_info.etag;
935 last_modified_time_ = new_create_info.last_modified;
936 content_disposition_ = new_create_info.content_disposition;
937
938 // Don't update observers. This method is expected to be called just before a
939 // DownloadFile is created and Start() is called. The observers will be
940 // notified when the download transitions to the IN_PROGRESS state.
941 }
942
899 void DownloadItemImpl::NotifyRemoved() { 943 void DownloadItemImpl::NotifyRemoved() {
900 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); 944 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this));
901 } 945 }
902 946
903 void DownloadItemImpl::OnDownloadedFileRemoved() { 947 void DownloadItemImpl::OnDownloadedFileRemoved() {
904 file_externally_removed_ = true; 948 file_externally_removed_ = true;
905 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 949 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
906 UpdateObservers(); 950 UpdateObservers();
907 } 951 }
908 952
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 case RESUME_MODE_USER_CONTINUE: 1748 case RESUME_MODE_USER_CONTINUE:
1705 return "USER_CONTINUE"; 1749 return "USER_CONTINUE";
1706 case RESUME_MODE_USER_RESTART: 1750 case RESUME_MODE_USER_RESTART:
1707 return "USER_RESTART"; 1751 return "USER_RESTART";
1708 } 1752 }
1709 NOTREACHED() << "Unknown resume mode " << mode; 1753 NOTREACHED() << "Unknown resume mode " << mode;
1710 return "unknown"; 1754 return "unknown";
1711 } 1755 }
1712 1756
1713 } // namespace content 1757 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698