| 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 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 content_disposition_ = new_create_info.content_disposition; | 1056 content_disposition_ = new_create_info.content_disposition; |
| 1057 // It is possible that the previous download attempt failed right before the | 1057 // It is possible that the previous download attempt failed right before the |
| 1058 // response is received. Need to reset the MIME type. | 1058 // response is received. Need to reset the MIME type. |
| 1059 mime_type_ = new_create_info.mime_type; | 1059 mime_type_ = new_create_info.mime_type; |
| 1060 | 1060 |
| 1061 // Don't update observers. This method is expected to be called just before a | 1061 // Don't update observers. This method is expected to be called just before a |
| 1062 // DownloadFile is created and Start() is called. The observers will be | 1062 // DownloadFile is created and Start() is called. The observers will be |
| 1063 // notified when the download transitions to the IN_PROGRESS state. | 1063 // notified when the download transitions to the IN_PROGRESS state. |
| 1064 } | 1064 } |
| 1065 | 1065 |
| 1066 void DownloadItemImpl::CancelRequestWithOffset(int64_t offset) { | |
| 1067 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 1068 if (job_) | |
| 1069 job_->CancelRequestWithOffset(offset); | |
| 1070 } | |
| 1071 | |
| 1072 void DownloadItemImpl::NotifyRemoved() { | 1066 void DownloadItemImpl::NotifyRemoved() { |
| 1073 for (auto& observer : observers_) | 1067 for (auto& observer : observers_) |
| 1074 observer.OnDownloadRemoved(this); | 1068 observer.OnDownloadRemoved(this); |
| 1075 } | 1069 } |
| 1076 | 1070 |
| 1077 void DownloadItemImpl::OnDownloadedFileRemoved() { | 1071 void DownloadItemImpl::OnDownloadedFileRemoved() { |
| 1078 file_externally_removed_ = true; | 1072 file_externally_removed_ = true; |
| 1079 DVLOG(20) << __func__ << "() download=" << DebugString(true); | 1073 DVLOG(20) << __func__ << "() download=" << DebugString(true); |
| 1080 UpdateObservers(); | 1074 UpdateObservers(); |
| 1081 } | 1075 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 // If the download uses parallel requests, and choose not to create parallel | 1311 // If the download uses parallel requests, and choose not to create parallel |
| 1318 // request during resumption, clear the received_slices_ vector. | 1312 // request during resumption, clear the received_slices_ vector. |
| 1319 if (!IsParallelDownloadEnabled() && !received_slices_.empty()) { | 1313 if (!IsParallelDownloadEnabled() && !received_slices_.empty()) { |
| 1320 received_bytes_ = | 1314 received_bytes_ = |
| 1321 GetMaxContiguousDataBlockSizeFromBeginning(received_slices_); | 1315 GetMaxContiguousDataBlockSizeFromBeginning(received_slices_); |
| 1322 received_slices_.clear(); | 1316 received_slices_.clear(); |
| 1323 } | 1317 } |
| 1324 | 1318 |
| 1325 TransitionTo(TARGET_PENDING_INTERNAL); | 1319 TransitionTo(TARGET_PENDING_INTERNAL); |
| 1326 | 1320 |
| 1327 job_->Start(); | 1321 job_->Start(download_file_.get(), |
| 1328 } | 1322 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, |
| 1329 | 1323 weak_ptr_factory_.GetWeakPtr()), |
| 1330 void DownloadItemImpl::StartDownload() { | 1324 GetReceivedSlices()); |
| 1331 BrowserThread::PostTask( | |
| 1332 BrowserThread::FILE, FROM_HERE, | |
| 1333 base::Bind(&DownloadFile::Initialize, | |
| 1334 // Safe because we control download file lifetime. | |
| 1335 base::Unretained(download_file_.get()), | |
| 1336 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, | |
| 1337 weak_ptr_factory_.GetWeakPtr()), | |
| 1338 base::Bind(&DownloadItemImpl::CancelRequestWithOffset, | |
| 1339 weak_ptr_factory_.GetWeakPtr()), | |
| 1340 received_slices_, job_ && job_->IsParallelizable())); | |
| 1341 } | 1325 } |
| 1342 | 1326 |
| 1343 void DownloadItemImpl::OnDownloadFileInitialized( | 1327 void DownloadItemImpl::OnDownloadFileInitialized( |
| 1344 DownloadInterruptReason result) { | 1328 DownloadInterruptReason result) { |
| 1345 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1329 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1346 DCHECK(state_ == TARGET_PENDING_INTERNAL || | 1330 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
| 1347 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) | 1331 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) |
| 1348 << "Unexpected state: " << DebugDownloadStateString(state_); | 1332 << "Unexpected state: " << DebugDownloadStateString(state_); |
| 1349 | 1333 |
| 1350 DVLOG(20) << __func__ | 1334 DVLOG(20) << __func__ |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2301 case RESUME_MODE_USER_CONTINUE: | 2285 case RESUME_MODE_USER_CONTINUE: |
| 2302 return "USER_CONTINUE"; | 2286 return "USER_CONTINUE"; |
| 2303 case RESUME_MODE_USER_RESTART: | 2287 case RESUME_MODE_USER_RESTART: |
| 2304 return "USER_RESTART"; | 2288 return "USER_RESTART"; |
| 2305 } | 2289 } |
| 2306 NOTREACHED() << "Unknown resume mode " << mode; | 2290 NOTREACHED() << "Unknown resume mode " << mode; |
| 2307 return "unknown"; | 2291 return "unknown"; |
| 2308 } | 2292 } |
| 2309 | 2293 |
| 2310 } // namespace content | 2294 } // namespace content |
| OLD | NEW |