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 // interfaces Start, DelayedDownloadOpened, MaybeCompleteDownload, and | 7 // interfaces Start, DelayedDownloadOpened, MaybeCompleteDownload, and |
8 // OnDownloadCompleting are placed in chronological order with the other | 8 // OnDownloadCompleting are placed in chronological order with the other |
9 // (private) routines that together define a DownloadItem's state transitions | 9 // (private) routines that together define a DownloadItem's state transitions |
10 // as the download progresses. See "Download progression cascade" later in | 10 // as the download progresses. See "Download progression cascade" later in |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 OnDownloadRenamedToIntermediateName(last_reason_, FilePath()); | 1104 OnDownloadRenamedToIntermediateName(last_reason_, FilePath()); |
1105 return; | 1105 return; |
1106 } | 1106 } |
1107 | 1107 |
1108 // Rename to intermediate name. | 1108 // Rename to intermediate name. |
1109 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a | 1109 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a |
1110 // spurious rename when we can just rename to the final | 1110 // spurious rename when we can just rename to the final |
1111 // filename. Unnecessary renames may cause bugs like | 1111 // filename. Unnecessary renames may cause bugs like |
1112 // http://crbug.com/74187. | 1112 // http://crbug.com/74187. |
1113 DCHECK(!is_save_package_download_); | 1113 DCHECK(!is_save_package_download_); |
1114 CHECK(download_file_.get()); | 1114 DCHECK(download_file_.get()); |
1115 DownloadFile::RenameCompletionCallback callback = | 1115 DownloadFile::RenameCompletionCallback callback = |
1116 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, | 1116 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, |
1117 weak_ptr_factory_.GetWeakPtr()); | 1117 weak_ptr_factory_.GetWeakPtr()); |
1118 BrowserThread::PostTask( | 1118 BrowserThread::PostTask( |
1119 BrowserThread::FILE, FROM_HERE, | 1119 BrowserThread::FILE, FROM_HERE, |
1120 base::Bind(&DownloadFile::Rename, | 1120 base::Bind(&DownloadFile::Rename, |
1121 // Safe because we control download file lifetime. | 1121 // Safe because we control download file lifetime. |
1122 base::Unretained(download_file_.get()), | 1122 base::Unretained(download_file_.get()), |
1123 intermediate_path, false, callback)); | 1123 intermediate_path, false, callback)); |
1124 } | 1124 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 DCHECK_NE(DANGEROUS, GetSafetyState()); | 1193 DCHECK_NE(DANGEROUS, GetSafetyState()); |
1194 | 1194 |
1195 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. | 1195 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. |
1196 if (is_save_package_download_) { | 1196 if (is_save_package_download_) { |
1197 // Avoid doing anything on the file thread; there's nothing we control | 1197 // Avoid doing anything on the file thread; there's nothing we control |
1198 // there. | 1198 // there. |
1199 OnDownloadFileReleased(); | 1199 OnDownloadFileReleased(); |
1200 return; | 1200 return; |
1201 } | 1201 } |
1202 | 1202 |
1203 CHECK(download_file_.get()); | 1203 DCHECK(download_file_.get()); |
1204 if (NeedsRename()) { | 1204 if (NeedsRename()) { |
1205 content::DownloadFile::RenameCompletionCallback callback = | 1205 content::DownloadFile::RenameCompletionCallback callback = |
1206 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, | 1206 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, |
1207 weak_ptr_factory_.GetWeakPtr()); | 1207 weak_ptr_factory_.GetWeakPtr()); |
1208 BrowserThread::PostTask( | 1208 BrowserThread::PostTask( |
1209 BrowserThread::FILE, FROM_HERE, | 1209 BrowserThread::FILE, FROM_HERE, |
1210 base::Bind(&DownloadFile::Rename, | 1210 base::Bind(&DownloadFile::Rename, |
1211 base::Unretained(download_file_.get()), | 1211 base::Unretained(download_file_.get()), |
1212 GetTargetFilePath(), true, callback)); | 1212 GetTargetFilePath(), true, callback)); |
1213 } else { | 1213 } else { |
(...skipping 28 matching lines...) Expand all Loading... |
1242 target_path_ = full_path; | 1242 target_path_ = full_path; |
1243 SetFullPath(full_path); | 1243 SetFullPath(full_path); |
1244 delegate_->DownloadRenamedToFinalName(this); | 1244 delegate_->DownloadRenamedToFinalName(this); |
1245 | 1245 |
1246 ReleaseDownloadFile(); | 1246 ReleaseDownloadFile(); |
1247 } | 1247 } |
1248 | 1248 |
1249 void DownloadItemImpl::ReleaseDownloadFile() { | 1249 void DownloadItemImpl::ReleaseDownloadFile() { |
1250 // Complete the download and release the DownloadFile. | 1250 // Complete the download and release the DownloadFile. |
1251 DCHECK(!is_save_package_download_); | 1251 DCHECK(!is_save_package_download_); |
1252 CHECK(download_file_.get()); | 1252 DCHECK(download_file_.get()); |
1253 BrowserThread::PostTask( | 1253 BrowserThread::PostTask( |
1254 BrowserThread::FILE, FROM_HERE, | 1254 BrowserThread::FILE, FROM_HERE, |
1255 base::Bind(&DownloadFileDetach, base::Passed(download_file_.Pass()), | 1255 base::Bind(&DownloadFileDetach, base::Passed(download_file_.Pass()), |
1256 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, | 1256 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, |
1257 weak_ptr_factory_.GetWeakPtr()))); | 1257 weak_ptr_factory_.GetWeakPtr()))); |
1258 | 1258 |
1259 // We're not completely done with the download item yet, but at this | 1259 // We're not completely done with the download item yet, but at this |
1260 // point we're committed to complete the download. Cancels (or Interrupts, | 1260 // point we're committed to complete the download. Cancels (or Interrupts, |
1261 // though it's not clear how they could happen) after this point will be | 1261 // though it's not clear how they could happen) after this point will be |
1262 // ignored. | 1262 // ignored. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 UpdateObservers(); | 1301 UpdateObservers(); |
1302 } | 1302 } |
1303 } | 1303 } |
1304 | 1304 |
1305 // **** End of Download progression cascade | 1305 // **** End of Download progression cascade |
1306 | 1306 |
1307 void DownloadItemImpl::CancelDownloadFile() { | 1307 void DownloadItemImpl::CancelDownloadFile() { |
1308 // TODO(rdsmith/benjhayden): Remove condition as part of | 1308 // TODO(rdsmith/benjhayden): Remove condition as part of |
1309 // SavePackage integration. | 1309 // SavePackage integration. |
1310 if (!is_save_package_download_) { | 1310 if (!is_save_package_download_) { |
1311 CHECK(download_file_.get()); | 1311 DCHECK(download_file_.get()); |
1312 BrowserThread::PostTask( | 1312 BrowserThread::PostTask( |
1313 BrowserThread::FILE, FROM_HERE, | 1313 BrowserThread::FILE, FROM_HERE, |
1314 // Will be deleted at end of task execution. | 1314 // Will be deleted at end of task execution. |
1315 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); | 1315 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); |
1316 } | 1316 } |
1317 } | 1317 } |
1318 | 1318 |
1319 bool DownloadItemImpl::IsDownloadReadyForCompletion() { | 1319 bool DownloadItemImpl::IsDownloadReadyForCompletion() { |
1320 // If we don't have all the data, the download is not ready for | 1320 // If we don't have all the data, the download is not ready for |
1321 // completion. | 1321 // completion. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 return "COMPLETE"; | 1475 return "COMPLETE"; |
1476 case CANCELLED_INTERNAL: | 1476 case CANCELLED_INTERNAL: |
1477 return "CANCELLED"; | 1477 return "CANCELLED"; |
1478 case INTERRUPTED_INTERNAL: | 1478 case INTERRUPTED_INTERNAL: |
1479 return "INTERRUPTED"; | 1479 return "INTERRUPTED"; |
1480 default: | 1480 default: |
1481 NOTREACHED() << "Unknown download state " << state; | 1481 NOTREACHED() << "Unknown download state " << state; |
1482 return "unknown"; | 1482 return "unknown"; |
1483 }; | 1483 }; |
1484 } | 1484 } |
OLD | NEW |