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

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

Issue 2799333002: Clear the received slices in DownloadItemImpl when etag changed. (Closed)
Patch Set: Address the uma issue. Created 3 years, 8 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
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 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 // download since the initial request, in order. 1018 // download since the initial request, in order.
1019 std::vector<GURL>::const_iterator chain_iter = 1019 std::vector<GURL>::const_iterator chain_iter =
1020 new_create_info.url_chain.begin(); 1020 new_create_info.url_chain.begin();
1021 if (*chain_iter == url_chain_.back()) 1021 if (*chain_iter == url_chain_.back())
1022 ++chain_iter; 1022 ++chain_iter;
1023 1023
1024 // Record some stats. If the precondition failed (the server returned 1024 // Record some stats. If the precondition failed (the server returned
1025 // HTTP_PRECONDITION_FAILED), then the download will automatically retried as 1025 // HTTP_PRECONDITION_FAILED), then the download will automatically retried as
1026 // a full request rather than a partial. Full restarts clobber validators. 1026 // a full request rather than a partial. Full restarts clobber validators.
1027 int origin_state = 0; 1027 int origin_state = 0;
1028 bool is_partial = received_bytes_ > 0;
1028 if (chain_iter != new_create_info.url_chain.end()) 1029 if (chain_iter != new_create_info.url_chain.end())
1029 origin_state |= ORIGIN_STATE_ON_RESUMPTION_ADDITIONAL_REDIRECTS; 1030 origin_state |= ORIGIN_STATE_ON_RESUMPTION_ADDITIONAL_REDIRECTS;
1030 if (etag_ != new_create_info.etag || 1031 if (etag_ != new_create_info.etag ||
1031 last_modified_time_ != new_create_info.last_modified) 1032 last_modified_time_ != new_create_info.last_modified) {
1033 received_slices_.clear();
1034 received_bytes_ = 0;
1032 origin_state |= ORIGIN_STATE_ON_RESUMPTION_VALIDATORS_CHANGED; 1035 origin_state |= ORIGIN_STATE_ON_RESUMPTION_VALIDATORS_CHANGED;
1036 }
1033 if (content_disposition_ != new_create_info.content_disposition) 1037 if (content_disposition_ != new_create_info.content_disposition)
1034 origin_state |= ORIGIN_STATE_ON_RESUMPTION_CONTENT_DISPOSITION_CHANGED; 1038 origin_state |= ORIGIN_STATE_ON_RESUMPTION_CONTENT_DISPOSITION_CHANGED;
1035 RecordOriginStateOnResumption(received_bytes_ != 0, origin_state); 1039 RecordOriginStateOnResumption(is_partial, origin_state);
1036 1040
1037 url_chain_.insert( 1041 url_chain_.insert(
1038 url_chain_.end(), chain_iter, new_create_info.url_chain.end()); 1042 url_chain_.end(), chain_iter, new_create_info.url_chain.end());
1039 etag_ = new_create_info.etag; 1043 etag_ = new_create_info.etag;
1040 last_modified_time_ = new_create_info.last_modified; 1044 last_modified_time_ = new_create_info.last_modified;
1041 content_disposition_ = new_create_info.content_disposition; 1045 content_disposition_ = new_create_info.content_disposition;
1042 // It is possible that the previous download attempt failed right before the 1046 // It is possible that the previous download attempt failed right before the
1043 // response is received. Need to reset the MIME type. 1047 // response is received. Need to reset the MIME type.
1044 mime_type_ = new_create_info.mime_type; 1048 mime_type_ = new_create_info.mime_type;
1045 1049
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 job_->Start(); 1286 job_->Start();
1283 } 1287 }
1284 1288
1285 void DownloadItemImpl::StartDownload() { 1289 void DownloadItemImpl::StartDownload() {
1286 BrowserThread::PostTask( 1290 BrowserThread::PostTask(
1287 BrowserThread::FILE, FROM_HERE, 1291 BrowserThread::FILE, FROM_HERE,
1288 base::Bind(&DownloadFile::Initialize, 1292 base::Bind(&DownloadFile::Initialize,
1289 // Safe because we control download file lifetime. 1293 // Safe because we control download file lifetime.
1290 base::Unretained(download_file_.get()), 1294 base::Unretained(download_file_.get()),
1291 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, 1295 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized,
1292 weak_ptr_factory_.GetWeakPtr()))); 1296 weak_ptr_factory_.GetWeakPtr()),
1297 received_slices_));
1293 } 1298 }
1294 1299
1295 void DownloadItemImpl::OnDownloadFileInitialized( 1300 void DownloadItemImpl::OnDownloadFileInitialized(
1296 DownloadInterruptReason result) { 1301 DownloadInterruptReason result) {
1297 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1302 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1298 DCHECK(state_ == TARGET_PENDING_INTERNAL || 1303 DCHECK(state_ == TARGET_PENDING_INTERNAL ||
1299 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) 1304 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL)
1300 << "Unexpected state: " << DebugDownloadStateString(state_); 1305 << "Unexpected state: " << DebugDownloadStateString(state_);
1301 1306
1302 DVLOG(20) << __func__ 1307 DVLOG(20) << __func__
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
2240 case RESUME_MODE_USER_CONTINUE: 2245 case RESUME_MODE_USER_CONTINUE:
2241 return "USER_CONTINUE"; 2246 return "USER_CONTINUE";
2242 case RESUME_MODE_USER_RESTART: 2247 case RESUME_MODE_USER_RESTART:
2243 return "USER_RESTART"; 2248 return "USER_RESTART";
2244 } 2249 }
2245 NOTREACHED() << "Unknown resume mode " << mode; 2250 NOTREACHED() << "Unknown resume mode " << mode;
2246 return "unknown"; 2251 return "unknown";
2247 } 2252 }
2248 2253
2249 } // namespace content 2254 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_file_unittest.cc ('k') | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698