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 18 matching lines...) Expand all Loading... |
29 #include "base/bind.h" | 29 #include "base/bind.h" |
30 #include "base/files/file_util.h" | 30 #include "base/files/file_util.h" |
31 #include "base/format_macros.h" | 31 #include "base/format_macros.h" |
32 #include "base/guid.h" | 32 #include "base/guid.h" |
33 #include "base/logging.h" | 33 #include "base/logging.h" |
34 #include "base/metrics/histogram_macros.h" | 34 #include "base/metrics/histogram_macros.h" |
35 #include "base/stl_util.h" | 35 #include "base/stl_util.h" |
36 #include "base/strings/string_util.h" | 36 #include "base/strings/string_util.h" |
37 #include "base/strings/stringprintf.h" | 37 #include "base/strings/stringprintf.h" |
38 #include "base/strings/utf_string_conversions.h" | 38 #include "base/strings/utf_string_conversions.h" |
| 39 #include "base/task_runner_util.h" |
39 #include "content/browser/download/download_create_info.h" | 40 #include "content/browser/download/download_create_info.h" |
40 #include "content/browser/download/download_file.h" | 41 #include "content/browser/download/download_file.h" |
41 #include "content/browser/download/download_interrupt_reasons_impl.h" | 42 #include "content/browser/download/download_interrupt_reasons_impl.h" |
42 #include "content/browser/download/download_item_impl_delegate.h" | 43 #include "content/browser/download/download_item_impl_delegate.h" |
43 #include "content/browser/download/download_job_factory.h" | 44 #include "content/browser/download/download_job_factory.h" |
44 #include "content/browser/download/download_job_impl.h" | 45 #include "content/browser/download/download_job_impl.h" |
45 #include "content/browser/download/download_net_log_parameters.h" | 46 #include "content/browser/download/download_net_log_parameters.h" |
46 #include "content/browser/download/download_request_handle.h" | 47 #include "content/browser/download/download_request_handle.h" |
47 #include "content/browser/download/download_stats.h" | 48 #include "content/browser/download/download_stats.h" |
| 49 #include "content/browser/download/download_task_runner.h" |
48 #include "content/browser/download/parallel_download_utils.h" | 50 #include "content/browser/download/parallel_download_utils.h" |
49 #include "content/browser/renderer_host/render_view_host_impl.h" | 51 #include "content/browser/renderer_host/render_view_host_impl.h" |
50 #include "content/browser/web_contents/web_contents_impl.h" | 52 #include "content/browser/web_contents/web_contents_impl.h" |
51 #include "content/public/browser/browser_context.h" | 53 #include "content/public/browser/browser_context.h" |
52 #include "content/public/browser/browser_thread.h" | 54 #include "content/public/browser/browser_thread.h" |
53 #include "content/public/browser/content_browser_client.h" | 55 #include "content/public/browser/content_browser_client.h" |
54 #include "content/public/browser/download_danger_type.h" | 56 #include "content/public/browser/download_danger_type.h" |
55 #include "content/public/browser/download_interrupt_reasons.h" | 57 #include "content/public/browser/download_interrupt_reasons.h" |
56 #include "content/public/browser/download_url_parameters.h" | 58 #include "content/public/browser/download_url_parameters.h" |
57 #include "content/public/browser/storage_partition.h" | 59 #include "content/public/browser/storage_partition.h" |
58 #include "content/public/common/content_features.h" | 60 #include "content/public/common/content_features.h" |
59 #include "content/public/common/referrer.h" | 61 #include "content/public/common/referrer.h" |
60 #include "net/http/http_response_headers.h" | 62 #include "net/http/http_response_headers.h" |
61 #include "net/log/net_log.h" | 63 #include "net/log/net_log.h" |
62 #include "net/log/net_log_event_type.h" | 64 #include "net/log/net_log_event_type.h" |
63 #include "net/log/net_log_parameters_callback.h" | 65 #include "net/log/net_log_parameters_callback.h" |
64 #include "net/log/net_log_source.h" | 66 #include "net/log/net_log_source.h" |
65 #include "net/traffic_annotation/network_traffic_annotation.h" | 67 #include "net/traffic_annotation/network_traffic_annotation.h" |
66 | 68 |
67 namespace content { | 69 namespace content { |
68 | 70 |
69 namespace { | 71 namespace { |
70 | 72 |
71 bool DeleteDownloadedFile(const base::FilePath& path) { | 73 bool DeleteDownloadedFile(const base::FilePath& path) { |
72 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 74 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
73 | 75 |
74 // Make sure we only delete files. | 76 // Make sure we only delete files. |
75 if (base::DirectoryExists(path)) | 77 if (base::DirectoryExists(path)) |
76 return true; | 78 return true; |
77 return base::DeleteFile(path, false); | 79 return base::DeleteFile(path, false); |
78 } | 80 } |
79 | 81 |
80 void DeleteDownloadedFileDone( | 82 void DeleteDownloadedFileDone( |
81 base::WeakPtr<DownloadItemImpl> item, | 83 base::WeakPtr<DownloadItemImpl> item, |
82 const base::Callback<void(bool)>& callback, | 84 const base::Callback<void(bool)>& callback, |
83 bool success) { | 85 bool success) { |
84 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 86 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
85 if (success && item.get()) | 87 if (success && item.get()) |
86 item->OnDownloadedFileRemoved(); | 88 item->OnDownloadedFileRemoved(); |
87 callback.Run(success); | 89 callback.Run(success); |
88 } | 90 } |
89 | 91 |
90 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that | 92 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that |
91 // takes ownership of the DownloadFile and hence implicitly destroys it | 93 // takes ownership of the DownloadFile and hence implicitly destroys it |
92 // at the end of the function. | 94 // at the end of the function. |
93 static base::FilePath DownloadFileDetach( | 95 static base::FilePath DownloadFileDetach( |
94 std::unique_ptr<DownloadFile> download_file) { | 96 std::unique_ptr<DownloadFile> download_file) { |
95 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 97 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
96 base::FilePath full_path = download_file->FullPath(); | 98 base::FilePath full_path = download_file->FullPath(); |
97 download_file->Detach(); | 99 download_file->Detach(); |
98 return full_path; | 100 return full_path; |
99 } | 101 } |
100 | 102 |
101 static base::FilePath MakeCopyOfDownloadFile(DownloadFile* download_file) { | 103 static base::FilePath MakeCopyOfDownloadFile(DownloadFile* download_file) { |
102 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 104 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
103 base::FilePath temp_file_path; | 105 base::FilePath temp_file_path; |
104 if (base::CreateTemporaryFile(&temp_file_path) && | 106 if (base::CreateTemporaryFile(&temp_file_path) && |
105 base::CopyFile(download_file->FullPath(), temp_file_path)) { | 107 base::CopyFile(download_file->FullPath(), temp_file_path)) { |
106 return temp_file_path; | 108 return temp_file_path; |
107 } else { | 109 } else { |
108 // Deletes the file at |temp_file_path|. | 110 // Deletes the file at |temp_file_path|. |
109 if (!base::DirectoryExists(temp_file_path)) | 111 if (!base::DirectoryExists(temp_file_path)) |
110 base::DeleteFile(temp_file_path, false); | 112 base::DeleteFile(temp_file_path, false); |
111 temp_file_path.clear(); | 113 temp_file_path.clear(); |
112 return base::FilePath(); | 114 return base::FilePath(); |
113 } | 115 } |
114 } | 116 } |
115 | 117 |
116 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { | 118 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { |
117 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 119 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
118 download_file->Cancel(); | 120 download_file->Cancel(); |
119 } | 121 } |
120 | 122 |
121 // Most of the cancellation pathways behave the same whether the cancellation | 123 // Most of the cancellation pathways behave the same whether the cancellation |
122 // was initiated by ther user (CANCELED) or initiated due to browser context | 124 // was initiated by ther user (CANCELED) or initiated due to browser context |
123 // shutdown (SHUTDOWN). | 125 // shutdown (SHUTDOWN). |
124 bool IsCancellation(DownloadInterruptReason reason) { | 126 bool IsCancellation(DownloadInterruptReason reason) { |
125 return reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN || | 127 return reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN || |
126 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; | 128 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; |
127 } | 129 } |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 void DownloadItemImpl::StealDangerousDownload( | 404 void DownloadItemImpl::StealDangerousDownload( |
403 bool delete_file_afterward, | 405 bool delete_file_afterward, |
404 const AcquireFileCallback& callback) { | 406 const AcquireFileCallback& callback) { |
405 DVLOG(20) << __func__ << "() download = " << DebugString(true); | 407 DVLOG(20) << __func__ << "() download = " << DebugString(true); |
406 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 408 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
407 DCHECK(IsDangerous()); | 409 DCHECK(IsDangerous()); |
408 DCHECK(AllDataSaved()); | 410 DCHECK(AllDataSaved()); |
409 | 411 |
410 if (delete_file_afterward) { | 412 if (delete_file_afterward) { |
411 if (download_file_) { | 413 if (download_file_) { |
412 BrowserThread::PostTaskAndReplyWithResult( | 414 PostTaskAndReplyWithResult( |
413 BrowserThread::FILE, FROM_HERE, | 415 GetDownloadTaskRunner().get(), FROM_HERE, |
414 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), | 416 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), |
415 callback); | 417 callback); |
416 } else { | 418 } else { |
417 callback.Run(GetFullPath()); | 419 callback.Run(GetFullPath()); |
418 } | 420 } |
419 destination_info_.current_path.clear(); | 421 destination_info_.current_path.clear(); |
420 Remove(); | 422 Remove(); |
421 // Download item has now been deleted. | 423 // Download item has now been deleted. |
422 } else if (download_file_) { | 424 } else if (download_file_) { |
423 BrowserThread::PostTaskAndReplyWithResult( | 425 PostTaskAndReplyWithResult( |
424 BrowserThread::FILE, FROM_HERE, | 426 GetDownloadTaskRunner().get(), FROM_HERE, |
425 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), callback); | 427 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), callback); |
426 } else { | 428 } else { |
427 callback.Run(GetFullPath()); | 429 callback.Run(GetFullPath()); |
428 } | 430 } |
429 } | 431 } |
430 | 432 |
431 void DownloadItemImpl::Pause() { | 433 void DownloadItemImpl::Pause() { |
432 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 434 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
433 | 435 |
434 // Ignore irrelevant states. | 436 // Ignore irrelevant states. |
(...skipping 14 matching lines...) Expand all Loading... |
449 // associated with this DII. When a request is assigned (due to a | 451 // associated with this DII. When a request is assigned (due to a |
450 // resumption, for example) we can honor the |DownloadJob::is_paused_| | 452 // resumption, for example) we can honor the |DownloadJob::is_paused_| |
451 // setting. | 453 // setting. |
452 return; | 454 return; |
453 | 455 |
454 case IN_PROGRESS_INTERNAL: | 456 case IN_PROGRESS_INTERNAL: |
455 case TARGET_PENDING_INTERNAL: | 457 case TARGET_PENDING_INTERNAL: |
456 job_->Pause(); | 458 job_->Pause(); |
457 UpdateObservers(); | 459 UpdateObservers(); |
458 if (download_file_) { | 460 if (download_file_) { |
459 BrowserThread::PostTask( | 461 GetDownloadTaskRunner()->PostTask( |
460 BrowserThread::FILE, FROM_HERE, | 462 FROM_HERE, |
461 base::Bind(&DownloadFile::WasPaused, | 463 base::Bind(&DownloadFile::WasPaused, |
462 // Safe because we control download file lifetime. | 464 // Safe because we control download file lifetime. |
463 base::Unretained(download_file_.get()))); | 465 base::Unretained(download_file_.get()))); |
464 } | 466 } |
465 return; | 467 return; |
466 | 468 |
467 case MAX_DOWNLOAD_INTERNAL_STATE: | 469 case MAX_DOWNLOAD_INTERNAL_STATE: |
468 case TARGET_RESOLVED_INTERNAL: | 470 case TARGET_RESOLVED_INTERNAL: |
469 NOTREACHED(); | 471 NOTREACHED(); |
470 } | 472 } |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 return; | 759 return; |
758 } | 760 } |
759 if (GetFullPath().empty() || file_externally_removed_) { | 761 if (GetFullPath().empty() || file_externally_removed_) { |
760 // Pass a null WeakPtr so it doesn't call OnDownloadedFileRemoved. | 762 // Pass a null WeakPtr so it doesn't call OnDownloadedFileRemoved. |
761 BrowserThread::PostTask( | 763 BrowserThread::PostTask( |
762 BrowserThread::UI, FROM_HERE, | 764 BrowserThread::UI, FROM_HERE, |
763 base::Bind(&DeleteDownloadedFileDone, | 765 base::Bind(&DeleteDownloadedFileDone, |
764 base::WeakPtr<DownloadItemImpl>(), callback, true)); | 766 base::WeakPtr<DownloadItemImpl>(), callback, true)); |
765 return; | 767 return; |
766 } | 768 } |
767 BrowserThread::PostTaskAndReplyWithResult( | 769 PostTaskAndReplyWithResult( |
768 BrowserThread::FILE, FROM_HERE, | 770 GetDownloadTaskRunner().get(), FROM_HERE, |
769 base::Bind(&DeleteDownloadedFile, GetFullPath()), | 771 base::Bind(&DeleteDownloadedFile, GetFullPath()), |
770 base::Bind(&DeleteDownloadedFileDone, weak_ptr_factory_.GetWeakPtr(), | 772 base::Bind(&DeleteDownloadedFileDone, weak_ptr_factory_.GetWeakPtr(), |
771 callback)); | 773 callback)); |
772 } | 774 } |
773 | 775 |
774 bool DownloadItemImpl::IsDangerous() const { | 776 bool DownloadItemImpl::IsDangerous() const { |
775 return (danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || | 777 return (danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || |
776 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || | 778 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || |
777 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || | 779 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || |
778 danger_type_ == DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || | 780 danger_type_ == DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 | 1485 |
1484 // Rename to intermediate name. | 1486 // Rename to intermediate name. |
1485 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a | 1487 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a |
1486 // spurious rename when we can just rename to the final | 1488 // spurious rename when we can just rename to the final |
1487 // filename. Unnecessary renames may cause bugs like | 1489 // filename. Unnecessary renames may cause bugs like |
1488 // http://crbug.com/74187. | 1490 // http://crbug.com/74187. |
1489 DCHECK(!IsSavePackageDownload()); | 1491 DCHECK(!IsSavePackageDownload()); |
1490 DownloadFile::RenameCompletionCallback callback = | 1492 DownloadFile::RenameCompletionCallback callback = |
1491 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, | 1493 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, |
1492 weak_ptr_factory_.GetWeakPtr()); | 1494 weak_ptr_factory_.GetWeakPtr()); |
1493 BrowserThread::PostTask( | 1495 GetDownloadTaskRunner()->PostTask( |
1494 BrowserThread::FILE, FROM_HERE, | 1496 FROM_HERE, base::Bind(&DownloadFile::RenameAndUniquify, |
1495 base::Bind(&DownloadFile::RenameAndUniquify, | 1497 // Safe because we control download file lifetime. |
1496 // Safe because we control download file lifetime. | 1498 base::Unretained(download_file_.get()), |
1497 base::Unretained(download_file_.get()), | 1499 intermediate_path, callback)); |
1498 intermediate_path, callback)); | |
1499 } | 1500 } |
1500 | 1501 |
1501 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( | 1502 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( |
1502 DownloadInterruptReason reason, | 1503 DownloadInterruptReason reason, |
1503 const base::FilePath& full_path) { | 1504 const base::FilePath& full_path) { |
1504 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1505 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1505 DCHECK(state_ == TARGET_PENDING_INTERNAL || | 1506 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
1506 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); | 1507 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); |
1507 DCHECK(download_file_); | 1508 DCHECK(download_file_); |
1508 DVLOG(20) << __func__ << "() download=" << DebugString(true); | 1509 DVLOG(20) << __func__ << "() download=" << DebugString(true); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 DVLOG(20) << __func__ << "() " << DebugString(true); | 1595 DVLOG(20) << __func__ << "() " << DebugString(true); |
1595 DCHECK(!GetTargetFilePath().empty()); | 1596 DCHECK(!GetTargetFilePath().empty()); |
1596 DCHECK(!IsDangerous()); | 1597 DCHECK(!IsDangerous()); |
1597 | 1598 |
1598 DCHECK(download_file_.get()); | 1599 DCHECK(download_file_.get()); |
1599 // Unilaterally rename; even if it already has the right name, | 1600 // Unilaterally rename; even if it already has the right name, |
1600 // we need theannotation. | 1601 // we need theannotation. |
1601 DownloadFile::RenameCompletionCallback callback = | 1602 DownloadFile::RenameCompletionCallback callback = |
1602 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, | 1603 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, |
1603 weak_ptr_factory_.GetWeakPtr()); | 1604 weak_ptr_factory_.GetWeakPtr()); |
1604 BrowserThread::PostTask( | 1605 GetDownloadTaskRunner()->PostTask( |
1605 BrowserThread::FILE, | |
1606 FROM_HERE, | 1606 FROM_HERE, |
1607 base::Bind(&DownloadFile::RenameAndAnnotate, | 1607 base::Bind(&DownloadFile::RenameAndAnnotate, |
1608 base::Unretained(download_file_.get()), | 1608 base::Unretained(download_file_.get()), GetTargetFilePath(), |
1609 GetTargetFilePath(), | 1609 delegate_->GetApplicationClientIdForFileScanning(), GetURL(), |
1610 delegate_->GetApplicationClientIdForFileScanning(), | 1610 GetReferrerUrl(), callback)); |
1611 GetURL(), | |
1612 GetReferrerUrl(), | |
1613 callback)); | |
1614 } | 1611 } |
1615 | 1612 |
1616 void DownloadItemImpl::OnDownloadRenamedToFinalName( | 1613 void DownloadItemImpl::OnDownloadRenamedToFinalName( |
1617 DownloadInterruptReason reason, | 1614 DownloadInterruptReason reason, |
1618 const base::FilePath& full_path) { | 1615 const base::FilePath& full_path) { |
1619 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1616 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1620 DCHECK(!IsSavePackageDownload()); | 1617 DCHECK(!IsSavePackageDownload()); |
1621 | 1618 |
1622 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which | 1619 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which |
1623 // will result in deleting the file on the file thread. So we don't | 1620 // will result in deleting the file on the file thread. So we don't |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1785 // The first non-cancel interrupt reason wins in cases where multiple | 1782 // The first non-cancel interrupt reason wins in cases where multiple |
1786 // things go wrong. | 1783 // things go wrong. |
1787 if (!IsCancellation(reason)) | 1784 if (!IsCancellation(reason)) |
1788 return; | 1785 return; |
1789 | 1786 |
1790 last_reason_ = reason; | 1787 last_reason_ = reason; |
1791 if (!GetFullPath().empty()) { | 1788 if (!GetFullPath().empty()) { |
1792 // There is no download file and this is transitioning from INTERRUPTED | 1789 // There is no download file and this is transitioning from INTERRUPTED |
1793 // to CANCELLED. The intermediate file is no longer usable, and should | 1790 // to CANCELLED. The intermediate file is no longer usable, and should |
1794 // be deleted. | 1791 // be deleted. |
1795 BrowserThread::PostTask( | 1792 GetDownloadTaskRunner()->PostTask( |
1796 BrowserThread::FILE, FROM_HERE, | 1793 FROM_HERE, base::Bind(base::IgnoreResult(&DeleteDownloadedFile), |
1797 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), | 1794 GetFullPath())); |
1798 GetFullPath())); | |
1799 destination_info_.current_path.clear(); | 1795 destination_info_.current_path.clear(); |
1800 } | 1796 } |
1801 break; | 1797 break; |
1802 } | 1798 } |
1803 | 1799 |
1804 // Reset all data saved, as even if we did save all the data we're going to go | 1800 // Reset all data saved, as even if we did save all the data we're going to go |
1805 // through another round of downloading when we resume. There's a potential | 1801 // through another round of downloading when we resume. There's a potential |
1806 // problem here in the abstract, as if we did download all the data and then | 1802 // problem here in the abstract, as if we did download all the data and then |
1807 // run into a continuable error, on resumption we won't download any more | 1803 // run into a continuable error, on resumption we won't download any more |
1808 // data. However, a) there are currently no continuable errors that can occur | 1804 // data. However, a) there are currently no continuable errors that can occur |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1885 std::vector<char> hash_value(clone_of_hash_state->GetHashLength()); | 1881 std::vector<char> hash_value(clone_of_hash_state->GetHashLength()); |
1886 clone_of_hash_state->Finish(&hash_value.front(), hash_value.size()); | 1882 clone_of_hash_state->Finish(&hash_value.front(), hash_value.size()); |
1887 destination_info_.hash.assign(hash_value.begin(), hash_value.end()); | 1883 destination_info_.hash.assign(hash_value.begin(), hash_value.end()); |
1888 } | 1884 } |
1889 | 1885 |
1890 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { | 1886 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { |
1891 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1887 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1892 DVLOG(20) << __func__ << "() destroy_file:" << destroy_file; | 1888 DVLOG(20) << __func__ << "() destroy_file:" << destroy_file; |
1893 | 1889 |
1894 if (destroy_file) { | 1890 if (destroy_file) { |
1895 BrowserThread::PostTask( | 1891 GetDownloadTaskRunner()->PostTask( |
1896 BrowserThread::FILE, FROM_HERE, | 1892 FROM_HERE, |
1897 // Will be deleted at end of task execution. | 1893 // Will be deleted at end of task execution. |
1898 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); | 1894 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); |
1899 // Avoid attempting to reuse the intermediate file by clearing out | 1895 // Avoid attempting to reuse the intermediate file by clearing out |
1900 // current_path_ and received slices. | 1896 // current_path_ and received slices. |
1901 destination_info_.current_path.clear(); | 1897 destination_info_.current_path.clear(); |
1902 received_slices_.clear(); | 1898 received_slices_.clear(); |
1903 } else { | 1899 } else { |
1904 BrowserThread::PostTask( | 1900 GetDownloadTaskRunner()->PostTask( |
1905 BrowserThread::FILE, | 1901 FROM_HERE, base::Bind(base::IgnoreResult(&DownloadFileDetach), |
1906 FROM_HERE, | 1902 // Will be deleted at end of task execution. |
1907 base::Bind(base::IgnoreResult(&DownloadFileDetach), | 1903 base::Passed(&download_file_))); |
1908 // Will be deleted at end of task execution. | |
1909 base::Passed(&download_file_))); | |
1910 } | 1904 } |
1911 // Don't accept any more messages from the DownloadFile, and null | 1905 // Don't accept any more messages from the DownloadFile, and null |
1912 // out any previous "all data received". This also breaks links to | 1906 // out any previous "all data received". This also breaks links to |
1913 // other entities we've given out weak pointers to. | 1907 // other entities we've given out weak pointers to. |
1914 weak_ptr_factory_.InvalidateWeakPtrs(); | 1908 weak_ptr_factory_.InvalidateWeakPtrs(); |
1915 } | 1909 } |
1916 | 1910 |
1917 bool DownloadItemImpl::IsDownloadReadyForCompletion( | 1911 bool DownloadItemImpl::IsDownloadReadyForCompletion( |
1918 const base::Closure& state_change_notification) { | 1912 const base::Closure& state_change_notification) { |
1919 // If the download hasn't progressed to the IN_PROGRESS state, then it's not | 1913 // If the download hasn't progressed to the IN_PROGRESS state, then it's not |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2342 case RESUME_MODE_USER_CONTINUE: | 2336 case RESUME_MODE_USER_CONTINUE: |
2343 return "USER_CONTINUE"; | 2337 return "USER_CONTINUE"; |
2344 case RESUME_MODE_USER_RESTART: | 2338 case RESUME_MODE_USER_RESTART: |
2345 return "USER_RESTART"; | 2339 return "USER_RESTART"; |
2346 } | 2340 } |
2347 NOTREACHED() << "Unknown resume mode " << mode; | 2341 NOTREACHED() << "Unknown resume mode " << mode; |
2348 return "unknown"; | 2342 return "unknown"; |
2349 } | 2343 } |
2350 | 2344 |
2351 } // namespace content | 2345 } // namespace content |
OLD | NEW |