| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 temp_file_path.clear(); | 109 temp_file_path.clear(); |
| 110 return base::FilePath(); | 110 return base::FilePath(); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { | 114 static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { |
| 115 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 115 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 116 download_file->Cancel(); | 116 download_file->Cancel(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool IsCancellation(DownloadInterruptReason reason) { |
| 120 return reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN || |
| 121 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; |
| 122 } |
| 123 |
| 119 } // namespace | 124 } // namespace |
| 120 | 125 |
| 121 const uint32_t DownloadItem::kInvalidId = 0; | 126 const uint32_t DownloadItem::kInvalidId = 0; |
| 122 | 127 |
| 123 // The maximum number of attempts we will make to resume automatically. | 128 // The maximum number of attempts we will make to resume automatically. |
| 124 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; | 129 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; |
| 125 | 130 |
| 126 // Constructor for reading from the history service. | 131 // Constructor for reading from the history service. |
| 127 DownloadItemImpl::DownloadItemImpl( | 132 DownloadItemImpl::DownloadItemImpl( |
| 128 DownloadItemImplDelegate* delegate, | 133 DownloadItemImplDelegate* delegate, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 316 |
| 312 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED; | 317 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED; |
| 313 | 318 |
| 314 net_log_.AddEvent( | 319 net_log_.AddEvent( |
| 315 net::NetLogEventType::DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, | 320 net::NetLogEventType::DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
| 316 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); | 321 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); |
| 317 | 322 |
| 318 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download | 323 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download |
| 319 // may not be in a consistent state or around at all after | 324 // may not be in a consistent state or around at all after |
| 320 // invoking observers. http://crbug.com/586610 | 325 // invoking observers. http://crbug.com/586610 |
| 321 | |
| 322 MaybeCompleteDownload(); | 326 MaybeCompleteDownload(); |
| 323 } | 327 } |
| 324 | 328 |
| 325 void DownloadItemImpl::StealDangerousDownload( | 329 void DownloadItemImpl::StealDangerousDownload( |
| 326 bool delete_file_afterward, | 330 bool delete_file_afterward, |
| 327 const AcquireFileCallback& callback) { | 331 const AcquireFileCallback& callback) { |
| 328 DVLOG(20) << __func__ << "() download = " << DebugString(true); | 332 DVLOG(20) << __func__ << "() download = " << DebugString(true); |
| 329 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 333 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 330 DCHECK(IsDangerous()); | 334 DCHECK(IsDangerous()); |
| 331 DCHECK(AllDataSaved()); | 335 DCHECK(AllDataSaved()); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 std::string DownloadItemImpl::GetOriginalMimeType() const { | 609 std::string DownloadItemImpl::GetOriginalMimeType() const { |
| 606 return original_mime_type_; | 610 return original_mime_type_; |
| 607 } | 611 } |
| 608 | 612 |
| 609 std::string DownloadItemImpl::GetRemoteAddress() const { | 613 std::string DownloadItemImpl::GetRemoteAddress() const { |
| 610 return remote_address_; | 614 return remote_address_; |
| 611 } | 615 } |
| 612 | 616 |
| 613 bool DownloadItemImpl::HasUserGesture() const { | 617 bool DownloadItemImpl::HasUserGesture() const { |
| 614 return has_user_gesture_; | 618 return has_user_gesture_; |
| 615 }; | 619 } |
| 616 | 620 |
| 617 ui::PageTransition DownloadItemImpl::GetTransitionType() const { | 621 ui::PageTransition DownloadItemImpl::GetTransitionType() const { |
| 618 return transition_type_; | 622 return transition_type_; |
| 619 }; | 623 } |
| 620 | 624 |
| 621 const std::string& DownloadItemImpl::GetLastModifiedTime() const { | 625 const std::string& DownloadItemImpl::GetLastModifiedTime() const { |
| 622 return last_modified_time_; | 626 return last_modified_time_; |
| 623 } | 627 } |
| 624 | 628 |
| 625 const std::string& DownloadItemImpl::GetETag() const { | 629 const std::string& DownloadItemImpl::GetETag() const { |
| 626 return etag_; | 630 return etag_; |
| 627 } | 631 } |
| 628 | 632 |
| 629 bool DownloadItemImpl::IsSavePackageDownload() const { | 633 bool DownloadItemImpl::IsSavePackageDownload() const { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 // We also can't continue if we don't have some verifier to make sure | 908 // We also can't continue if we don't have some verifier to make sure |
| 905 // we're getting the same file. | 909 // we're getting the same file. |
| 906 bool restart_required = | 910 bool restart_required = |
| 907 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); | 911 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); |
| 908 | 912 |
| 909 // We won't auto-restart if we've used up our attempts or the | 913 // We won't auto-restart if we've used up our attempts or the |
| 910 // download has been paused by user action. | 914 // download has been paused by user action. |
| 911 bool user_action_required = | 915 bool user_action_required = |
| 912 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); | 916 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); |
| 913 | 917 |
| 914 switch(last_reason_) { | 918 switch (last_reason_) { |
| 915 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: | 919 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: |
| 916 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: | 920 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: |
| 917 break; | 921 break; |
| 918 | 922 |
| 919 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: | 923 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: |
| 920 // The server disagreed with the file offset that we sent. | 924 // The server disagreed with the file offset that we sent. |
| 921 | 925 |
| 922 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: | 926 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: |
| 923 // The file on disk was found to not match the expected hash. Discard and | 927 // The file on disk was found to not match the expected hash. Discard and |
| 924 // start from beginning. | 928 // start from beginning. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 case DOWNLOAD_INTERRUPT_REASON_NONE: | 969 case DOWNLOAD_INTERRUPT_REASON_NONE: |
| 966 case DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST: | 970 case DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST: |
| 967 case DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED: | 971 case DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED: |
| 968 case DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT: | 972 case DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT: |
| 969 case DOWNLOAD_INTERRUPT_REASON_USER_CANCELED: | 973 case DOWNLOAD_INTERRUPT_REASON_USER_CANCELED: |
| 970 case DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED: | 974 case DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED: |
| 971 case DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED: | 975 case DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED: |
| 972 case DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED: | 976 case DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED: |
| 973 case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM: | 977 case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM: |
| 974 case DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN: | 978 case DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN: |
| 975 // Unhandled. | |
| 976 return RESUME_MODE_INVALID; | 979 return RESUME_MODE_INVALID; |
| 977 } | 980 } |
| 978 | 981 |
| 979 if (user_action_required && restart_required) | 982 if (user_action_required && restart_required) |
| 980 return RESUME_MODE_USER_RESTART; | 983 return RESUME_MODE_USER_RESTART; |
| 981 | 984 |
| 982 if (restart_required) | 985 if (restart_required) |
| 983 return RESUME_MODE_IMMEDIATE_RESTART; | 986 return RESUME_MODE_IMMEDIATE_RESTART; |
| 984 | 987 |
| 985 if (user_action_required) | 988 if (user_action_required) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 int64_t bytes_per_sec, | 1093 int64_t bytes_per_sec, |
| 1091 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { | 1094 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { |
| 1092 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1095 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1093 // If the download is in any other state we don't expect any | 1096 // If the download is in any other state we don't expect any |
| 1094 // DownloadDestinationObserver callbacks. An interruption or a cancellation | 1097 // DownloadDestinationObserver callbacks. An interruption or a cancellation |
| 1095 // results in a call to ReleaseDownloadFile which invalidates the weak | 1098 // results in a call to ReleaseDownloadFile which invalidates the weak |
| 1096 // reference held by the DownloadFile and hence cuts off any pending | 1099 // reference held by the DownloadFile and hence cuts off any pending |
| 1097 // callbacks. | 1100 // callbacks. |
| 1098 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL); | 1101 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL); |
| 1099 | 1102 |
| 1100 // There must be no pending destination_error_. | 1103 // There must be no pending deferred_interrupt_reason_. |
| 1101 DCHECK_EQ(destination_error_, DOWNLOAD_INTERRUPT_REASON_NONE); | 1104 DCHECK_EQ(deferred_interrupt_reason_, DOWNLOAD_INTERRUPT_REASON_NONE); |
| 1102 | 1105 |
| 1103 DVLOG(20) << __func__ << "() so_far=" << bytes_so_far | 1106 DVLOG(20) << __func__ << "() so_far=" << bytes_so_far |
| 1104 << " per_sec=" << bytes_per_sec | 1107 << " per_sec=" << bytes_per_sec |
| 1105 << " download=" << DebugString(true); | 1108 << " download=" << DebugString(true); |
| 1106 | 1109 |
| 1107 UpdateProgress(bytes_so_far, bytes_per_sec); | 1110 UpdateProgress(bytes_so_far, bytes_per_sec); |
| 1108 received_slices_ = received_slices; | 1111 received_slices_ = received_slices; |
| 1109 if (net_log_.IsCapturing()) { | 1112 if (net_log_.IsCapturing()) { |
| 1110 net_log_.AddEvent( | 1113 net_log_.AddEvent( |
| 1111 net::NetLogEventType::DOWNLOAD_ITEM_UPDATED, | 1114 net::NetLogEventType::DOWNLOAD_ITEM_UPDATED, |
| 1112 net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); | 1115 net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); |
| 1113 } | 1116 } |
| 1114 | 1117 |
| 1115 UpdateObservers(); | 1118 UpdateObservers(); |
| 1116 } | 1119 } |
| 1117 | 1120 |
| 1118 void DownloadItemImpl::DestinationError( | 1121 void DownloadItemImpl::DestinationError( |
| 1119 DownloadInterruptReason reason, | 1122 DownloadInterruptReason reason, |
| 1120 int64_t bytes_so_far, | 1123 int64_t bytes_so_far, |
| 1121 std::unique_ptr<crypto::SecureHash> secure_hash) { | 1124 std::unique_ptr<crypto::SecureHash> secure_hash) { |
| 1122 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1125 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1123 // If the download is in any other state we don't expect any | 1126 // If the download is in any other state we don't expect any |
| 1124 // DownloadDestinationObserver callbacks. An interruption or a cancellation | 1127 // DownloadDestinationObserver callbacks. An interruption or a cancellation |
| 1125 // results in a call to ReleaseDownloadFile which invalidates the weak | 1128 // results in a call to ReleaseDownloadFile which invalidates the weak |
| 1126 // reference held by the DownloadFile and hence cuts off any pending | 1129 // reference held by the DownloadFile and hence cuts off any pending |
| 1127 // callbacks. | 1130 // callbacks. |
| 1128 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL); | 1131 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL); |
| 1129 DVLOG(20) << __func__ | 1132 DVLOG(20) << __func__ |
| 1130 << "() reason:" << DownloadInterruptReasonToString(reason); | 1133 << "() reason:" << DownloadInterruptReasonToString(reason) |
| 1134 << " this:" << DebugString(true); |
| 1131 | 1135 |
| 1132 // Postpone recognition of this error until after file name determination | |
| 1133 // has completed and the intermediate file has been renamed to simplify | |
| 1134 // resumption conditions. | |
| 1135 if (state_ == TARGET_PENDING_INTERNAL) { | |
| 1136 received_bytes_ = bytes_so_far; | |
| 1137 hash_state_ = std::move(secure_hash); | |
| 1138 hash_.clear(); | |
| 1139 destination_error_ = reason; | |
| 1140 return; | |
| 1141 } | |
| 1142 InterruptWithPartialState(bytes_so_far, std::move(secure_hash), reason); | 1136 InterruptWithPartialState(bytes_so_far, std::move(secure_hash), reason); |
| 1143 UpdateObservers(); | 1137 UpdateObservers(); |
| 1144 } | 1138 } |
| 1145 | 1139 |
| 1146 void DownloadItemImpl::DestinationCompleted( | 1140 void DownloadItemImpl::DestinationCompleted( |
| 1147 int64_t total_bytes, | 1141 int64_t total_bytes, |
| 1148 std::unique_ptr<crypto::SecureHash> secure_hash) { | 1142 std::unique_ptr<crypto::SecureHash> secure_hash) { |
| 1149 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1143 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1150 // If the download is in any other state we don't expect any | 1144 // If the download is in any other state we don't expect any |
| 1151 // DownloadDestinationObserver callbacks. An interruption or a cancellation | 1145 // DownloadDestinationObserver callbacks. An interruption or a cancellation |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | 1193 std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
| 1200 const DownloadCreateInfo& new_create_info) { | 1194 const DownloadCreateInfo& new_create_info) { |
| 1201 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1195 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1202 DCHECK(!download_file_.get()); | 1196 DCHECK(!download_file_.get()); |
| 1203 DVLOG(20) << __func__ << "() this=" << DebugString(true); | 1197 DVLOG(20) << __func__ << "() this=" << DebugString(true); |
| 1204 RecordDownloadCount(START_COUNT); | 1198 RecordDownloadCount(START_COUNT); |
| 1205 | 1199 |
| 1206 download_file_ = std::move(file); | 1200 download_file_ = std::move(file); |
| 1207 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle), | 1201 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle), |
| 1208 new_create_info); | 1202 new_create_info); |
| 1209 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; | 1203 deferred_interrupt_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 1210 | 1204 |
| 1211 if (state_ == CANCELLED_INTERNAL) { | 1205 if (state_ == CANCELLED_INTERNAL) { |
| 1212 // The download was in the process of resuming when it was cancelled. Don't | 1206 // The download was in the process of resuming when it was cancelled. Don't |
| 1213 // proceed. | 1207 // proceed. |
| 1214 ReleaseDownloadFile(true); | 1208 ReleaseDownloadFile(true); |
| 1215 job_->Cancel(true); | 1209 job_->Cancel(true); |
| 1216 return; | 1210 return; |
| 1217 } | 1211 } |
| 1218 | 1212 |
| 1219 // The state could be one of the following: | 1213 // The state could be one of the following: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1235 // Download requests that are interrupted by Start() should result in a | 1229 // Download requests that are interrupted by Start() should result in a |
| 1236 // DownloadCreateInfo with an intact DownloadSaveInfo. | 1230 // DownloadCreateInfo with an intact DownloadSaveInfo. |
| 1237 DCHECK(new_create_info.save_info); | 1231 DCHECK(new_create_info.save_info); |
| 1238 | 1232 |
| 1239 int64_t offset = new_create_info.save_info->offset; | 1233 int64_t offset = new_create_info.save_info->offset; |
| 1240 std::unique_ptr<crypto::SecureHash> hash_state = | 1234 std::unique_ptr<crypto::SecureHash> hash_state = |
| 1241 new_create_info.save_info->hash_state | 1235 new_create_info.save_info->hash_state |
| 1242 ? new_create_info.save_info->hash_state->Clone() | 1236 ? new_create_info.save_info->hash_state->Clone() |
| 1243 : nullptr; | 1237 : nullptr; |
| 1244 | 1238 |
| 1245 // Interrupted downloads also need a target path. | 1239 current_path_ = new_create_info.save_info->file_path; |
| 1246 if (target_path_.empty()) { | 1240 received_bytes_ = offset; |
| 1247 received_bytes_ = offset; | 1241 hash_state_ = std::move(hash_state); |
| 1248 hash_state_ = std::move(hash_state); | 1242 hash_.clear(); |
| 1249 hash_.clear(); | 1243 deferred_interrupt_reason_ = new_create_info.result; |
| 1250 destination_error_ = new_create_info.result; | 1244 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); |
| 1251 received_slices_.clear(); | 1245 DetermineDownloadTarget(); |
| 1252 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); | |
| 1253 DetermineDownloadTarget(); | |
| 1254 return; | |
| 1255 } | |
| 1256 | |
| 1257 // Otherwise, this was a resumption attempt which ended with an | |
| 1258 // interruption. Continue with current target path. | |
| 1259 TransitionTo(TARGET_RESOLVED_INTERNAL); | |
| 1260 InterruptWithPartialState( | |
| 1261 offset, std::move(hash_state), new_create_info.result); | |
| 1262 UpdateObservers(); | |
| 1263 return; | 1246 return; |
| 1264 } | 1247 } |
| 1265 | 1248 |
| 1266 if (state_ == INITIAL_INTERNAL) { | 1249 if (state_ == INITIAL_INTERNAL) { |
| 1267 RecordDownloadCount(NEW_DOWNLOAD_COUNT); | 1250 RecordDownloadCount(NEW_DOWNLOAD_COUNT); |
| 1268 RecordDownloadMimeType(mime_type_); | 1251 RecordDownloadMimeType(mime_type_); |
| 1269 if (!GetBrowserContext()->IsOffTheRecord()) { | 1252 if (!GetBrowserContext()->IsOffTheRecord()) { |
| 1270 RecordDownloadCount(NEW_DOWNLOAD_COUNT_NORMAL_PROFILE); | 1253 RecordDownloadCount(NEW_DOWNLOAD_COUNT_NORMAL_PROFILE); |
| 1271 RecordDownloadMimeTypeForNormalProfile(mime_type_); | 1254 RecordDownloadMimeTypeForNormalProfile(mime_type_); |
| 1272 } | 1255 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1293 base::Bind(&DownloadFile::Initialize, | 1276 base::Bind(&DownloadFile::Initialize, |
| 1294 // Safe because we control download file lifetime. | 1277 // Safe because we control download file lifetime. |
| 1295 base::Unretained(download_file_.get()), | 1278 base::Unretained(download_file_.get()), |
| 1296 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, | 1279 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, |
| 1297 weak_ptr_factory_.GetWeakPtr()))); | 1280 weak_ptr_factory_.GetWeakPtr()))); |
| 1298 } | 1281 } |
| 1299 | 1282 |
| 1300 void DownloadItemImpl::OnDownloadFileInitialized( | 1283 void DownloadItemImpl::OnDownloadFileInitialized( |
| 1301 DownloadInterruptReason result) { | 1284 DownloadInterruptReason result) { |
| 1302 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1285 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1303 DCHECK_EQ(state_, TARGET_PENDING_INTERNAL); | 1286 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
| 1287 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) |
| 1288 << "Unexpected state: " << DebugDownloadStateString(state_); |
| 1289 |
| 1304 DVLOG(20) << __func__ | 1290 DVLOG(20) << __func__ |
| 1305 << "() result:" << DownloadInterruptReasonToString(result); | 1291 << "() result:" << DownloadInterruptReasonToString(result); |
| 1306 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { | 1292 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 1307 // Whoops. That didn't work. Proceed as an interrupted download, but reset | 1293 ReleaseDownloadFile(true); |
| 1308 // the partial state. Currently, the partial stub cannot be recovered if the | 1294 InterruptAndDiscardPartialState(result); |
| 1309 // download file initialization fails. | |
| 1310 received_bytes_ = 0; | |
| 1311 hash_state_.reset(); | |
| 1312 hash_.clear(); | |
| 1313 destination_error_ = result; | |
| 1314 received_slices_.clear(); | |
| 1315 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); | |
| 1316 } | 1295 } |
| 1317 | 1296 |
| 1318 DetermineDownloadTarget(); | 1297 DetermineDownloadTarget(); |
| 1319 } | 1298 } |
| 1320 | 1299 |
| 1321 void DownloadItemImpl::DetermineDownloadTarget() { | 1300 void DownloadItemImpl::DetermineDownloadTarget() { |
| 1322 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1301 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1323 DVLOG(20) << __func__ << "() " << DebugString(true); | 1302 DVLOG(20) << __func__ << "() " << DebugString(true); |
| 1324 | 1303 |
| 1325 delegate_->DetermineDownloadTarget( | 1304 delegate_->DetermineDownloadTarget( |
| 1326 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, | 1305 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, |
| 1327 weak_ptr_factory_.GetWeakPtr())); | 1306 weak_ptr_factory_.GetWeakPtr())); |
| 1328 } | 1307 } |
| 1329 | 1308 |
| 1330 // Called by delegate_ when the download target path has been determined. | 1309 // Called by delegate_ when the download target path has been determined. |
| 1331 void DownloadItemImpl::OnDownloadTargetDetermined( | 1310 void DownloadItemImpl::OnDownloadTargetDetermined( |
| 1332 const base::FilePath& target_path, | 1311 const base::FilePath& target_path, |
| 1333 TargetDisposition disposition, | 1312 TargetDisposition disposition, |
| 1334 DownloadDangerType danger_type, | 1313 DownloadDangerType danger_type, |
| 1335 const base::FilePath& intermediate_path) { | 1314 const base::FilePath& intermediate_path, |
| 1315 DownloadInterruptReason interrupt_reason) { |
| 1336 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1316 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1337 DCHECK(state_ == TARGET_PENDING_INTERNAL || | 1317 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
| 1338 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); | 1318 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); |
| 1319 DVLOG(20) << __func__ << "() target_path:" << target_path.value() |
| 1320 << " intermediate_path:" << intermediate_path.value() |
| 1321 << " disposition:" << disposition << " danger_type:" << danger_type |
| 1322 << " interrupt_reason:" |
| 1323 << DownloadInterruptReasonToString(interrupt_reason) |
| 1324 << " this:" << DebugString(true); |
| 1339 | 1325 |
| 1340 // If the |target_path| is empty, then we consider this download to be | 1326 if (IsCancellation(interrupt_reason) || target_path.empty()) { |
| 1341 // canceled. | |
| 1342 if (target_path.empty()) { | |
| 1343 Cancel(true); | 1327 Cancel(true); |
| 1344 return; | 1328 return; |
| 1345 } | 1329 } |
| 1346 | 1330 |
| 1347 DVLOG(20) << __func__ << "() target_path:" << target_path.value() | |
| 1348 << " disposition:" << disposition << " danger_type:" << danger_type | |
| 1349 << " this:" << DebugString(true); | |
| 1350 | |
| 1351 target_path_ = target_path; | 1331 target_path_ = target_path; |
| 1352 target_disposition_ = disposition; | 1332 target_disposition_ = disposition; |
| 1353 SetDangerType(danger_type); | 1333 SetDangerType(danger_type); |
| 1354 | 1334 |
| 1355 // This was an interrupted download that was looking for a filename. Now that | 1335 // There were no other pending errors, and we just failed to determined the |
| 1356 // it has one, transition to interrupted. | 1336 // download target. |
| 1357 if (state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) { | 1337 if (state_ == TARGET_PENDING_INTERNAL && |
| 1358 InterruptWithPartialState( | 1338 interrupt_reason != DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 1359 received_bytes_, std::move(hash_state_), destination_error_); | 1339 deferred_interrupt_reason_ = interrupt_reason; |
| 1360 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; | 1340 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); |
| 1361 UpdateObservers(); | 1341 } |
| 1342 |
| 1343 // This was an interrupted download that was looking for a filename. Resolve |
| 1344 // early without performing the intermediate rename. If there is a |
| 1345 // DownloadFile, then that should be renamed to the intermediate name before |
| 1346 // we can interrupt the download. Otherwise we may lose intermediate state. |
| 1347 if (state_ == INTERRUPTED_TARGET_PENDING_INTERNAL && !download_file_) { |
| 1348 OnTargetResolved(); |
| 1362 return; | 1349 return; |
| 1363 } | 1350 } |
| 1364 | 1351 |
| 1365 // We want the intermediate and target paths to refer to the same directory so | 1352 // We want the intermediate and target paths to refer to the same directory so |
| 1366 // that they are both on the same device and subject to same | 1353 // that they are both on the same device and subject to same |
| 1367 // space/permission/availability constraints. | 1354 // space/permission/availability constraints. |
| 1368 DCHECK(intermediate_path.DirName() == target_path.DirName()); | 1355 DCHECK(intermediate_path.DirName() == target_path.DirName()); |
| 1369 | 1356 |
| 1370 // During resumption, we may choose to proceed with the same intermediate | 1357 // During resumption, we may choose to proceed with the same intermediate |
| 1371 // file. No rename is necessary if our intermediate file already has the | 1358 // file. No rename is necessary if our intermediate file already has the |
| 1372 // correct name. | 1359 // correct name. |
| 1373 // | 1360 // |
| 1374 // The intermediate name may change from its original value during filename | 1361 // The intermediate name may change from its original value during filename |
| 1375 // determination on resumption, for example if the reason for the interruption | 1362 // determination on resumption, for example if the reason for the interruption |
| 1376 // was the download target running out space, resulting in a user prompt. | 1363 // was the download target running out space, resulting in a user prompt. |
| 1377 if (intermediate_path == current_path_) { | 1364 if (intermediate_path == current_path_) { |
| 1378 OnDownloadRenamedToIntermediateName(DOWNLOAD_INTERRUPT_REASON_NONE, | 1365 OnDownloadRenamedToIntermediateName(DOWNLOAD_INTERRUPT_REASON_NONE, |
| 1379 intermediate_path); | 1366 intermediate_path); |
| 1380 return; | 1367 return; |
| 1381 } | 1368 } |
| 1382 | 1369 |
| 1383 // Rename to intermediate name. | 1370 // Rename to intermediate name. |
| 1384 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a | 1371 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a |
| 1385 // spurious rename when we can just rename to the final | 1372 // spurious rename when we can just rename to the final |
| 1386 // filename. Unnecessary renames may cause bugs like | 1373 // filename. Unnecessary renames may cause bugs like |
| 1387 // http://crbug.com/74187. | 1374 // http://crbug.com/74187. |
| 1388 DCHECK(!is_save_package_download_); | 1375 DCHECK(!is_save_package_download_); |
| 1389 DCHECK(download_file_.get()); | |
| 1390 DownloadFile::RenameCompletionCallback callback = | 1376 DownloadFile::RenameCompletionCallback callback = |
| 1391 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, | 1377 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, |
| 1392 weak_ptr_factory_.GetWeakPtr()); | 1378 weak_ptr_factory_.GetWeakPtr()); |
| 1393 BrowserThread::PostTask( | 1379 BrowserThread::PostTask( |
| 1394 BrowserThread::FILE, FROM_HERE, | 1380 BrowserThread::FILE, FROM_HERE, |
| 1395 base::Bind(&DownloadFile::RenameAndUniquify, | 1381 base::Bind(&DownloadFile::RenameAndUniquify, |
| 1396 // Safe because we control download file lifetime. | 1382 // Safe because we control download file lifetime. |
| 1397 base::Unretained(download_file_.get()), | 1383 base::Unretained(download_file_.get()), |
| 1398 intermediate_path, callback)); | 1384 intermediate_path, callback)); |
| 1399 } | 1385 } |
| 1400 | 1386 |
| 1401 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( | 1387 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( |
| 1402 DownloadInterruptReason reason, | 1388 DownloadInterruptReason reason, |
| 1403 const base::FilePath& full_path) { | 1389 const base::FilePath& full_path) { |
| 1404 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1390 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1405 DCHECK_EQ(state_, TARGET_PENDING_INTERNAL); | 1391 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
| 1392 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); |
| 1393 DCHECK(download_file_); |
| 1406 DVLOG(20) << __func__ << "() download=" << DebugString(true); | 1394 DVLOG(20) << __func__ << "() download=" << DebugString(true); |
| 1407 | 1395 |
| 1396 if (DOWNLOAD_INTERRUPT_REASON_NONE == reason) { |
| 1397 SetFullPath(full_path); |
| 1398 } else { |
| 1399 // TODO(asanka): Even though the rename failed, it may still be possible to |
| 1400 // recover the partial state from the 'before' name. |
| 1401 deferred_interrupt_reason_ = reason; |
| 1402 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); |
| 1403 } |
| 1404 OnTargetResolved(); |
| 1405 } |
| 1406 |
| 1407 void DownloadItemImpl::OnTargetResolved() { |
| 1408 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1409 DVLOG(20) << __func__ << "() download=" << DebugString(true); |
| 1410 DCHECK((state_ == TARGET_PENDING_INTERNAL && |
| 1411 deferred_interrupt_reason_ == DOWNLOAD_INTERRUPT_REASON_NONE) || |
| 1412 (state_ == INTERRUPTED_TARGET_PENDING_INTERNAL && |
| 1413 deferred_interrupt_reason_ != DOWNLOAD_INTERRUPT_REASON_NONE)) |
| 1414 << " deferred_interrupt_reason_:" |
| 1415 << DownloadInterruptReasonToString(deferred_interrupt_reason_) |
| 1416 << " this:" << DebugString(true); |
| 1417 |
| 1418 // This transition is here to ensure that the DownloadItemImpl state machines |
| 1419 // doesn't transition to INTERRUPTED or IN_PROGRESS from |
| 1420 // TARGET_PENDING_INTERNAL directly. Doing so without passing through |
| 1421 // OnTargetResolved() can result in an externally visible state where the |
| 1422 // download is interrupted but doesn't have a target path associated with it. |
| 1423 // |
| 1424 // While not terrible, this complicates the DownloadItem<->Observer |
| 1425 // relationship since an observer that needs a target path in order to respond |
| 1426 // properly to an interruption will need to wait for another OnDownloadUpdated |
| 1427 // notification. This requirement currently affects all of our UIs. |
| 1408 TransitionTo(TARGET_RESOLVED_INTERNAL); | 1428 TransitionTo(TARGET_RESOLVED_INTERNAL); |
| 1409 | 1429 |
| 1410 // If the intermediate rename fails while there's also a destination_error_, | 1430 if (DOWNLOAD_INTERRUPT_REASON_NONE != deferred_interrupt_reason_) { |
| 1411 // then the former is considered the critical error since it requires | 1431 InterruptWithPartialState(received_bytes_, std::move(hash_state_), |
| 1412 // discarding the partial state. | 1432 deferred_interrupt_reason_); |
| 1413 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { | 1433 deferred_interrupt_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 1414 // TODO(asanka): Even though the rename failed, it may still be possible to | |
| 1415 // recover the partial state from the 'before' name. | |
| 1416 InterruptAndDiscardPartialState(reason); | |
| 1417 UpdateObservers(); | 1434 UpdateObservers(); |
| 1418 return; | 1435 return; |
| 1419 } | 1436 } |
| 1420 | 1437 |
| 1421 if (DOWNLOAD_INTERRUPT_REASON_NONE != destination_error_) { | |
| 1422 SetFullPath(full_path); | |
| 1423 InterruptWithPartialState( | |
| 1424 received_bytes_, std::move(hash_state_), destination_error_); | |
| 1425 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; | |
| 1426 UpdateObservers(); | |
| 1427 return; | |
| 1428 } | |
| 1429 | |
| 1430 SetFullPath(full_path); | |
| 1431 TransitionTo(IN_PROGRESS_INTERNAL); | 1438 TransitionTo(IN_PROGRESS_INTERNAL); |
| 1432 // TODO(asanka): Calling UpdateObservers() prior to MaybeCompleteDownload() is | 1439 // TODO(asanka): Calling UpdateObservers() prior to MaybeCompleteDownload() is |
| 1433 // not safe. The download could be in an underminate state after invoking | 1440 // not safe. The download could be in an underminate state after invoking |
| 1434 // observers. http://crbug.com/586610 | 1441 // observers. http://crbug.com/586610 |
| 1435 UpdateObservers(); | 1442 UpdateObservers(); |
| 1436 MaybeCompleteDownload(); | 1443 MaybeCompleteDownload(); |
| 1437 } | 1444 } |
| 1438 | 1445 |
| 1439 // When SavePackage downloads MHTML to GData (see | 1446 // When SavePackage downloads MHTML to GData (see |
| 1440 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it | 1447 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 case COMPLETING_INTERNAL: | 1631 case COMPLETING_INTERNAL: |
| 1625 case COMPLETE_INTERNAL: | 1632 case COMPLETE_INTERNAL: |
| 1626 // Already complete. | 1633 // Already complete. |
| 1627 return; | 1634 return; |
| 1628 | 1635 |
| 1629 case INITIAL_INTERNAL: | 1636 case INITIAL_INTERNAL: |
| 1630 case MAX_DOWNLOAD_INTERNAL_STATE: | 1637 case MAX_DOWNLOAD_INTERNAL_STATE: |
| 1631 NOTREACHED(); | 1638 NOTREACHED(); |
| 1632 return; | 1639 return; |
| 1633 | 1640 |
| 1641 case TARGET_PENDING_INTERNAL: |
| 1634 case INTERRUPTED_TARGET_PENDING_INTERNAL: | 1642 case INTERRUPTED_TARGET_PENDING_INTERNAL: |
| 1643 // Postpone recognition of this error until after file name determination |
| 1644 // has completed and the intermediate file has been renamed to simplify |
| 1645 // resumption conditions. The target determination logic is much simpler |
| 1646 // if the state of the download remains constant until that stage |
| 1647 // completes. |
| 1648 // |
| 1649 // current_path_ may be empty because it is possible for DownloadItem to |
| 1650 // receive a DestinationError prior to the download file initialization |
| 1651 // complete callback. |
| 1652 if (!IsCancellation(reason)) { |
| 1653 UpdateProgress(bytes_so_far, 0); |
| 1654 SetHashState(std::move(hash_state)); |
| 1655 deferred_interrupt_reason_ = reason; |
| 1656 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); |
| 1657 return; |
| 1658 } |
| 1659 // else - Fallthrough for cancellation handling which is equivalent to the |
| 1660 // IN_PROGRESS state. |
| 1661 |
| 1635 case IN_PROGRESS_INTERNAL: | 1662 case IN_PROGRESS_INTERNAL: |
| 1636 case TARGET_PENDING_INTERNAL: | |
| 1637 case TARGET_RESOLVED_INTERNAL: | 1663 case TARGET_RESOLVED_INTERNAL: |
| 1638 // last_reason_ needs to be set for GetResumeMode() to work. | 1664 // last_reason_ needs to be set for GetResumeMode() to work. |
| 1639 last_reason_ = reason; | 1665 last_reason_ = reason; |
| 1640 | 1666 |
| 1641 if (download_file_) { | 1667 if (download_file_) { |
| 1642 ResumeMode resume_mode = GetResumeMode(); | 1668 ResumeMode resume_mode = GetResumeMode(); |
| 1643 ReleaseDownloadFile(resume_mode != RESUME_MODE_IMMEDIATE_CONTINUE && | 1669 ReleaseDownloadFile(resume_mode != RESUME_MODE_IMMEDIATE_CONTINUE && |
| 1644 resume_mode != RESUME_MODE_USER_CONTINUE); | 1670 resume_mode != RESUME_MODE_USER_CONTINUE); |
| 1645 } | 1671 } |
| 1646 break; | 1672 break; |
| 1647 | 1673 |
| 1648 case RESUMING_INTERNAL: | 1674 case RESUMING_INTERNAL: |
| 1649 case INTERRUPTED_INTERNAL: | 1675 case INTERRUPTED_INTERNAL: |
| 1650 DCHECK(!download_file_); | 1676 DCHECK(!download_file_); |
| 1651 // The first non-cancel interrupt reason wins in cases where multiple | 1677 // The first non-cancel interrupt reason wins in cases where multiple |
| 1652 // things go wrong. | 1678 // things go wrong. |
| 1653 if (reason != DOWNLOAD_INTERRUPT_REASON_USER_CANCELED && | 1679 if (!IsCancellation(reason)) |
| 1654 reason != DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) | |
| 1655 return; | 1680 return; |
| 1656 | 1681 |
| 1657 last_reason_ = reason; | 1682 last_reason_ = reason; |
| 1658 if (!current_path_.empty()) { | 1683 if (!current_path_.empty()) { |
| 1659 // There is no download file and this is transitioning from INTERRUPTED | 1684 // There is no download file and this is transitioning from INTERRUPTED |
| 1660 // to CANCELLED. The intermediate file is no longer usable, and should | 1685 // to CANCELLED. The intermediate file is no longer usable, and should |
| 1661 // be deleted. | 1686 // be deleted. |
| 1662 BrowserThread::PostTask( | 1687 BrowserThread::PostTask( |
| 1663 BrowserThread::FILE, FROM_HERE, | 1688 BrowserThread::FILE, FROM_HERE, |
| 1664 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), | 1689 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1685 received_bytes_ = 0; | 1710 received_bytes_ = 0; |
| 1686 received_slices_.clear(); | 1711 received_slices_.clear(); |
| 1687 } else { | 1712 } else { |
| 1688 UpdateProgress(bytes_so_far, 0); | 1713 UpdateProgress(bytes_so_far, 0); |
| 1689 SetHashState(std::move(hash_state)); | 1714 SetHashState(std::move(hash_state)); |
| 1690 } | 1715 } |
| 1691 | 1716 |
| 1692 if (job_) | 1717 if (job_) |
| 1693 job_->Cancel(false); | 1718 job_->Cancel(false); |
| 1694 | 1719 |
| 1695 if (reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED || | 1720 if (IsCancellation(reason)) { |
| 1696 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) { | |
| 1697 if (IsDangerous()) { | 1721 if (IsDangerous()) { |
| 1698 RecordDangerousDownloadDiscard( | 1722 RecordDangerousDownloadDiscard( |
| 1699 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED | 1723 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED |
| 1700 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION | 1724 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION |
| 1701 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, | 1725 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, |
| 1702 GetDangerType(), GetTargetFilePath()); | 1726 GetDangerType(), GetTargetFilePath()); |
| 1703 } | 1727 } |
| 1704 | 1728 |
| 1705 RecordDownloadCount(CANCELLED_COUNT); | 1729 RecordDownloadCount(CANCELLED_COUNT); |
| 1730 DCHECK_EQ(last_reason_, reason); |
| 1706 TransitionTo(CANCELLED_INTERNAL); | 1731 TransitionTo(CANCELLED_INTERNAL); |
| 1707 return; | 1732 return; |
| 1708 } | 1733 } |
| 1709 | 1734 |
| 1710 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); | 1735 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); |
| 1711 if (!GetWebContents()) | 1736 if (!GetWebContents()) |
| 1712 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); | 1737 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); |
| 1713 | 1738 |
| 1739 // TODO(asanka): This is not good. We can transition to interrupted from |
| 1740 // target-pending, which is something we don't want to do. Perhaps we should |
| 1741 // explicitly transition to target-resolved prior to switching to interrupted. |
| 1742 DCHECK_EQ(last_reason_, reason); |
| 1714 TransitionTo(INTERRUPTED_INTERNAL); | 1743 TransitionTo(INTERRUPTED_INTERNAL); |
| 1715 AutoResumeIfValid(); | 1744 AutoResumeIfValid(); |
| 1716 } | 1745 } |
| 1717 | 1746 |
| 1718 void DownloadItemImpl::UpdateProgress( | 1747 void DownloadItemImpl::UpdateProgress( |
| 1719 int64_t bytes_so_far, | 1748 int64_t bytes_so_far, |
| 1720 int64_t bytes_per_sec) { | 1749 int64_t bytes_per_sec) { |
| 1721 received_bytes_ = bytes_so_far; | 1750 received_bytes_ = bytes_so_far; |
| 1722 bytes_per_sec_ = bytes_per_sec; | 1751 bytes_per_sec_ = bytes_per_sec; |
| 1723 | 1752 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 base::Bind(&ItemCompletingNetLogCallback, received_bytes_, &hash_)); | 1879 base::Bind(&ItemCompletingNetLogCallback, received_bytes_, &hash_)); |
| 1851 break; | 1880 break; |
| 1852 | 1881 |
| 1853 case COMPLETE_INTERNAL: | 1882 case COMPLETE_INTERNAL: |
| 1854 net_log_.AddEvent( | 1883 net_log_.AddEvent( |
| 1855 net::NetLogEventType::DOWNLOAD_ITEM_FINISHED, | 1884 net::NetLogEventType::DOWNLOAD_ITEM_FINISHED, |
| 1856 base::Bind(&ItemFinishedNetLogCallback, auto_opened_)); | 1885 base::Bind(&ItemFinishedNetLogCallback, auto_opened_)); |
| 1857 break; | 1886 break; |
| 1858 | 1887 |
| 1859 case INTERRUPTED_INTERNAL: | 1888 case INTERRUPTED_INTERNAL: |
| 1889 DCHECK(!download_file_) |
| 1890 << "Download file must be released prior to interruption."; |
| 1891 DCHECK_NE(last_reason_, DOWNLOAD_INTERRUPT_REASON_NONE); |
| 1860 net_log_.AddEvent(net::NetLogEventType::DOWNLOAD_ITEM_INTERRUPTED, | 1892 net_log_.AddEvent(net::NetLogEventType::DOWNLOAD_ITEM_INTERRUPTED, |
| 1861 base::Bind(&ItemInterruptedNetLogCallback, | 1893 base::Bind(&ItemInterruptedNetLogCallback, |
| 1862 last_reason_, received_bytes_)); | 1894 last_reason_, received_bytes_)); |
| 1863 break; | 1895 break; |
| 1864 | 1896 |
| 1865 case RESUMING_INTERNAL: | 1897 case RESUMING_INTERNAL: |
| 1866 net_log_.AddEvent(net::NetLogEventType::DOWNLOAD_ITEM_RESUMED, | 1898 net_log_.AddEvent(net::NetLogEventType::DOWNLOAD_ITEM_RESUMED, |
| 1867 base::Bind(&ItemResumingNetLogCallback, false, | 1899 base::Bind(&ItemResumingNetLogCallback, false, |
| 1868 last_reason_, received_bytes_)); | 1900 last_reason_, received_bytes_)); |
| 1869 break; | 1901 break; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 return; | 1991 return; |
| 1960 | 1992 |
| 1961 // We are starting a new request. Shake off all pending operations. | 1993 // We are starting a new request. Shake off all pending operations. |
| 1962 DCHECK(!download_file_); | 1994 DCHECK(!download_file_); |
| 1963 weak_ptr_factory_.InvalidateWeakPtrs(); | 1995 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 1964 | 1996 |
| 1965 // Reset the appropriate state if restarting. | 1997 // Reset the appropriate state if restarting. |
| 1966 ResumeMode mode = GetResumeMode(); | 1998 ResumeMode mode = GetResumeMode(); |
| 1967 if (mode == RESUME_MODE_IMMEDIATE_RESTART || | 1999 if (mode == RESUME_MODE_IMMEDIATE_RESTART || |
| 1968 mode == RESUME_MODE_USER_RESTART) { | 2000 mode == RESUME_MODE_USER_RESTART) { |
| 2001 DCHECK(current_path_.empty()); |
| 1969 received_bytes_ = 0; | 2002 received_bytes_ = 0; |
| 1970 last_modified_time_.clear(); | 2003 last_modified_time_.clear(); |
| 1971 etag_.clear(); | 2004 etag_.clear(); |
| 1972 hash_.clear(); | 2005 hash_.clear(); |
| 1973 hash_state_.reset(); | 2006 hash_state_.reset(); |
| 1974 received_slices_.clear(); | 2007 received_slices_.clear(); |
| 1975 } | 2008 } |
| 1976 | 2009 |
| 1977 StoragePartition* storage_partition = | 2010 StoragePartition* storage_partition = |
| 1978 BrowserContext::GetStoragePartitionForSite(GetBrowserContext(), | 2011 BrowserContext::GetStoragePartitionForSite(GetBrowserContext(), |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2100 switch (from) { | 2133 switch (from) { |
| 2101 case INITIAL_INTERNAL: | 2134 case INITIAL_INTERNAL: |
| 2102 return to == TARGET_PENDING_INTERNAL || | 2135 return to == TARGET_PENDING_INTERNAL || |
| 2103 to == INTERRUPTED_TARGET_PENDING_INTERNAL; | 2136 to == INTERRUPTED_TARGET_PENDING_INTERNAL; |
| 2104 | 2137 |
| 2105 case TARGET_PENDING_INTERNAL: | 2138 case TARGET_PENDING_INTERNAL: |
| 2106 return to == INTERRUPTED_TARGET_PENDING_INTERNAL || | 2139 return to == INTERRUPTED_TARGET_PENDING_INTERNAL || |
| 2107 to == TARGET_RESOLVED_INTERNAL || to == CANCELLED_INTERNAL; | 2140 to == TARGET_RESOLVED_INTERNAL || to == CANCELLED_INTERNAL; |
| 2108 | 2141 |
| 2109 case INTERRUPTED_TARGET_PENDING_INTERNAL: | 2142 case INTERRUPTED_TARGET_PENDING_INTERNAL: |
| 2110 return to == INTERRUPTED_INTERNAL || to == CANCELLED_INTERNAL; | 2143 return to == TARGET_RESOLVED_INTERNAL || to == CANCELLED_INTERNAL; |
| 2111 | 2144 |
| 2112 case TARGET_RESOLVED_INTERNAL: | 2145 case TARGET_RESOLVED_INTERNAL: |
| 2113 return to == IN_PROGRESS_INTERNAL || to == INTERRUPTED_INTERNAL || | 2146 return to == IN_PROGRESS_INTERNAL || to == INTERRUPTED_INTERNAL || |
| 2114 to == CANCELLED_INTERNAL; | 2147 to == CANCELLED_INTERNAL; |
| 2115 | 2148 |
| 2116 case IN_PROGRESS_INTERNAL: | 2149 case IN_PROGRESS_INTERNAL: |
| 2117 return to == COMPLETING_INTERNAL || to == CANCELLED_INTERNAL || | 2150 return to == COMPLETING_INTERNAL || to == CANCELLED_INTERNAL || |
| 2118 to == INTERRUPTED_INTERNAL; | 2151 to == INTERRUPTED_INTERNAL; |
| 2119 | 2152 |
| 2120 case COMPLETING_INTERNAL: | 2153 case COMPLETING_INTERNAL: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 case COMPLETE_INTERNAL: | 2194 case COMPLETE_INTERNAL: |
| 2162 return "COMPLETE"; | 2195 return "COMPLETE"; |
| 2163 case CANCELLED_INTERNAL: | 2196 case CANCELLED_INTERNAL: |
| 2164 return "CANCELLED"; | 2197 return "CANCELLED"; |
| 2165 case INTERRUPTED_INTERNAL: | 2198 case INTERRUPTED_INTERNAL: |
| 2166 return "INTERRUPTED"; | 2199 return "INTERRUPTED"; |
| 2167 case RESUMING_INTERNAL: | 2200 case RESUMING_INTERNAL: |
| 2168 return "RESUMING"; | 2201 return "RESUMING"; |
| 2169 case MAX_DOWNLOAD_INTERNAL_STATE: | 2202 case MAX_DOWNLOAD_INTERNAL_STATE: |
| 2170 break; | 2203 break; |
| 2171 }; | 2204 } |
| 2172 NOTREACHED() << "Unknown download state " << state; | 2205 NOTREACHED() << "Unknown download state " << state; |
| 2173 return "unknown"; | 2206 return "unknown"; |
| 2174 } | 2207 } |
| 2175 | 2208 |
| 2176 const char* DownloadItemImpl::DebugResumeModeString(ResumeMode mode) { | 2209 const char* DownloadItemImpl::DebugResumeModeString(ResumeMode mode) { |
| 2177 switch (mode) { | 2210 switch (mode) { |
| 2178 case RESUME_MODE_INVALID: | 2211 case RESUME_MODE_INVALID: |
| 2179 return "INVALID"; | 2212 return "INVALID"; |
| 2180 case RESUME_MODE_IMMEDIATE_CONTINUE: | 2213 case RESUME_MODE_IMMEDIATE_CONTINUE: |
| 2181 return "IMMEDIATE_CONTINUE"; | 2214 return "IMMEDIATE_CONTINUE"; |
| 2182 case RESUME_MODE_IMMEDIATE_RESTART: | 2215 case RESUME_MODE_IMMEDIATE_RESTART: |
| 2183 return "IMMEDIATE_RESTART"; | 2216 return "IMMEDIATE_RESTART"; |
| 2184 case RESUME_MODE_USER_CONTINUE: | 2217 case RESUME_MODE_USER_CONTINUE: |
| 2185 return "USER_CONTINUE"; | 2218 return "USER_CONTINUE"; |
| 2186 case RESUME_MODE_USER_RESTART: | 2219 case RESUME_MODE_USER_RESTART: |
| 2187 return "USER_RESTART"; | 2220 return "USER_RESTART"; |
| 2188 } | 2221 } |
| 2189 NOTREACHED() << "Unknown resume mode " << mode; | 2222 NOTREACHED() << "Unknown resume mode " << mode; |
| 2190 return "unknown"; | 2223 return "unknown"; |
| 2191 } | 2224 } |
| 2192 | 2225 |
| 2193 } // namespace content | 2226 } // namespace content |
| OLD | NEW |