| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 virtual void CancelRequest() const OVERRIDE {} | 93 virtual void CancelRequest() const OVERRIDE {} |
| 94 virtual std::string DebugString() const OVERRIDE { | 94 virtual std::string DebugString() const OVERRIDE { |
| 95 return "Null DownloadRequestHandle"; | 95 return "Null DownloadRequestHandle"; |
| 96 } | 96 } |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that | 99 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that |
| 100 // takes ownership of the DownloadFile and hence implicitly destroys it | 100 // takes ownership of the DownloadFile and hence implicitly destroys it |
| 101 // at the end of the function. | 101 // at the end of the function. |
| 102 static void DownloadFileDetach( | 102 static void DownloadFileDetach( |
| 103 scoped_ptr<DownloadFile> download_file, base::Closure callback) { | 103 scoped_ptr<DownloadFile> download_file, |
| 104 const DownloadFile::DetachCompletionCallback& callback) { |
| 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 105 download_file->Detach(callback); | 106 download_file->Detach(callback); |
| 106 } | 107 } |
| 107 | 108 |
| 108 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { | 109 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { |
| 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 110 download_file->Cancel(); | 111 download_file->Cancel(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace | 114 } // namespace |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 // Somewhat counter-intuitively, it is possible for us to receive an | 821 // Somewhat counter-intuitively, it is possible for us to receive an |
| 821 // interrupt after we've already been interrupted. The generation of | 822 // interrupt after we've already been interrupted. The generation of |
| 822 // interrupts from the file thread Renames and the generation of | 823 // interrupts from the file thread Renames and the generation of |
| 823 // interrupts from disk writes go through two different mechanisms (driven | 824 // interrupts from disk writes go through two different mechanisms (driven |
| 824 // by rename requests from UI thread and by write requests from IO thread, | 825 // by rename requests from UI thread and by write requests from IO thread, |
| 825 // respectively), and since we choose not to keep state on the File thread, | 826 // respectively), and since we choose not to keep state on the File thread, |
| 826 // this is the place where the races collide. It's also possible for | 827 // this is the place where the races collide. It's also possible for |
| 827 // interrupts to race with cancels. | 828 // interrupts to race with cancels. |
| 828 | 829 |
| 829 // Whatever happens, the first one to hit the UI thread wins. | 830 // Whatever happens, the first one to hit the UI thread wins. |
| 830 if (state_ != IN_PROGRESS_INTERNAL) | 831 if (state_ != IN_PROGRESS_INTERNAL && state_ != COMPLETING_INTERNAL) |
| 831 return; | 832 return; |
| 832 | 833 |
| 833 last_reason_ = reason; | 834 last_reason_ = reason; |
| 834 TransitionTo(INTERRUPTED_INTERNAL); | 835 TransitionTo(INTERRUPTED_INTERNAL); |
| 835 | 836 |
| 836 CancelDownloadFile(); | 837 CancelDownloadFile(); |
| 837 | 838 |
| 838 // Cancel the originating URL request. | 839 // Cancel the originating URL request. |
| 839 request_handle_->CancelRequest(); | 840 request_handle_->CancelRequest(); |
| 840 | 841 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 VLOG(20) << __FUNCTION__ << "()" | 1173 VLOG(20) << __FUNCTION__ << "()" |
| 1173 << " needs rename = " << NeedsRename() | 1174 << " needs rename = " << NeedsRename() |
| 1174 << " " << DebugString(true); | 1175 << " " << DebugString(true); |
| 1175 DCHECK(!GetTargetFilePath().empty()); | 1176 DCHECK(!GetTargetFilePath().empty()); |
| 1176 DCHECK_NE(DANGEROUS, GetSafetyState()); | 1177 DCHECK_NE(DANGEROUS, GetSafetyState()); |
| 1177 | 1178 |
| 1178 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. | 1179 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. |
| 1179 if (is_save_package_download_) { | 1180 if (is_save_package_download_) { |
| 1180 // Avoid doing anything on the file thread; there's nothing we control | 1181 // Avoid doing anything on the file thread; there's nothing we control |
| 1181 // there. | 1182 // there. |
| 1182 OnDownloadFileReleased(); | 1183 OnDownloadFileReleased(DOWNLOAD_INTERRUPT_REASON_NONE); |
| 1183 return; | 1184 return; |
| 1184 } | 1185 } |
| 1185 | 1186 |
| 1186 DCHECK(download_file_.get()); | 1187 DCHECK(download_file_.get()); |
| 1187 if (NeedsRename()) { | 1188 if (NeedsRename()) { |
| 1188 DownloadFile::RenameCompletionCallback callback = | 1189 DownloadFile::RenameCompletionCallback callback = |
| 1189 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, | 1190 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, |
| 1190 weak_ptr_factory_.GetWeakPtr()); | 1191 weak_ptr_factory_.GetWeakPtr()); |
| 1191 BrowserThread::PostTask( | 1192 BrowserThread::PostTask( |
| 1192 BrowserThread::FILE, FROM_HERE, | 1193 BrowserThread::FILE, FROM_HERE, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, | 1240 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, |
| 1240 weak_ptr_factory_.GetWeakPtr()))); | 1241 weak_ptr_factory_.GetWeakPtr()))); |
| 1241 | 1242 |
| 1242 // We're not completely done with the download item yet, but at this | 1243 // We're not completely done with the download item yet, but at this |
| 1243 // point we're committed to complete the download. Cancels (or Interrupts, | 1244 // point we're committed to complete the download. Cancels (or Interrupts, |
| 1244 // though it's not clear how they could happen) after this point will be | 1245 // though it's not clear how they could happen) after this point will be |
| 1245 // ignored. | 1246 // ignored. |
| 1246 TransitionTo(COMPLETING_INTERNAL); | 1247 TransitionTo(COMPLETING_INTERNAL); |
| 1247 } | 1248 } |
| 1248 | 1249 |
| 1249 void DownloadItemImpl::OnDownloadFileReleased() { | 1250 void DownloadItemImpl::OnDownloadFileReleased(DownloadInterruptReason reason) { |
| 1251 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { |
| 1252 Interrupt(reason); |
| 1253 return; |
| 1254 } |
| 1250 if (delegate_->ShouldOpenDownload(this)) | 1255 if (delegate_->ShouldOpenDownload(this)) |
| 1251 Completed(); | 1256 Completed(); |
| 1252 else | 1257 else |
| 1253 delegate_delayed_complete_ = true; | 1258 delegate_delayed_complete_ = true; |
| 1254 } | 1259 } |
| 1255 | 1260 |
| 1256 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { | 1261 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { |
| 1257 auto_opened_ = auto_opened; | 1262 auto_opened_ = auto_opened; |
| 1258 Completed(); | 1263 Completed(); |
| 1259 } | 1264 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1283 auto_opened_ = true; | 1288 auto_opened_ = true; |
| 1284 UpdateObservers(); | 1289 UpdateObservers(); |
| 1285 } | 1290 } |
| 1286 } | 1291 } |
| 1287 | 1292 |
| 1288 // **** End of Download progression cascade | 1293 // **** End of Download progression cascade |
| 1289 | 1294 |
| 1290 void DownloadItemImpl::CancelDownloadFile() { | 1295 void DownloadItemImpl::CancelDownloadFile() { |
| 1291 // TODO(rdsmith/benjhayden): Remove condition as part of | 1296 // TODO(rdsmith/benjhayden): Remove condition as part of |
| 1292 // SavePackage integration. | 1297 // SavePackage integration. |
| 1293 if (!is_save_package_download_) { | 1298 // download_file_ can be NULL if Interrupt() is called after the download file |
| 1294 DCHECK(download_file_.get()); | 1299 // has been released. |
| 1300 if (!is_save_package_download_ && download_file_.get()) { |
| 1295 BrowserThread::PostTask( | 1301 BrowserThread::PostTask( |
| 1296 BrowserThread::FILE, FROM_HERE, | 1302 BrowserThread::FILE, FROM_HERE, |
| 1297 // Will be deleted at end of task execution. | 1303 // Will be deleted at end of task execution. |
| 1298 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); | 1304 base::Bind(&DownloadFileCancel, base::Passed(download_file_.Pass()))); |
| 1299 } | 1305 } |
| 1300 } | 1306 } |
| 1301 | 1307 |
| 1302 bool DownloadItemImpl::IsDownloadReadyForCompletion() { | 1308 bool DownloadItemImpl::IsDownloadReadyForCompletion() { |
| 1303 // If we don't have all the data, the download is not ready for | 1309 // If we don't have all the data, the download is not ready for |
| 1304 // completion. | 1310 // completion. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 return "CANCELLED"; | 1463 return "CANCELLED"; |
| 1458 case INTERRUPTED_INTERNAL: | 1464 case INTERRUPTED_INTERNAL: |
| 1459 return "INTERRUPTED"; | 1465 return "INTERRUPTED"; |
| 1460 default: | 1466 default: |
| 1461 NOTREACHED() << "Unknown download state " << state; | 1467 NOTREACHED() << "Unknown download state " << state; |
| 1462 return "unknown"; | 1468 return "unknown"; |
| 1463 }; | 1469 }; |
| 1464 } | 1470 } |
| 1465 | 1471 |
| 1466 } // namespace content | 1472 } // namespace content |
| OLD | NEW |