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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); | 930 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); |
931 | 931 |
932 // We won't auto-restart if we've used up our attempts or the | 932 // We won't auto-restart if we've used up our attempts or the |
933 // download has been paused by user action. | 933 // download has been paused by user action. |
934 bool user_action_required = | 934 bool user_action_required = |
935 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); | 935 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); |
936 | 936 |
937 switch(last_reason_) { | 937 switch(last_reason_) { |
938 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: | 938 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: |
939 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: | 939 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: |
| 940 case DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH: |
940 break; | 941 break; |
941 | 942 |
942 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: | 943 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: |
943 // The server disagreed with the file offset that we sent. | 944 // The server disagreed with the file offset that we sent. |
944 | 945 |
945 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: | 946 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: |
946 // The file on disk was found to not match the expected hash. Discard and | 947 // The file on disk was found to not match the expected hash. Discard and |
947 // start from beginning. | 948 // start from beginning. |
948 | 949 |
949 case DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT: | 950 case DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT: |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 DCHECK(!all_data_saved_); | 1100 DCHECK(!all_data_saved_); |
1100 all_data_saved_ = true; | 1101 all_data_saved_ = true; |
1101 SetTotalBytes(total_bytes); | 1102 SetTotalBytes(total_bytes); |
1102 UpdateProgress(total_bytes, 0); | 1103 UpdateProgress(total_bytes, 0); |
1103 received_slices_.clear(); | 1104 received_slices_.clear(); |
1104 SetHashState(std::move(hash_state)); | 1105 SetHashState(std::move(hash_state)); |
1105 hash_state_.reset(); // No need to retain hash_state_ since we are done with | 1106 hash_state_.reset(); // No need to retain hash_state_ since we are done with |
1106 // the download and don't expect to receive any more | 1107 // the download and don't expect to receive any more |
1107 // data. | 1108 // data. |
1108 | 1109 |
| 1110 if (received_bytes_at_length_mismatch > 0) { |
| 1111 if (total_bytes > received_bytes_at_length_mismatch) { |
| 1112 RecordDownloadCount( |
| 1113 MORE_BYTES_RECEIVED_AFTER_CONTENT_LENGTH_MISMATCH_COUNT); |
| 1114 } else if (total_bytes == received_bytes_at_length_mismatch) { |
| 1115 RecordDownloadCount( |
| 1116 NO_BYTES_RECEIVED_AFTER_CONTENT_LENGTH_MISMATCH_COUNT); |
| 1117 } else { |
| 1118 // This could happen if the content changes on the server. |
| 1119 } |
| 1120 } |
1109 DVLOG(20) << __func__ << "() download=" << DebugString(true); | 1121 DVLOG(20) << __func__ << "() download=" << DebugString(true); |
1110 UpdateObservers(); | 1122 UpdateObservers(); |
1111 } | 1123 } |
1112 | 1124 |
1113 void DownloadItemImpl::MarkAsComplete() { | 1125 void DownloadItemImpl::MarkAsComplete() { |
1114 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1126 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1115 | 1127 |
1116 DCHECK(all_data_saved_); | 1128 DCHECK(all_data_saved_); |
1117 end_time_ = base::Time::Now(); | 1129 end_time_ = base::Time::Now(); |
1118 TransitionTo(COMPLETE_INTERNAL); | 1130 TransitionTo(COMPLETE_INTERNAL); |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 IsParallelDownloadEnabled()); | 1801 IsParallelDownloadEnabled()); |
1790 } | 1802 } |
1791 DCHECK_EQ(last_reason_, reason); | 1803 DCHECK_EQ(last_reason_, reason); |
1792 TransitionTo(CANCELLED_INTERNAL); | 1804 TransitionTo(CANCELLED_INTERNAL); |
1793 return; | 1805 return; |
1794 } | 1806 } |
1795 | 1807 |
1796 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, | 1808 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, |
1797 job_ && job_->IsParallelizable(), | 1809 job_ && job_->IsParallelizable(), |
1798 IsParallelDownloadEnabled()); | 1810 IsParallelDownloadEnabled()); |
| 1811 if (reason == DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH) |
| 1812 received_bytes_at_length_mismatch = received_bytes_; |
| 1813 |
1799 if (!GetWebContents()) | 1814 if (!GetWebContents()) |
1800 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); | 1815 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); |
1801 | 1816 |
1802 // TODO(asanka): This is not good. We can transition to interrupted from | 1817 // TODO(asanka): This is not good. We can transition to interrupted from |
1803 // target-pending, which is something we don't want to do. Perhaps we should | 1818 // target-pending, which is something we don't want to do. Perhaps we should |
1804 // explicitly transition to target-resolved prior to switching to interrupted. | 1819 // explicitly transition to target-resolved prior to switching to interrupted. |
1805 DCHECK_EQ(last_reason_, reason); | 1820 DCHECK_EQ(last_reason_, reason); |
1806 TransitionTo(INTERRUPTED_INTERNAL); | 1821 TransitionTo(INTERRUPTED_INTERNAL); |
1807 AutoResumeIfValid(); | 1822 AutoResumeIfValid(); |
1808 } | 1823 } |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2286 case RESUME_MODE_USER_CONTINUE: | 2301 case RESUME_MODE_USER_CONTINUE: |
2287 return "USER_CONTINUE"; | 2302 return "USER_CONTINUE"; |
2288 case RESUME_MODE_USER_RESTART: | 2303 case RESUME_MODE_USER_RESTART: |
2289 return "USER_RESTART"; | 2304 return "USER_RESTART"; |
2290 } | 2305 } |
2291 NOTREACHED() << "Unknown resume mode " << mode; | 2306 NOTREACHED() << "Unknown resume mode " << mode; |
2292 return "unknown"; | 2307 return "unknown"; |
2293 } | 2308 } |
2294 | 2309 |
2295 } // namespace content | 2310 } // namespace content |
OLD | NEW |