Chromium Code Reviews| 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(); | |
|
qinmin
2017/04/07 18:03:49
should we also clear the received_bytes_ after the
xingliu
2017/04/07 20:50:08
Done.
Make sense, it's good to clear received sli
xingliu
2017/04/07 22:18:03
Done,
Sorry that I somehow misunderstood the comm
| |
| 1032 origin_state |= ORIGIN_STATE_ON_RESUMPTION_VALIDATORS_CHANGED; | 1033 origin_state |= ORIGIN_STATE_ON_RESUMPTION_VALIDATORS_CHANGED; |
| 1034 } | |
| 1033 if (content_disposition_ != new_create_info.content_disposition) | 1035 if (content_disposition_ != new_create_info.content_disposition) |
| 1034 origin_state |= ORIGIN_STATE_ON_RESUMPTION_CONTENT_DISPOSITION_CHANGED; | 1036 origin_state |= ORIGIN_STATE_ON_RESUMPTION_CONTENT_DISPOSITION_CHANGED; |
| 1035 RecordOriginStateOnResumption(received_bytes_ != 0, origin_state); | 1037 RecordOriginStateOnResumption(received_bytes_ != 0, origin_state); |
| 1036 | 1038 |
| 1037 url_chain_.insert( | 1039 url_chain_.insert( |
| 1038 url_chain_.end(), chain_iter, new_create_info.url_chain.end()); | 1040 url_chain_.end(), chain_iter, new_create_info.url_chain.end()); |
| 1039 etag_ = new_create_info.etag; | 1041 etag_ = new_create_info.etag; |
| 1040 last_modified_time_ = new_create_info.last_modified; | 1042 last_modified_time_ = new_create_info.last_modified; |
| 1041 content_disposition_ = new_create_info.content_disposition; | 1043 content_disposition_ = new_create_info.content_disposition; |
| 1042 // It is possible that the previous download attempt failed right before the | 1044 // 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(); | 1284 job_->Start(); |
| 1283 } | 1285 } |
| 1284 | 1286 |
| 1285 void DownloadItemImpl::StartDownload() { | 1287 void DownloadItemImpl::StartDownload() { |
| 1286 BrowserThread::PostTask( | 1288 BrowserThread::PostTask( |
| 1287 BrowserThread::FILE, FROM_HERE, | 1289 BrowserThread::FILE, FROM_HERE, |
| 1288 base::Bind(&DownloadFile::Initialize, | 1290 base::Bind(&DownloadFile::Initialize, |
| 1289 // Safe because we control download file lifetime. | 1291 // Safe because we control download file lifetime. |
| 1290 base::Unretained(download_file_.get()), | 1292 base::Unretained(download_file_.get()), |
| 1291 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, | 1293 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, |
| 1292 weak_ptr_factory_.GetWeakPtr()))); | 1294 weak_ptr_factory_.GetWeakPtr()), |
| 1295 received_slices_)); | |
| 1293 } | 1296 } |
| 1294 | 1297 |
| 1295 void DownloadItemImpl::OnDownloadFileInitialized( | 1298 void DownloadItemImpl::OnDownloadFileInitialized( |
| 1296 DownloadInterruptReason result) { | 1299 DownloadInterruptReason result) { |
| 1297 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1300 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1298 DCHECK(state_ == TARGET_PENDING_INTERNAL || | 1301 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
| 1299 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) | 1302 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) |
| 1300 << "Unexpected state: " << DebugDownloadStateString(state_); | 1303 << "Unexpected state: " << DebugDownloadStateString(state_); |
| 1301 | 1304 |
| 1302 DVLOG(20) << __func__ | 1305 DVLOG(20) << __func__ |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2240 case RESUME_MODE_USER_CONTINUE: | 2243 case RESUME_MODE_USER_CONTINUE: |
| 2241 return "USER_CONTINUE"; | 2244 return "USER_CONTINUE"; |
| 2242 case RESUME_MODE_USER_RESTART: | 2245 case RESUME_MODE_USER_RESTART: |
| 2243 return "USER_RESTART"; | 2246 return "USER_RESTART"; |
| 2244 } | 2247 } |
| 2245 NOTREACHED() << "Unknown resume mode " << mode; | 2248 NOTREACHED() << "Unknown resume mode " << mode; |
| 2246 return "unknown"; | 2249 return "unknown"; |
| 2247 } | 2250 } |
| 2248 | 2251 |
| 2249 } // namespace content | 2252 } // namespace content |
| OLD | NEW |