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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 | 1489 |
1488 // Rename to intermediate name. | 1490 // Rename to intermediate name. |
1489 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a | 1491 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a |
1490 // spurious rename when we can just rename to the final | 1492 // spurious rename when we can just rename to the final |
1491 // filename. Unnecessary renames may cause bugs like | 1493 // filename. Unnecessary renames may cause bugs like |
1492 // http://crbug.com/74187. | 1494 // http://crbug.com/74187. |
1493 DCHECK(!IsSavePackageDownload()); | 1495 DCHECK(!IsSavePackageDownload()); |
1494 DownloadFile::RenameCompletionCallback callback = | 1496 DownloadFile::RenameCompletionCallback callback = |
1495 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, | 1497 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, |
1496 weak_ptr_factory_.GetWeakPtr()); | 1498 weak_ptr_factory_.GetWeakPtr()); |
1497 BrowserThread::PostTask( | 1499 GetDownloadTaskRunner()->PostTask( |
1498 BrowserThread::FILE, FROM_HERE, | 1500 FROM_HERE, base::Bind(&DownloadFile::RenameAndUniquify, |
1499 base::Bind(&DownloadFile::RenameAndUniquify, | 1501 // Safe because we control download file lifetime. |
1500 // Safe because we control download file lifetime. | 1502 base::Unretained(download_file_.get()), |
1501 base::Unretained(download_file_.get()), | 1503 intermediate_path, callback)); |
1502 intermediate_path, callback)); | |
1503 } | 1504 } |
1504 | 1505 |
1505 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( | 1506 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( |
1506 DownloadInterruptReason reason, | 1507 DownloadInterruptReason reason, |
1507 const base::FilePath& full_path) { | 1508 const base::FilePath& full_path) { |
1508 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1509 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1509 DCHECK(state_ == TARGET_PENDING_INTERNAL || | 1510 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
1510 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); | 1511 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); |
1511 DCHECK(download_file_); | 1512 DCHECK(download_file_); |
1512 DVLOG(20) << __func__ << "() download=" << DebugString(true); | 1513 DVLOG(20) << __func__ << "() download=" << DebugString(true); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 DVLOG(20) << __func__ << "() " << DebugString(true); | 1599 DVLOG(20) << __func__ << "() " << DebugString(true); |
1599 DCHECK(!GetTargetFilePath().empty()); | 1600 DCHECK(!GetTargetFilePath().empty()); |
1600 DCHECK(!IsDangerous()); | 1601 DCHECK(!IsDangerous()); |
1601 | 1602 |
1602 DCHECK(download_file_.get()); | 1603 DCHECK(download_file_.get()); |
1603 // Unilaterally rename; even if it already has the right name, | 1604 // Unilaterally rename; even if it already has the right name, |
1604 // we need theannotation. | 1605 // we need theannotation. |
1605 DownloadFile::RenameCompletionCallback callback = | 1606 DownloadFile::RenameCompletionCallback callback = |
1606 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, | 1607 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, |
1607 weak_ptr_factory_.GetWeakPtr()); | 1608 weak_ptr_factory_.GetWeakPtr()); |
1608 BrowserThread::PostTask( | 1609 GetDownloadTaskRunner()->PostTask( |
1609 BrowserThread::FILE, | |
1610 FROM_HERE, | 1610 FROM_HERE, |
1611 base::Bind(&DownloadFile::RenameAndAnnotate, | 1611 base::Bind(&DownloadFile::RenameAndAnnotate, |
1612 base::Unretained(download_file_.get()), | 1612 base::Unretained(download_file_.get()), GetTargetFilePath(), |
1613 GetTargetFilePath(), | 1613 delegate_->GetApplicationClientIdForFileScanning(), GetURL(), |
1614 delegate_->GetApplicationClientIdForFileScanning(), | 1614 GetReferrerUrl(), callback)); |
1615 GetURL(), | |
1616 GetReferrerUrl(), | |
1617 callback)); | |
1618 } | 1615 } |
1619 | 1616 |
1620 void DownloadItemImpl::OnDownloadRenamedToFinalName( | 1617 void DownloadItemImpl::OnDownloadRenamedToFinalName( |
1621 DownloadInterruptReason reason, | 1618 DownloadInterruptReason reason, |
1622 const base::FilePath& full_path) { | 1619 const base::FilePath& full_path) { |
1623 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1620 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1624 DCHECK(!IsSavePackageDownload()); | 1621 DCHECK(!IsSavePackageDownload()); |
1625 | 1622 |
1626 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which | 1623 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which |
1627 // will result in deleting the file on the file thread. So we don't | 1624 // 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... |
1789 // The first non-cancel interrupt reason wins in cases where multiple | 1786 // The first non-cancel interrupt reason wins in cases where multiple |
1790 // things go wrong. | 1787 // things go wrong. |
1791 if (!IsCancellation(reason)) | 1788 if (!IsCancellation(reason)) |
1792 return; | 1789 return; |
1793 | 1790 |
1794 last_reason_ = reason; | 1791 last_reason_ = reason; |
1795 if (!GetFullPath().empty()) { | 1792 if (!GetFullPath().empty()) { |
1796 // There is no download file and this is transitioning from INTERRUPTED | 1793 // There is no download file and this is transitioning from INTERRUPTED |
1797 // to CANCELLED. The intermediate file is no longer usable, and should | 1794 // to CANCELLED. The intermediate file is no longer usable, and should |
1798 // be deleted. | 1795 // be deleted. |
1799 BrowserThread::PostTask( | 1796 GetDownloadTaskRunner()->PostTask( |
1800 BrowserThread::FILE, FROM_HERE, | 1797 FROM_HERE, base::Bind(base::IgnoreResult(&DeleteDownloadedFile), |
1801 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), | 1798 GetFullPath())); |
1802 GetFullPath())); | |
1803 destination_info_.current_path.clear(); | 1799 destination_info_.current_path.clear(); |
1804 } | 1800 } |
1805 break; | 1801 break; |
1806 } | 1802 } |
1807 | 1803 |
1808 // Reset all data saved, as even if we did save all the data we're going to go | 1804 // Reset all data saved, as even if we did save all the data we're going to go |
1809 // through another round of downloading when we resume. There's a potential | 1805 // through another round of downloading when we resume. There's a potential |
1810 // problem here in the abstract, as if we did download all the data and then | 1806 // problem here in the abstract, as if we did download all the data and then |
1811 // run into a continuable error, on resumption we won't download any more | 1807 // run into a continuable error, on resumption we won't download any more |
1812 // data. However, a) there are currently no continuable errors that can occur | 1808 // 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... |
1889 std::vector<char> hash_value(clone_of_hash_state->GetHashLength()); | 1885 std::vector<char> hash_value(clone_of_hash_state->GetHashLength()); |
1890 clone_of_hash_state->Finish(&hash_value.front(), hash_value.size()); | 1886 clone_of_hash_state->Finish(&hash_value.front(), hash_value.size()); |
1891 destination_info_.hash.assign(hash_value.begin(), hash_value.end()); | 1887 destination_info_.hash.assign(hash_value.begin(), hash_value.end()); |
1892 } | 1888 } |
1893 | 1889 |
1894 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { | 1890 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { |
1895 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1891 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1896 DVLOG(20) << __func__ << "() destroy_file:" << destroy_file; | 1892 DVLOG(20) << __func__ << "() destroy_file:" << destroy_file; |
1897 | 1893 |
1898 if (destroy_file) { | 1894 if (destroy_file) { |
1899 BrowserThread::PostTask( | 1895 GetDownloadTaskRunner()->PostTask( |
1900 BrowserThread::FILE, FROM_HERE, | 1896 FROM_HERE, |
1901 // Will be deleted at end of task execution. | 1897 // Will be deleted at end of task execution. |
1902 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); | 1898 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); |
1903 // Avoid attempting to reuse the intermediate file by clearing out | 1899 // Avoid attempting to reuse the intermediate file by clearing out |
1904 // current_path_ and received slices. | 1900 // current_path_ and received slices. |
1905 destination_info_.current_path.clear(); | 1901 destination_info_.current_path.clear(); |
1906 received_slices_.clear(); | 1902 received_slices_.clear(); |
1907 } else { | 1903 } else { |
1908 BrowserThread::PostTask( | 1904 GetDownloadTaskRunner()->PostTask( |
1909 BrowserThread::FILE, | 1905 FROM_HERE, base::Bind(base::IgnoreResult(&DownloadFileDetach), |
1910 FROM_HERE, | 1906 // Will be deleted at end of task execution. |
1911 base::Bind(base::IgnoreResult(&DownloadFileDetach), | 1907 base::Passed(&download_file_))); |
1912 // Will be deleted at end of task execution. | |
1913 base::Passed(&download_file_))); | |
1914 } | 1908 } |
1915 // Don't accept any more messages from the DownloadFile, and null | 1909 // Don't accept any more messages from the DownloadFile, and null |
1916 // out any previous "all data received". This also breaks links to | 1910 // out any previous "all data received". This also breaks links to |
1917 // other entities we've given out weak pointers to. | 1911 // other entities we've given out weak pointers to. |
1918 weak_ptr_factory_.InvalidateWeakPtrs(); | 1912 weak_ptr_factory_.InvalidateWeakPtrs(); |
1919 } | 1913 } |
1920 | 1914 |
1921 bool DownloadItemImpl::IsDownloadReadyForCompletion( | 1915 bool DownloadItemImpl::IsDownloadReadyForCompletion( |
1922 const base::Closure& state_change_notification) { | 1916 const base::Closure& state_change_notification) { |
1923 // If the download hasn't progressed to the IN_PROGRESS state, then it's not | 1917 // If the download hasn't progressed to the IN_PROGRESS state, then it's not |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2370 case RESUME_MODE_USER_CONTINUE: | 2364 case RESUME_MODE_USER_CONTINUE: |
2371 return "USER_CONTINUE"; | 2365 return "USER_CONTINUE"; |
2372 case RESUME_MODE_USER_RESTART: | 2366 case RESUME_MODE_USER_RESTART: |
2373 return "USER_RESTART"; | 2367 return "USER_RESTART"; |
2374 } | 2368 } |
2375 NOTREACHED() << "Unknown resume mode " << mode; | 2369 NOTREACHED() << "Unknown resume mode " << mode; |
2376 return "unknown"; | 2370 return "unknown"; |
2377 } | 2371 } |
2378 | 2372 |
2379 } // namespace content | 2373 } // namespace content |
OLD | NEW |