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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 base::FilePath full_path = download_file->FullPath(); | 88 base::FilePath full_path = download_file->FullPath(); |
89 download_file->Detach(); | 89 download_file->Detach(); |
90 return full_path; | 90 return full_path; |
91 } | 91 } |
92 | 92 |
93 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { | 93 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { |
94 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 94 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
95 download_file->Cancel(); | 95 download_file->Cancel(); |
96 } | 96 } |
97 | 97 |
98 bool IsDownloadResumptionEnabled() { | |
99 return base::FeatureList::IsEnabled(features::kDownloadResumption); | |
100 } | |
101 | |
102 } // namespace | 98 } // namespace |
103 | 99 |
104 const uint32_t DownloadItem::kInvalidId = 0; | 100 const uint32_t DownloadItem::kInvalidId = 0; |
105 | 101 |
106 // The maximum number of attempts we will make to resume automatically. | 102 // The maximum number of attempts we will make to resume automatically. |
107 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; | 103 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; |
108 | 104 |
109 // Constructor for reading from the history service. | 105 // Constructor for reading from the history service. |
110 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, | 106 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, |
111 const std::string& guid, | 107 const std::string& guid, |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 472 |
477 case TARGET_PENDING_INTERNAL: | 473 case TARGET_PENDING_INTERNAL: |
478 case TARGET_RESOLVED_INTERNAL: | 474 case TARGET_RESOLVED_INTERNAL: |
479 case IN_PROGRESS_INTERNAL: | 475 case IN_PROGRESS_INTERNAL: |
480 return is_paused_; | 476 return is_paused_; |
481 | 477 |
482 case INTERRUPTED_INTERNAL: { | 478 case INTERRUPTED_INTERNAL: { |
483 ResumeMode resume_mode = GetResumeMode(); | 479 ResumeMode resume_mode = GetResumeMode(); |
484 // Only allow Resume() calls if the resumption mode requires a user | 480 // Only allow Resume() calls if the resumption mode requires a user |
485 // action. | 481 // action. |
486 return IsDownloadResumptionEnabled() && | 482 return resume_mode == RESUME_MODE_USER_RESTART || |
487 (resume_mode == RESUME_MODE_USER_RESTART || | 483 resume_mode == RESUME_MODE_USER_CONTINUE; |
488 resume_mode == RESUME_MODE_USER_CONTINUE); | |
489 } | 484 } |
490 | 485 |
491 case MAX_DOWNLOAD_INTERNAL_STATE: | 486 case MAX_DOWNLOAD_INTERNAL_STATE: |
492 NOTREACHED(); | 487 NOTREACHED(); |
493 } | 488 } |
494 return false; | 489 return false; |
495 } | 490 } |
496 | 491 |
497 bool DownloadItemImpl::IsDone() const { | 492 bool DownloadItemImpl::IsDone() const { |
498 switch (state_) { | 493 switch (state_) { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 } | 832 } |
838 | 833 |
839 description += " }"; | 834 description += " }"; |
840 | 835 |
841 return description; | 836 return description; |
842 } | 837 } |
843 | 838 |
844 DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const { | 839 DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const { |
845 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 840 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
846 | 841 |
847 if (!IsDownloadResumptionEnabled()) | |
848 return RESUME_MODE_INVALID; | |
849 | |
850 // Only support resumption for HTTP(S). | 842 // Only support resumption for HTTP(S). |
851 if (!GetURL().SchemeIsHTTPOrHTTPS()) | 843 if (!GetURL().SchemeIsHTTPOrHTTPS()) |
852 return RESUME_MODE_INVALID; | 844 return RESUME_MODE_INVALID; |
853 | 845 |
854 // We can't continue without a handle on the intermediate file. | 846 // We can't continue without a handle on the intermediate file. |
855 // We also can't continue if we don't have some verifier to make sure | 847 // We also can't continue if we don't have some verifier to make sure |
856 // we're getting the same file. | 848 // we're getting the same file. |
857 bool restart_required = | 849 bool restart_required = |
858 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); | 850 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); |
859 | 851 |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1877 } | 1869 } |
1878 | 1870 |
1879 auto_resume_count_++; | 1871 auto_resume_count_++; |
1880 | 1872 |
1881 ResumeInterruptedDownload(ResumptionRequestSource::AUTOMATIC); | 1873 ResumeInterruptedDownload(ResumptionRequestSource::AUTOMATIC); |
1882 } | 1874 } |
1883 | 1875 |
1884 void DownloadItemImpl::ResumeInterruptedDownload( | 1876 void DownloadItemImpl::ResumeInterruptedDownload( |
1885 ResumptionRequestSource source) { | 1877 ResumptionRequestSource source) { |
1886 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1878 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1887 if (!IsDownloadResumptionEnabled()) | |
1888 return; | |
1889 | |
1890 // If we're not interrupted, ignore the request; our caller is drunk. | 1879 // If we're not interrupted, ignore the request; our caller is drunk. |
1891 if (state_ != INTERRUPTED_INTERNAL) | 1880 if (state_ != INTERRUPTED_INTERNAL) |
1892 return; | 1881 return; |
1893 | 1882 |
1894 // We are starting a new request. Shake off all pending operations. | 1883 // We are starting a new request. Shake off all pending operations. |
1895 DCHECK(!download_file_); | 1884 DCHECK(!download_file_); |
1896 weak_ptr_factory_.InvalidateWeakPtrs(); | 1885 weak_ptr_factory_.InvalidateWeakPtrs(); |
1897 | 1886 |
1898 // Reset the appropriate state if restarting. | 1887 // Reset the appropriate state if restarting. |
1899 ResumeMode mode = GetResumeMode(); | 1888 ResumeMode mode = GetResumeMode(); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2109 case RESUME_MODE_USER_CONTINUE: | 2098 case RESUME_MODE_USER_CONTINUE: |
2110 return "USER_CONTINUE"; | 2099 return "USER_CONTINUE"; |
2111 case RESUME_MODE_USER_RESTART: | 2100 case RESUME_MODE_USER_RESTART: |
2112 return "USER_RESTART"; | 2101 return "USER_RESTART"; |
2113 } | 2102 } |
2114 NOTREACHED() << "Unknown resume mode " << mode; | 2103 NOTREACHED() << "Unknown resume mode " << mode; |
2115 return "unknown"; | 2104 return "unknown"; |
2116 } | 2105 } |
2117 | 2106 |
2118 } // namespace content | 2107 } // namespace content |
OLD | NEW |