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 // 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 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 if (chain_iter != new_create_info.url_chain.end()) | 1028 if (chain_iter != new_create_info.url_chain.end()) |
1029 origin_state |= ORIGIN_STATE_ON_RESUMPTION_ADDITIONAL_REDIRECTS; | 1029 origin_state |= ORIGIN_STATE_ON_RESUMPTION_ADDITIONAL_REDIRECTS; |
1030 if (etag_ != new_create_info.etag || | 1030 if (etag_ != new_create_info.etag || |
1031 last_modified_time_ != new_create_info.last_modified) | 1031 last_modified_time_ != new_create_info.last_modified) { |
1032 received_slices_.clear(); | |
1033 received_bytes_ = 0; | |
qinmin
2017/04/07 23:37:43
you either need to do this after RecordOriginState
xingliu
2017/04/08 02:29:13
Oh, I see, thanks for the suggestion, didn't notic
| |
1032 origin_state |= ORIGIN_STATE_ON_RESUMPTION_VALIDATORS_CHANGED; | 1034 origin_state |= ORIGIN_STATE_ON_RESUMPTION_VALIDATORS_CHANGED; |
1035 } | |
1033 if (content_disposition_ != new_create_info.content_disposition) | 1036 if (content_disposition_ != new_create_info.content_disposition) |
1034 origin_state |= ORIGIN_STATE_ON_RESUMPTION_CONTENT_DISPOSITION_CHANGED; | 1037 origin_state |= ORIGIN_STATE_ON_RESUMPTION_CONTENT_DISPOSITION_CHANGED; |
1035 RecordOriginStateOnResumption(received_bytes_ != 0, origin_state); | 1038 RecordOriginStateOnResumption(received_bytes_ != 0, origin_state); |
1036 | 1039 |
1037 url_chain_.insert( | 1040 url_chain_.insert( |
1038 url_chain_.end(), chain_iter, new_create_info.url_chain.end()); | 1041 url_chain_.end(), chain_iter, new_create_info.url_chain.end()); |
1039 etag_ = new_create_info.etag; | 1042 etag_ = new_create_info.etag; |
1040 last_modified_time_ = new_create_info.last_modified; | 1043 last_modified_time_ = new_create_info.last_modified; |
1041 content_disposition_ = new_create_info.content_disposition; | 1044 content_disposition_ = new_create_info.content_disposition; |
1042 // It is possible that the previous download attempt failed right before the | 1045 // It is possible that the previous download attempt failed right before the |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1282 job_->Start(); | 1285 job_->Start(); |
1283 } | 1286 } |
1284 | 1287 |
1285 void DownloadItemImpl::StartDownload() { | 1288 void DownloadItemImpl::StartDownload() { |
1286 BrowserThread::PostTask( | 1289 BrowserThread::PostTask( |
1287 BrowserThread::FILE, FROM_HERE, | 1290 BrowserThread::FILE, FROM_HERE, |
1288 base::Bind(&DownloadFile::Initialize, | 1291 base::Bind(&DownloadFile::Initialize, |
1289 // Safe because we control download file lifetime. | 1292 // Safe because we control download file lifetime. |
1290 base::Unretained(download_file_.get()), | 1293 base::Unretained(download_file_.get()), |
1291 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, | 1294 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, |
1292 weak_ptr_factory_.GetWeakPtr()))); | 1295 weak_ptr_factory_.GetWeakPtr()), |
1296 received_slices_)); | |
1293 } | 1297 } |
1294 | 1298 |
1295 void DownloadItemImpl::OnDownloadFileInitialized( | 1299 void DownloadItemImpl::OnDownloadFileInitialized( |
1296 DownloadInterruptReason result) { | 1300 DownloadInterruptReason result) { |
1297 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1301 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1298 DCHECK(state_ == TARGET_PENDING_INTERNAL || | 1302 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
1299 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) | 1303 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) |
1300 << "Unexpected state: " << DebugDownloadStateString(state_); | 1304 << "Unexpected state: " << DebugDownloadStateString(state_); |
1301 | 1305 |
1302 DVLOG(20) << __func__ | 1306 DVLOG(20) << __func__ |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2240 case RESUME_MODE_USER_CONTINUE: | 2244 case RESUME_MODE_USER_CONTINUE: |
2241 return "USER_CONTINUE"; | 2245 return "USER_CONTINUE"; |
2242 case RESUME_MODE_USER_RESTART: | 2246 case RESUME_MODE_USER_RESTART: |
2243 return "USER_RESTART"; | 2247 return "USER_RESTART"; |
2244 } | 2248 } |
2245 NOTREACHED() << "Unknown resume mode " << mode; | 2249 NOTREACHED() << "Unknown resume mode " << mode; |
2246 return "unknown"; | 2250 return "unknown"; |
2247 } | 2251 } |
2248 | 2252 |
2249 } // namespace content | 2253 } // namespace content |
OLD | NEW |