| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 62 | 62 |
| 63 // Make sure we only delete files. | 63 // Make sure we only delete files. |
| 64 if (!file_util::DirectoryExists(path)) | 64 if (!file_util::DirectoryExists(path)) |
| 65 file_util::Delete(path, false); | 65 file_util::Delete(path, false); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that | 68 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that |
| 69 // takes ownership of the DownloadFile and hence implicitly destroys it | 69 // takes ownership of the DownloadFile and hence implicitly destroys it |
| 70 // at the end of the function. | 70 // at the end of the function. |
| 71 static void DownloadFileDetach(scoped_ptr<DownloadFile> download_file) { | 71 static base::FilePath DownloadFileDetach( |
| 72 scoped_ptr<DownloadFile> download_file) { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 74 base::FilePath full_path = download_file->FullPath(); |
| 73 download_file->Detach(); | 75 download_file->Detach(); |
| 76 return full_path; |
| 74 } | 77 } |
| 75 | 78 |
| 76 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { | 79 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 78 download_file->Cancel(); | 81 download_file->Cancel(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 } // namespace | 84 } // namespace |
| 82 | 85 |
| 83 const char DownloadItem::kEmptyFileHash[] = ""; | 86 const char DownloadItem::kEmptyFileHash[] = ""; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 // Delete the file if it exists and is not owned by a DownloadFile object. | 384 // Delete the file if it exists and is not owned by a DownloadFile object. |
| 382 // (In the latter case the DownloadFile object will delete it on cancel.) | 385 // (In the latter case the DownloadFile object will delete it on cancel.) |
| 383 if (!current_path_.empty() && download_file_.get() == NULL) { | 386 if (!current_path_.empty() && download_file_.get() == NULL) { |
| 384 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 387 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 385 base::Bind(&DeleteDownloadedFile, current_path_)); | 388 base::Bind(&DeleteDownloadedFile, current_path_)); |
| 386 } | 389 } |
| 387 Remove(); | 390 Remove(); |
| 388 // We have now been deleted. | 391 // We have now been deleted. |
| 389 } | 392 } |
| 390 | 393 |
| 394 void DownloadItemImpl::AcquireFileAndDeleteDownload( |
| 395 const AcquireFileCallback& callback) { |
| 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 397 |
| 398 if (download_file_) { |
| 399 BrowserThread::PostTaskAndReplyWithResult( |
| 400 BrowserThread::FILE, FROM_HERE, |
| 401 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), |
| 402 callback); |
| 403 } else { |
| 404 callback.Run(current_path_); |
| 405 } |
| 406 current_path_.clear(); |
| 407 Delete(DELETE_DUE_TO_USER_DISCARD); |
| 408 } |
| 409 |
| 391 void DownloadItemImpl::Remove() { | 410 void DownloadItemImpl::Remove() { |
| 392 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 411 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
| 393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 394 | 413 |
| 395 delegate_->AssertStateConsistent(this); | 414 delegate_->AssertStateConsistent(this); |
| 396 Cancel(true); | 415 Cancel(true); |
| 397 delegate_->AssertStateConsistent(this); | 416 delegate_->AssertStateConsistent(this); |
| 398 | 417 |
| 399 NotifyRemoved(); | 418 NotifyRemoved(); |
| 400 delegate_->DownloadRemoved(this); | 419 delegate_->DownloadRemoved(this); |
| (...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 | 1453 |
| 1435 if (destroy_file) { | 1454 if (destroy_file) { |
| 1436 BrowserThread::PostTask( | 1455 BrowserThread::PostTask( |
| 1437 BrowserThread::FILE, FROM_HERE, | 1456 BrowserThread::FILE, FROM_HERE, |
| 1438 // Will be deleted at end of task execution. | 1457 // Will be deleted at end of task execution. |
| 1439 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); | 1458 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); |
| 1440 } else { | 1459 } else { |
| 1441 BrowserThread::PostTask( | 1460 BrowserThread::PostTask( |
| 1442 BrowserThread::FILE, FROM_HERE, | 1461 BrowserThread::FILE, FROM_HERE, |
| 1443 // Will be deleted at end of task execution. | 1462 // Will be deleted at end of task execution. |
| 1444 base::Bind(&DownloadFileDetach, base::Passed(&download_file_))); | 1463 base::Bind(base::IgnoreResult(&DownloadFileDetach), |
| 1464 base::Passed(&download_file_))); |
| 1445 } | 1465 } |
| 1446 // Don't accept any more messages from the DownloadFile, and null | 1466 // Don't accept any more messages from the DownloadFile, and null |
| 1447 // out any previous "all data received". This also breaks links to | 1467 // out any previous "all data received". This also breaks links to |
| 1448 // other entities we've given out weak pointers to. | 1468 // other entities we've given out weak pointers to. |
| 1449 weak_ptr_factory_.InvalidateWeakPtrs(); | 1469 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 1450 | 1470 |
| 1451 // TODO(rdsmith/benjhayden): Remove condition as part of | 1471 // TODO(rdsmith/benjhayden): Remove condition as part of |
| 1452 // |SavePackage| integration. | 1472 // |SavePackage| integration. |
| 1453 // |download_file_| can be NULL if Interrupt() is called after the | 1473 // |download_file_| can be NULL if Interrupt() is called after the |
| 1454 // download file has been released. | 1474 // download file has been released. |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 case RESUME_MODE_USER_CONTINUE: | 1693 case RESUME_MODE_USER_CONTINUE: |
| 1674 return "USER_CONTINUE"; | 1694 return "USER_CONTINUE"; |
| 1675 case RESUME_MODE_USER_RESTART: | 1695 case RESUME_MODE_USER_RESTART: |
| 1676 return "USER_RESTART"; | 1696 return "USER_RESTART"; |
| 1677 } | 1697 } |
| 1678 NOTREACHED() << "Unknown resume mode " << mode; | 1698 NOTREACHED() << "Unknown resume mode " << mode; |
| 1679 return "unknown"; | 1699 return "unknown"; |
| 1680 } | 1700 } |
| 1681 | 1701 |
| 1682 } // namespace content | 1702 } // namespace content |
| OLD | NEW |