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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 last_access_time_(last_access_time), | 183 last_access_time_(last_access_time), |
184 transient_(transient), | 184 transient_(transient), |
185 current_path_(current_path), | 185 current_path_(current_path), |
186 received_bytes_(received_bytes), | 186 received_bytes_(received_bytes), |
187 all_data_saved_(state == COMPLETE), | 187 all_data_saved_(state == COMPLETE), |
188 hash_(hash), | 188 hash_(hash), |
189 last_modified_time_(last_modified), | 189 last_modified_time_(last_modified), |
190 etag_(etag), | 190 etag_(etag), |
191 received_slices_(received_slices), | 191 received_slices_(received_slices), |
192 net_log_(net_log), | 192 net_log_(net_log), |
| 193 received_bytes_if_content_length_mismatch_(-1), |
193 weak_ptr_factory_(this) { | 194 weak_ptr_factory_(this) { |
194 delegate_->Attach(); | 195 delegate_->Attach(); |
195 DCHECK(state_ == COMPLETE_INTERNAL || state_ == INTERRUPTED_INTERNAL || | 196 DCHECK(state_ == COMPLETE_INTERNAL || state_ == INTERRUPTED_INTERNAL || |
196 state_ == CANCELLED_INTERNAL); | 197 state_ == CANCELLED_INTERNAL); |
197 DCHECK(base::IsValidGUID(guid_)); | 198 DCHECK(base::IsValidGUID(guid_)); |
198 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT); | 199 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT); |
199 } | 200 } |
200 | 201 |
201 // Constructing for a regular download: | 202 // Constructing for a regular download: |
202 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, | 203 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, |
(...skipping 24 matching lines...) Expand all Loading... |
227 last_reason_(info.result), | 228 last_reason_(info.result), |
228 start_tick_(base::TimeTicks::Now()), | 229 start_tick_(base::TimeTicks::Now()), |
229 state_(INITIAL_INTERNAL), | 230 state_(INITIAL_INTERNAL), |
230 start_time_(info.start_time), | 231 start_time_(info.start_time), |
231 delegate_(delegate), | 232 delegate_(delegate), |
232 is_temporary_(!info.transient && !info.save_info->file_path.empty()), | 233 is_temporary_(!info.transient && !info.save_info->file_path.empty()), |
233 transient_(info.transient), | 234 transient_(info.transient), |
234 last_modified_time_(info.last_modified), | 235 last_modified_time_(info.last_modified), |
235 etag_(info.etag), | 236 etag_(info.etag), |
236 net_log_(net_log), | 237 net_log_(net_log), |
| 238 received_bytes_if_content_length_mismatch_(-1), |
237 weak_ptr_factory_(this) { | 239 weak_ptr_factory_(this) { |
238 delegate_->Attach(); | 240 delegate_->Attach(); |
239 Init(true /* actively downloading */, SRC_ACTIVE_DOWNLOAD); | 241 Init(true /* actively downloading */, SRC_ACTIVE_DOWNLOAD); |
240 | 242 |
241 // Link the event sources. | 243 // Link the event sources. |
242 net_log_.AddEvent( | 244 net_log_.AddEvent( |
243 net::NetLogEventType::DOWNLOAD_URL_REQUEST, | 245 net::NetLogEventType::DOWNLOAD_URL_REQUEST, |
244 info.request_net_log.source().ToEventParametersCallback()); | 246 info.request_net_log.source().ToEventParametersCallback()); |
245 | 247 |
246 info.request_net_log.AddEvent( | 248 info.request_net_log.AddEvent( |
(...skipping 16 matching lines...) Expand all Loading... |
263 target_path_(path), | 265 target_path_(path), |
264 url_chain_(1, url), | 266 url_chain_(1, url), |
265 mime_type_(mime_type), | 267 mime_type_(mime_type), |
266 original_mime_type_(mime_type), | 268 original_mime_type_(mime_type), |
267 start_tick_(base::TimeTicks::Now()), | 269 start_tick_(base::TimeTicks::Now()), |
268 state_(IN_PROGRESS_INTERNAL), | 270 state_(IN_PROGRESS_INTERNAL), |
269 start_time_(base::Time::Now()), | 271 start_time_(base::Time::Now()), |
270 delegate_(delegate), | 272 delegate_(delegate), |
271 current_path_(path), | 273 current_path_(path), |
272 net_log_(net_log), | 274 net_log_(net_log), |
| 275 received_bytes_if_content_length_mismatch_(-1), |
273 weak_ptr_factory_(this) { | 276 weak_ptr_factory_(this) { |
274 job_ = | 277 job_ = |
275 base::MakeUnique<DownloadJobImpl>(this, std::move(request_handle), false); | 278 base::MakeUnique<DownloadJobImpl>(this, std::move(request_handle), false); |
276 delegate_->Attach(); | 279 delegate_->Attach(); |
277 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); | 280 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); |
278 } | 281 } |
279 | 282 |
280 DownloadItemImpl::~DownloadItemImpl() { | 283 DownloadItemImpl::~DownloadItemImpl() { |
281 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 284 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
282 | 285 |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); | 933 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); |
931 | 934 |
932 // We won't auto-restart if we've used up our attempts or the | 935 // We won't auto-restart if we've used up our attempts or the |
933 // download has been paused by user action. | 936 // download has been paused by user action. |
934 bool user_action_required = | 937 bool user_action_required = |
935 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); | 938 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); |
936 | 939 |
937 switch(last_reason_) { | 940 switch(last_reason_) { |
938 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: | 941 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: |
939 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: | 942 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: |
| 943 case DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH: |
940 break; | 944 break; |
941 | 945 |
942 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: | 946 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: |
943 // The server disagreed with the file offset that we sent. | 947 // The server disagreed with the file offset that we sent. |
944 | 948 |
945 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: | 949 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: |
946 // The file on disk was found to not match the expected hash. Discard and | 950 // The file on disk was found to not match the expected hash. Discard and |
947 // start from beginning. | 951 // start from beginning. |
948 | 952 |
949 case DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT: | 953 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_); | 1103 DCHECK(!all_data_saved_); |
1100 all_data_saved_ = true; | 1104 all_data_saved_ = true; |
1101 SetTotalBytes(total_bytes); | 1105 SetTotalBytes(total_bytes); |
1102 UpdateProgress(total_bytes, 0); | 1106 UpdateProgress(total_bytes, 0); |
1103 received_slices_.clear(); | 1107 received_slices_.clear(); |
1104 SetHashState(std::move(hash_state)); | 1108 SetHashState(std::move(hash_state)); |
1105 hash_state_.reset(); // No need to retain hash_state_ since we are done with | 1109 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 | 1110 // the download and don't expect to receive any more |
1107 // data. | 1111 // data. |
1108 | 1112 |
| 1113 if (received_bytes_if_content_length_mismatch_ > 0) { |
| 1114 if (total_bytes > received_bytes_if_content_length_mismatch_) { |
| 1115 RecordDownloadCount( |
| 1116 MORE_BYTES_RECEIVED_AFTER_CONTENT_LENGTH_MISMATCH_COUNT); |
| 1117 } else if (total_bytes == received_bytes_if_content_length_mismatch_) { |
| 1118 RecordDownloadCount( |
| 1119 NO_BYTES_RECEIVED_AFTER_CONTENT_LENGTH_MISMATCH_COUNT); |
| 1120 } else { |
| 1121 // This could happen if the content changes on the server. |
| 1122 } |
| 1123 } |
1109 DVLOG(20) << __func__ << "() download=" << DebugString(true); | 1124 DVLOG(20) << __func__ << "() download=" << DebugString(true); |
1110 UpdateObservers(); | 1125 UpdateObservers(); |
1111 } | 1126 } |
1112 | 1127 |
1113 void DownloadItemImpl::MarkAsComplete() { | 1128 void DownloadItemImpl::MarkAsComplete() { |
1114 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1129 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1115 | 1130 |
1116 DCHECK(all_data_saved_); | 1131 DCHECK(all_data_saved_); |
1117 end_time_ = base::Time::Now(); | 1132 end_time_ = base::Time::Now(); |
1118 TransitionTo(COMPLETE_INTERNAL); | 1133 TransitionTo(COMPLETE_INTERNAL); |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 IsParallelDownloadEnabled()); | 1804 IsParallelDownloadEnabled()); |
1790 } | 1805 } |
1791 DCHECK_EQ(last_reason_, reason); | 1806 DCHECK_EQ(last_reason_, reason); |
1792 TransitionTo(CANCELLED_INTERNAL); | 1807 TransitionTo(CANCELLED_INTERNAL); |
1793 return; | 1808 return; |
1794 } | 1809 } |
1795 | 1810 |
1796 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, | 1811 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, |
1797 job_ && job_->IsParallelizable(), | 1812 job_ && job_->IsParallelizable(), |
1798 IsParallelDownloadEnabled()); | 1813 IsParallelDownloadEnabled()); |
| 1814 if (reason == DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH) |
| 1815 received_bytes_if_content_length_mismatch_ = received_bytes_; |
| 1816 |
1799 if (!GetWebContents()) | 1817 if (!GetWebContents()) |
1800 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); | 1818 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); |
1801 | 1819 |
1802 // TODO(asanka): This is not good. We can transition to interrupted from | 1820 // 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 | 1821 // 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. | 1822 // explicitly transition to target-resolved prior to switching to interrupted. |
1805 DCHECK_EQ(last_reason_, reason); | 1823 DCHECK_EQ(last_reason_, reason); |
1806 TransitionTo(INTERRUPTED_INTERNAL); | 1824 TransitionTo(INTERRUPTED_INTERNAL); |
1807 AutoResumeIfValid(); | 1825 AutoResumeIfValid(); |
1808 } | 1826 } |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2286 case RESUME_MODE_USER_CONTINUE: | 2304 case RESUME_MODE_USER_CONTINUE: |
2287 return "USER_CONTINUE"; | 2305 return "USER_CONTINUE"; |
2288 case RESUME_MODE_USER_RESTART: | 2306 case RESUME_MODE_USER_RESTART: |
2289 return "USER_RESTART"; | 2307 return "USER_RESTART"; |
2290 } | 2308 } |
2291 NOTREACHED() << "Unknown resume mode " << mode; | 2309 NOTREACHED() << "Unknown resume mode " << mode; |
2292 return "unknown"; | 2310 return "unknown"; |
2293 } | 2311 } |
2294 | 2312 |
2295 } // namespace content | 2313 } // namespace content |
OLD | NEW |