| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 virtual void CancelRequest() const OVERRIDE {} | 100 virtual void CancelRequest() const OVERRIDE {} |
| 101 virtual std::string DebugString() const OVERRIDE { | 101 virtual std::string DebugString() const OVERRIDE { |
| 102 return "Null DownloadRequestHandle"; | 102 return "Null DownloadRequestHandle"; |
| 103 } | 103 } |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that | 106 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that |
| 107 // takes ownership of the DownloadFile and hence implicitly destroys it | 107 // takes ownership of the DownloadFile and hence implicitly destroys it |
| 108 // at the end of the function. | 108 // at the end of the function. |
| 109 static void DownloadFileDetach( | 109 static void DownloadFileDetach( |
| 110 scoped_ptr<DownloadFile> download_file, base::Closure callback) { | 110 scoped_ptr<DownloadFile> download_file, |
| 111 const DownloadFile::DetachCompletionCallback& callback) { |
| 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 112 download_file->Detach(callback); | 113 download_file->Detach(callback); |
| 113 } | 114 } |
| 114 | 115 |
| 115 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { | 116 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { |
| 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 117 download_file->Cancel(); | 118 download_file->Cancel(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 } // namespace | 121 } // namespace |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 // Somewhat counter-intuitively, it is possible for us to receive an | 836 // Somewhat counter-intuitively, it is possible for us to receive an |
| 836 // interrupt after we've already been interrupted. The generation of | 837 // interrupt after we've already been interrupted. The generation of |
| 837 // interrupts from the file thread Renames and the generation of | 838 // interrupts from the file thread Renames and the generation of |
| 838 // interrupts from disk writes go through two different mechanisms (driven | 839 // interrupts from disk writes go through two different mechanisms (driven |
| 839 // by rename requests from UI thread and by write requests from IO thread, | 840 // by rename requests from UI thread and by write requests from IO thread, |
| 840 // respectively), and since we choose not to keep state on the File thread, | 841 // respectively), and since we choose not to keep state on the File thread, |
| 841 // this is the place where the races collide. It's also possible for | 842 // this is the place where the races collide. It's also possible for |
| 842 // interrupts to race with cancels. | 843 // interrupts to race with cancels. |
| 843 | 844 |
| 844 // Whatever happens, the first one to hit the UI thread wins. | 845 // Whatever happens, the first one to hit the UI thread wins. |
| 845 if (state_ != IN_PROGRESS_INTERNAL) | 846 if (state_ != IN_PROGRESS_INTERNAL && state_ != COMPLETING_INTERNAL) |
| 846 return; | 847 return; |
| 847 | 848 |
| 848 last_reason_ = reason; | 849 last_reason_ = reason; |
| 849 TransitionTo(INTERRUPTED_INTERNAL); | 850 TransitionTo(INTERRUPTED_INTERNAL); |
| 850 | 851 |
| 851 CancelDownloadFile(); | 852 CancelDownloadFile(); |
| 852 | 853 |
| 853 // Cancel the originating URL request. | 854 // Cancel the originating URL request. |
| 854 request_handle_->CancelRequest(); | 855 request_handle_->CancelRequest(); |
| 855 | 856 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 VLOG(20) << __FUNCTION__ << "()" | 1190 VLOG(20) << __FUNCTION__ << "()" |
| 1190 << " needs rename = " << NeedsRename() | 1191 << " needs rename = " << NeedsRename() |
| 1191 << " " << DebugString(true); | 1192 << " " << DebugString(true); |
| 1192 DCHECK(!GetTargetFilePath().empty()); | 1193 DCHECK(!GetTargetFilePath().empty()); |
| 1193 DCHECK_NE(DANGEROUS, GetSafetyState()); | 1194 DCHECK_NE(DANGEROUS, GetSafetyState()); |
| 1194 | 1195 |
| 1195 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. | 1196 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. |
| 1196 if (is_save_package_download_) { | 1197 if (is_save_package_download_) { |
| 1197 // Avoid doing anything on the file thread; there's nothing we control | 1198 // Avoid doing anything on the file thread; there's nothing we control |
| 1198 // there. | 1199 // there. |
| 1199 OnDownloadFileReleased(); | 1200 OnDownloadFileReleased(content::DOWNLOAD_INTERRUPT_REASON_NONE); |
| 1200 return; | 1201 return; |
| 1201 } | 1202 } |
| 1202 | 1203 |
| 1203 DCHECK(download_file_.get()); | 1204 DCHECK(download_file_.get()); |
| 1204 if (NeedsRename()) { | 1205 if (NeedsRename()) { |
| 1205 content::DownloadFile::RenameCompletionCallback callback = | 1206 content::DownloadFile::RenameCompletionCallback callback = |
| 1206 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, | 1207 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, |
| 1207 weak_ptr_factory_.GetWeakPtr()); | 1208 weak_ptr_factory_.GetWeakPtr()); |
| 1208 BrowserThread::PostTask( | 1209 BrowserThread::PostTask( |
| 1209 BrowserThread::FILE, FROM_HERE, | 1210 BrowserThread::FILE, FROM_HERE, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, | 1257 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, |
| 1257 weak_ptr_factory_.GetWeakPtr()))); | 1258 weak_ptr_factory_.GetWeakPtr()))); |
| 1258 | 1259 |
| 1259 // We're not completely done with the download item yet, but at this | 1260 // 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, | 1261 // 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 | 1262 // though it's not clear how they could happen) after this point will be |
| 1262 // ignored. | 1263 // ignored. |
| 1263 TransitionTo(COMPLETING_INTERNAL); | 1264 TransitionTo(COMPLETING_INTERNAL); |
| 1264 } | 1265 } |
| 1265 | 1266 |
| 1266 void DownloadItemImpl::OnDownloadFileReleased() { | 1267 void DownloadItemImpl::OnDownloadFileReleased( |
| 1268 content::DownloadInterruptReason reason) { |
| 1269 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != reason) { |
| 1270 Interrupt(reason); |
| 1271 return; |
| 1272 } |
| 1267 if (delegate_->ShouldOpenDownload(this)) | 1273 if (delegate_->ShouldOpenDownload(this)) |
| 1268 Completed(); | 1274 Completed(); |
| 1269 else | 1275 else |
| 1270 delegate_delayed_complete_ = true; | 1276 delegate_delayed_complete_ = true; |
| 1271 } | 1277 } |
| 1272 | 1278 |
| 1273 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { | 1279 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { |
| 1274 auto_opened_ = auto_opened; | 1280 auto_opened_ = auto_opened; |
| 1275 Completed(); | 1281 Completed(); |
| 1276 } | 1282 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1300 auto_opened_ = true; | 1306 auto_opened_ = true; |
| 1301 UpdateObservers(); | 1307 UpdateObservers(); |
| 1302 } | 1308 } |
| 1303 } | 1309 } |
| 1304 | 1310 |
| 1305 // **** End of Download progression cascade | 1311 // **** End of Download progression cascade |
| 1306 | 1312 |
| 1307 void DownloadItemImpl::CancelDownloadFile() { | 1313 void DownloadItemImpl::CancelDownloadFile() { |
| 1308 // TODO(rdsmith/benjhayden): Remove condition as part of | 1314 // TODO(rdsmith/benjhayden): Remove condition as part of |
| 1309 // SavePackage integration. | 1315 // SavePackage integration. |
| 1310 if (!is_save_package_download_) { | 1316 // download_file_ can be NULL if Interrupt() is called after the download file |
| 1311 DCHECK(download_file_.get()); | 1317 // has been released. |
| 1318 if (!is_save_package_download_ && download_file_.get()) { |
| 1312 BrowserThread::PostTask( | 1319 BrowserThread::PostTask( |
| 1313 BrowserThread::FILE, FROM_HERE, | 1320 BrowserThread::FILE, FROM_HERE, |
| 1314 // Will be deleted at end of task execution. | 1321 // Will be deleted at end of task execution. |
| 1315 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); | 1322 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); |
| 1316 } | 1323 } |
| 1317 } | 1324 } |
| 1318 | 1325 |
| 1319 bool DownloadItemImpl::IsDownloadReadyForCompletion() { | 1326 bool DownloadItemImpl::IsDownloadReadyForCompletion() { |
| 1320 // If we don't have all the data, the download is not ready for | 1327 // If we don't have all the data, the download is not ready for |
| 1321 // completion. | 1328 // completion. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 return "COMPLETE"; | 1482 return "COMPLETE"; |
| 1476 case CANCELLED_INTERNAL: | 1483 case CANCELLED_INTERNAL: |
| 1477 return "CANCELLED"; | 1484 return "CANCELLED"; |
| 1478 case INTERRUPTED_INTERNAL: | 1485 case INTERRUPTED_INTERNAL: |
| 1479 return "INTERRUPTED"; | 1486 return "INTERRUPTED"; |
| 1480 default: | 1487 default: |
| 1481 NOTREACHED() << "Unknown download state " << state; | 1488 NOTREACHED() << "Unknown download state " << state; |
| 1482 return "unknown"; | 1489 return "unknown"; |
| 1483 }; | 1490 }; |
| 1484 } | 1491 } |
| OLD | NEW |