| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 300 | 300 |
| 301 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); | 301 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void DownloadItemImpl::ValidateDangerousDownload() { | 304 void DownloadItemImpl::ValidateDangerousDownload() { |
| 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 306 DCHECK(!IsDone()); | 306 DCHECK(!IsDone()); |
| 307 DCHECK(IsDangerous()); | 307 DCHECK(IsDangerous()); |
| 308 | 308 |
| 309 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 309 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
| 310 | 310 |
| 311 if (IsDone() || !IsDangerous()) | 311 if (IsDone() || !IsDangerous()) |
| 312 return; | 312 return; |
| 313 | 313 |
| 314 RecordDangerousDownloadAccept(GetDangerType(), | 314 RecordDangerousDownloadAccept(GetDangerType(), |
| 315 GetTargetFilePath()); | 315 GetTargetFilePath()); |
| 316 | 316 |
| 317 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED; | 317 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED; |
| 318 | 318 |
| 319 bound_net_log_.AddEvent( | 319 bound_net_log_.AddEvent( |
| 320 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, | 320 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
| 321 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); | 321 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); |
| 322 | 322 |
| 323 UpdateObservers(); | 323 UpdateObservers(); |
| 324 | 324 |
| 325 MaybeCompleteDownload(); | 325 MaybeCompleteDownload(); |
| 326 } | 326 } |
| 327 | 327 |
| 328 void DownloadItemImpl::StealDangerousDownload( | 328 void DownloadItemImpl::StealDangerousDownload( |
| 329 const AcquireFileCallback& callback) { | 329 const AcquireFileCallback& callback) { |
| 330 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 330 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
| 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 332 DCHECK(IsDangerous()); | 332 DCHECK(IsDangerous()); |
| 333 if (download_file_) { | 333 if (download_file_) { |
| 334 BrowserThread::PostTaskAndReplyWithResult( | 334 BrowserThread::PostTaskAndReplyWithResult( |
| 335 BrowserThread::FILE, | 335 BrowserThread::FILE, |
| 336 FROM_HERE, | 336 FROM_HERE, |
| 337 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), | 337 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), |
| 338 callback); | 338 callback); |
| 339 } else { | 339 } else { |
| 340 callback.Run(current_path_); | 340 callback.Run(current_path_); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 return; | 379 return; |
| 380 | 380 |
| 381 case MAX_DOWNLOAD_INTERNAL_STATE: | 381 case MAX_DOWNLOAD_INTERNAL_STATE: |
| 382 NOTREACHED(); | 382 NOTREACHED(); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 void DownloadItemImpl::Cancel(bool user_cancel) { | 386 void DownloadItemImpl::Cancel(bool user_cancel) { |
| 387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 388 | 388 |
| 389 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 389 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
| 390 if (state_ != IN_PROGRESS_INTERNAL && | 390 if (state_ != IN_PROGRESS_INTERNAL && |
| 391 state_ != INTERRUPTED_INTERNAL && | 391 state_ != INTERRUPTED_INTERNAL && |
| 392 state_ != RESUMING_INTERNAL) { | 392 state_ != RESUMING_INTERNAL) { |
| 393 // Small downloads might be complete before this method has a chance to run. | 393 // Small downloads might be complete before this method has a chance to run. |
| 394 return; | 394 return; |
| 395 } | 395 } |
| 396 | 396 |
| 397 if (IsDangerous()) { | 397 if (IsDangerous()) { |
| 398 RecordDangerousDownloadDiscard( | 398 RecordDangerousDownloadDiscard( |
| 399 user_cancel ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION | 399 user_cancel ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION |
| (...skipping 27 matching lines...) Expand all Loading... |
| 427 BrowserThread::PostTask( | 427 BrowserThread::PostTask( |
| 428 BrowserThread::FILE, FROM_HERE, | 428 BrowserThread::FILE, FROM_HERE, |
| 429 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), current_path_)); | 429 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), current_path_)); |
| 430 current_path_.clear(); | 430 current_path_.clear(); |
| 431 } | 431 } |
| 432 | 432 |
| 433 TransitionTo(CANCELLED_INTERNAL, UPDATE_OBSERVERS); | 433 TransitionTo(CANCELLED_INTERNAL, UPDATE_OBSERVERS); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void DownloadItemImpl::Remove() { | 436 void DownloadItemImpl::Remove() { |
| 437 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 437 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
| 438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 439 | 439 |
| 440 delegate_->AssertStateConsistent(this); | 440 delegate_->AssertStateConsistent(this); |
| 441 Cancel(true); | 441 Cancel(true); |
| 442 delegate_->AssertStateConsistent(this); | 442 delegate_->AssertStateConsistent(this); |
| 443 | 443 |
| 444 NotifyRemoved(); | 444 NotifyRemoved(); |
| 445 delegate_->DownloadRemoved(this); | 445 delegate_->DownloadRemoved(this); |
| 446 // We have now been deleted. | 446 // We have now been deleted. |
| 447 } | 447 } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 // Currently such items have null request_handle_s, where other items | 774 // Currently such items have null request_handle_s, where other items |
| 775 // (regular and SavePackage downloads) have actual objects off the pointer. | 775 // (regular and SavePackage downloads) have actual objects off the pointer. |
| 776 if (request_handle_) | 776 if (request_handle_) |
| 777 return request_handle_->GetWebContents(); | 777 return request_handle_->GetWebContents(); |
| 778 return NULL; | 778 return NULL; |
| 779 } | 779 } |
| 780 | 780 |
| 781 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { | 781 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { |
| 782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 783 DCHECK(AllDataSaved()); | 783 DCHECK(AllDataSaved()); |
| 784 VLOG(20) << __FUNCTION__ << " danger_type=" << danger_type | 784 DVLOG(20) << __FUNCTION__ << " danger_type=" << danger_type |
| 785 << " download=" << DebugString(true); | 785 << " download=" << DebugString(true); |
| 786 SetDangerType(danger_type); | 786 SetDangerType(danger_type); |
| 787 UpdateObservers(); | 787 UpdateObservers(); |
| 788 } | 788 } |
| 789 | 789 |
| 790 void DownloadItemImpl::SetOpenWhenComplete(bool open) { | 790 void DownloadItemImpl::SetOpenWhenComplete(bool open) { |
| 791 open_when_complete_ = open; | 791 open_when_complete_ = open; |
| 792 } | 792 } |
| 793 | 793 |
| 794 void DownloadItemImpl::SetIsTemporary(bool temporary) { | 794 void DownloadItemImpl::SetIsTemporary(bool temporary) { |
| 795 is_temporary_ = temporary; | 795 is_temporary_ = temporary; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 // DownloadFile is created and Start() is called. The observers will be | 979 // DownloadFile is created and Start() is called. The observers will be |
| 980 // notified when the download transitions to the IN_PROGRESS state. | 980 // notified when the download transitions to the IN_PROGRESS state. |
| 981 } | 981 } |
| 982 | 982 |
| 983 void DownloadItemImpl::NotifyRemoved() { | 983 void DownloadItemImpl::NotifyRemoved() { |
| 984 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); | 984 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); |
| 985 } | 985 } |
| 986 | 986 |
| 987 void DownloadItemImpl::OnDownloadedFileRemoved() { | 987 void DownloadItemImpl::OnDownloadedFileRemoved() { |
| 988 file_externally_removed_ = true; | 988 file_externally_removed_ = true; |
| 989 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 989 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
| 990 UpdateObservers(); | 990 UpdateObservers(); |
| 991 } | 991 } |
| 992 | 992 |
| 993 base::WeakPtr<DownloadDestinationObserver> | 993 base::WeakPtr<DownloadDestinationObserver> |
| 994 DownloadItemImpl::DestinationObserverAsWeakPtr() { | 994 DownloadItemImpl::DestinationObserverAsWeakPtr() { |
| 995 return weak_ptr_factory_.GetWeakPtr(); | 995 return weak_ptr_factory_.GetWeakPtr(); |
| 996 } | 996 } |
| 997 | 997 |
| 998 const net::BoundNetLog& DownloadItemImpl::GetBoundNetLog() const { | 998 const net::BoundNetLog& DownloadItemImpl::GetBoundNetLog() const { |
| 999 return bound_net_log_; | 999 return bound_net_log_; |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { | 1002 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { |
| 1003 total_bytes_ = total_bytes; | 1003 total_bytes_ = total_bytes; |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) { | 1006 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) { |
| 1007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1008 | 1008 |
| 1009 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); | 1009 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); |
| 1010 DCHECK(!all_data_saved_); | 1010 DCHECK(!all_data_saved_); |
| 1011 all_data_saved_ = true; | 1011 all_data_saved_ = true; |
| 1012 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 1012 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
| 1013 | 1013 |
| 1014 // Store final hash and null out intermediate serialized hash state. | 1014 // Store final hash and null out intermediate serialized hash state. |
| 1015 hash_ = final_hash; | 1015 hash_ = final_hash; |
| 1016 hash_state_ = ""; | 1016 hash_state_ = ""; |
| 1017 | 1017 |
| 1018 UpdateObservers(); | 1018 UpdateObservers(); |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 void DownloadItemImpl::MarkAsComplete() { | 1021 void DownloadItemImpl::MarkAsComplete() { |
| 1022 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1022 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1023 | 1023 |
| 1024 DCHECK(all_data_saved_); | 1024 DCHECK(all_data_saved_); |
| 1025 end_time_ = base::Time::Now(); | 1025 end_time_ = base::Time::Now(); |
| 1026 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); | 1026 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, | 1029 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, |
| 1030 int64 bytes_per_sec, | 1030 int64 bytes_per_sec, |
| 1031 const std::string& hash_state) { | 1031 const std::string& hash_state) { |
| 1032 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1032 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1033 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far | 1033 DVLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far |
| 1034 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true); | 1034 << " per_sec=" << bytes_per_sec << " download=" |
| 1035 << DebugString(true); |
| 1035 | 1036 |
| 1036 if (GetState() != IN_PROGRESS) { | 1037 if (GetState() != IN_PROGRESS) { |
| 1037 // Ignore if we're no longer in-progress. This can happen if we race a | 1038 // Ignore if we're no longer in-progress. This can happen if we race a |
| 1038 // Cancel on the UI thread with an update on the FILE thread. | 1039 // Cancel on the UI thread with an update on the FILE thread. |
| 1039 // | 1040 // |
| 1040 // TODO(rdsmith): Arguably we should let this go through, as this means | 1041 // TODO(rdsmith): Arguably we should let this go through, as this means |
| 1041 // the download really did get further than we know before it was | 1042 // the download really did get further than we know before it was |
| 1042 // cancelled. But the gain isn't very large, and the code is more | 1043 // cancelled. But the gain isn't very large, and the code is more |
| 1043 // fragile if it has to support in progress updates in a non-in-progress | 1044 // fragile if it has to support in progress updates in a non-in-progress |
| 1044 // state. This issue should be readdressed when we revamp performance | 1045 // state. This issue should be readdressed when we revamp performance |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1067 // Postpone recognition of this error until after file name determination | 1068 // Postpone recognition of this error until after file name determination |
| 1068 // has completed and the intermediate file has been renamed to simplify | 1069 // has completed and the intermediate file has been renamed to simplify |
| 1069 // resumption conditions. | 1070 // resumption conditions. |
| 1070 if (current_path_.empty() || target_path_.empty()) | 1071 if (current_path_.empty() || target_path_.empty()) |
| 1071 destination_error_ = reason; | 1072 destination_error_ = reason; |
| 1072 else | 1073 else |
| 1073 Interrupt(reason); | 1074 Interrupt(reason); |
| 1074 } | 1075 } |
| 1075 | 1076 |
| 1076 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) { | 1077 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) { |
| 1077 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 1078 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
| 1078 if (GetState() != IN_PROGRESS) | 1079 if (GetState() != IN_PROGRESS) |
| 1079 return; | 1080 return; |
| 1080 OnAllDataSaved(final_hash); | 1081 OnAllDataSaved(final_hash); |
| 1081 MaybeCompleteDownload(); | 1082 MaybeCompleteDownload(); |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 // **** Download progression cascade | 1085 // **** Download progression cascade |
| 1085 | 1086 |
| 1086 void DownloadItemImpl::Init(bool active, | 1087 void DownloadItemImpl::Init(bool active, |
| 1087 DownloadType download_type) { | 1088 DownloadType download_type) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1108 base::Callback<base::Value*(net::NetLog::LogLevel)> active_data = base::Bind( | 1109 base::Callback<base::Value*(net::NetLog::LogLevel)> active_data = base::Bind( |
| 1109 &ItemActivatedNetLogCallback, this, download_type, &file_name); | 1110 &ItemActivatedNetLogCallback, this, download_type, &file_name); |
| 1110 if (active) { | 1111 if (active) { |
| 1111 bound_net_log_.BeginEvent( | 1112 bound_net_log_.BeginEvent( |
| 1112 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); | 1113 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); |
| 1113 } else { | 1114 } else { |
| 1114 bound_net_log_.AddEvent( | 1115 bound_net_log_.AddEvent( |
| 1115 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); | 1116 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); |
| 1116 } | 1117 } |
| 1117 | 1118 |
| 1118 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); | 1119 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true); |
| 1119 } | 1120 } |
| 1120 | 1121 |
| 1121 // We're starting the download. | 1122 // We're starting the download. |
| 1122 void DownloadItemImpl::Start( | 1123 void DownloadItemImpl::Start( |
| 1123 scoped_ptr<DownloadFile> file, | 1124 scoped_ptr<DownloadFile> file, |
| 1124 scoped_ptr<DownloadRequestHandleInterface> req_handle) { | 1125 scoped_ptr<DownloadRequestHandleInterface> req_handle) { |
| 1125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1126 DCHECK(!download_file_.get()); | 1127 DCHECK(!download_file_.get()); |
| 1127 DCHECK(file.get()); | 1128 DCHECK(file.get()); |
| 1128 DCHECK(req_handle.get()); | 1129 DCHECK(req_handle.get()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 } | 1188 } |
| 1188 | 1189 |
| 1189 // TODO(rdsmith,asanka): We are ignoring the possibility that the download | 1190 // TODO(rdsmith,asanka): We are ignoring the possibility that the download |
| 1190 // has been interrupted at this point until we finish the intermediate | 1191 // has been interrupted at this point until we finish the intermediate |
| 1191 // rename and set the full path. That's dangerous, because we might race | 1192 // rename and set the full path. That's dangerous, because we might race |
| 1192 // with resumption, either manual (because the interrupt is visible to the | 1193 // with resumption, either manual (because the interrupt is visible to the |
| 1193 // UI) or automatic. If we keep the "ignore an error on download until file | 1194 // UI) or automatic. If we keep the "ignore an error on download until file |
| 1194 // name determination complete" semantics, we need to make sure that the | 1195 // name determination complete" semantics, we need to make sure that the |
| 1195 // error is kept completely invisible until that point. | 1196 // error is kept completely invisible until that point. |
| 1196 | 1197 |
| 1197 VLOG(20) << __FUNCTION__ << " " << target_path.value() << " " << disposition | 1198 DVLOG(20) << __FUNCTION__ << " " << target_path.value() << " " << disposition |
| 1198 << " " << danger_type << " " << DebugString(true); | 1199 << " " << danger_type << " " << DebugString(true); |
| 1199 | 1200 |
| 1200 target_path_ = target_path; | 1201 target_path_ = target_path; |
| 1201 target_disposition_ = disposition; | 1202 target_disposition_ = disposition; |
| 1202 SetDangerType(danger_type); | 1203 SetDangerType(danger_type); |
| 1203 | 1204 |
| 1204 // We want the intermediate and target paths to refer to the same directory so | 1205 // We want the intermediate and target paths to refer to the same directory so |
| 1205 // that they are both on the same device and subject to same | 1206 // that they are both on the same device and subject to same |
| 1206 // space/permission/availability constraints. | 1207 // space/permission/availability constraints. |
| 1207 DCHECK(intermediate_path.DirName() == target_path.DirName()); | 1208 DCHECK(intermediate_path.DirName() == target_path.DirName()); |
| 1208 | 1209 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1234 base::Bind(&DownloadFile::RenameAndUniquify, | 1235 base::Bind(&DownloadFile::RenameAndUniquify, |
| 1235 // Safe because we control download file lifetime. | 1236 // Safe because we control download file lifetime. |
| 1236 base::Unretained(download_file_.get()), | 1237 base::Unretained(download_file_.get()), |
| 1237 intermediate_path, callback)); | 1238 intermediate_path, callback)); |
| 1238 } | 1239 } |
| 1239 | 1240 |
| 1240 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( | 1241 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( |
| 1241 DownloadInterruptReason reason, | 1242 DownloadInterruptReason reason, |
| 1242 const base::FilePath& full_path) { | 1243 const base::FilePath& full_path) { |
| 1243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1244 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 1245 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
| 1245 | 1246 |
| 1246 if (DOWNLOAD_INTERRUPT_REASON_NONE != destination_error_) { | 1247 if (DOWNLOAD_INTERRUPT_REASON_NONE != destination_error_) { |
| 1247 // Process destination error. If both |reason| and |destination_error_| | 1248 // Process destination error. If both |reason| and |destination_error_| |
| 1248 // refer to actual errors, we want to use the |destination_error_| as the | 1249 // refer to actual errors, we want to use the |destination_error_| as the |
| 1249 // argument to the Interrupt() routine, as it happened first. | 1250 // argument to the Interrupt() routine, as it happened first. |
| 1250 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) | 1251 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) |
| 1251 SetFullPath(full_path); | 1252 SetFullPath(full_path); |
| 1252 Interrupt(destination_error_); | 1253 Interrupt(destination_error_); |
| 1253 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; | 1254 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 1254 } else if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { | 1255 } else if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 } | 1297 } |
| 1297 | 1298 |
| 1298 // Called by MaybeCompleteDownload() when it has determined that the download | 1299 // Called by MaybeCompleteDownload() when it has determined that the download |
| 1299 // is ready for completion. | 1300 // is ready for completion. |
| 1300 void DownloadItemImpl::OnDownloadCompleting() { | 1301 void DownloadItemImpl::OnDownloadCompleting() { |
| 1301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1302 | 1303 |
| 1303 if (state_ != IN_PROGRESS_INTERNAL) | 1304 if (state_ != IN_PROGRESS_INTERNAL) |
| 1304 return; | 1305 return; |
| 1305 | 1306 |
| 1306 VLOG(20) << __FUNCTION__ << "()" | 1307 DVLOG(20) << __FUNCTION__ << "()" |
| 1307 << " " << DebugString(true); | 1308 << " " << DebugString(true); |
| 1308 DCHECK(!GetTargetFilePath().empty()); | 1309 DCHECK(!GetTargetFilePath().empty()); |
| 1309 DCHECK(!IsDangerous()); | 1310 DCHECK(!IsDangerous()); |
| 1310 | 1311 |
| 1311 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. | 1312 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. |
| 1312 if (is_save_package_download_) { | 1313 if (is_save_package_download_) { |
| 1313 // Avoid doing anything on the file thread; there's nothing we control | 1314 // Avoid doing anything on the file thread; there's nothing we control |
| 1314 // there. | 1315 // there. |
| 1315 // Strictly speaking, this skips giving the embedder a chance to open | 1316 // Strictly speaking, this skips giving the embedder a chance to open |
| 1316 // the download. But on a save package download, there's no real | 1317 // the download. But on a save package download, there's no real |
| 1317 // concept of opening. | 1318 // concept of opening. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1337 const base::FilePath& full_path) { | 1338 const base::FilePath& full_path) { |
| 1338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1339 DCHECK(!is_save_package_download_); | 1340 DCHECK(!is_save_package_download_); |
| 1340 | 1341 |
| 1341 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which | 1342 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which |
| 1342 // will result in deleting the file on the file thread. So we don't | 1343 // will result in deleting the file on the file thread. So we don't |
| 1343 // care about the name having been changed. | 1344 // care about the name having been changed. |
| 1344 if (state_ != IN_PROGRESS_INTERNAL) | 1345 if (state_ != IN_PROGRESS_INTERNAL) |
| 1345 return; | 1346 return; |
| 1346 | 1347 |
| 1347 VLOG(20) << __FUNCTION__ << "()" | 1348 DVLOG(20) << __FUNCTION__ << "()" |
| 1348 << " full_path = \"" << full_path.value() << "\"" | 1349 << " full_path = \"" << full_path.value() << "\"" |
| 1349 << " " << DebugString(false); | 1350 << " " << DebugString(false); |
| 1350 | 1351 |
| 1351 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { | 1352 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { |
| 1352 Interrupt(reason); | 1353 Interrupt(reason); |
| 1353 | 1354 |
| 1354 // All file errors should have resulted in in file deletion above. On | 1355 // All file errors should have resulted in in file deletion above. On |
| 1355 // resumption we will need to re-do filename determination. | 1356 // resumption we will need to re-do filename determination. |
| 1356 DCHECK(current_path_.empty()); | 1357 DCHECK(current_path_.empty()); |
| 1357 return; | 1358 return; |
| 1358 } | 1359 } |
| 1359 | 1360 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1388 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { | 1389 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { |
| 1389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1390 | 1391 |
| 1391 auto_opened_ = auto_opened; | 1392 auto_opened_ = auto_opened; |
| 1392 Completed(); | 1393 Completed(); |
| 1393 } | 1394 } |
| 1394 | 1395 |
| 1395 void DownloadItemImpl::Completed() { | 1396 void DownloadItemImpl::Completed() { |
| 1396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1397 | 1398 |
| 1398 VLOG(20) << __FUNCTION__ << "() " << DebugString(false); | 1399 DVLOG(20) << __FUNCTION__ << "() " << DebugString(false); |
| 1399 | 1400 |
| 1400 DCHECK(all_data_saved_); | 1401 DCHECK(all_data_saved_); |
| 1401 end_time_ = base::Time::Now(); | 1402 end_time_ = base::Time::Now(); |
| 1402 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); | 1403 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); |
| 1403 RecordDownloadCompleted(start_tick_, received_bytes_); | 1404 RecordDownloadCompleted(start_tick_, received_bytes_); |
| 1404 | 1405 |
| 1405 if (auto_opened_) { | 1406 if (auto_opened_) { |
| 1406 // If it was already handled by the delegate, do nothing. | 1407 // If it was already handled by the delegate, do nothing. |
| 1407 } else if (GetOpenWhenComplete() || | 1408 } else if (GetOpenWhenComplete() || |
| 1408 ShouldOpenFileBasedOnExtension() || | 1409 ShouldOpenFileBasedOnExtension() || |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 case CANCELLED_INTERNAL: | 1596 case CANCELLED_INTERNAL: |
| 1596 bound_net_log_.AddEvent( | 1597 bound_net_log_.AddEvent( |
| 1597 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, | 1598 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, |
| 1598 base::Bind(&ItemCanceledNetLogCallback, received_bytes_, | 1599 base::Bind(&ItemCanceledNetLogCallback, received_bytes_, |
| 1599 &hash_state_)); | 1600 &hash_state_)); |
| 1600 break; | 1601 break; |
| 1601 default: | 1602 default: |
| 1602 break; | 1603 break; |
| 1603 } | 1604 } |
| 1604 | 1605 |
| 1605 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) | 1606 DVLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) |
| 1606 << " " << InternalToExternalState(old_state) | 1607 << " " << InternalToExternalState(old_state) |
| 1607 << " " << InternalToExternalState(state_); | 1608 << " " << InternalToExternalState(state_); |
| 1608 | 1609 |
| 1609 bool is_done = (state_ != IN_PROGRESS_INTERNAL && | 1610 bool is_done = (state_ != IN_PROGRESS_INTERNAL && |
| 1610 state_ != COMPLETING_INTERNAL); | 1611 state_ != COMPLETING_INTERNAL); |
| 1611 bool was_done = (old_state != IN_PROGRESS_INTERNAL && | 1612 bool was_done = (old_state != IN_PROGRESS_INTERNAL && |
| 1612 old_state != COMPLETING_INTERNAL); | 1613 old_state != COMPLETING_INTERNAL); |
| 1613 // Termination | 1614 // Termination |
| 1614 if (is_done && !was_done) | 1615 if (is_done && !was_done) |
| 1615 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); | 1616 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); |
| 1616 | 1617 |
| 1617 // Resumption | 1618 // Resumption |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1643 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || | 1644 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || |
| 1644 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || | 1645 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || |
| 1645 danger_type == DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED)) { | 1646 danger_type == DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED)) { |
| 1646 RecordMaliciousDownloadClassified(danger_type); | 1647 RecordMaliciousDownloadClassified(danger_type); |
| 1647 } | 1648 } |
| 1648 danger_type_ = danger_type; | 1649 danger_type_ = danger_type; |
| 1649 } | 1650 } |
| 1650 | 1651 |
| 1651 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { | 1652 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { |
| 1652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1653 VLOG(20) << __FUNCTION__ << "()" | 1654 DVLOG(20) << __FUNCTION__ << "()" |
| 1654 << " new_path = \"" << new_path.value() << "\"" | 1655 << " new_path = \"" << new_path.value() << "\"" |
| 1655 << " " << DebugString(true); | 1656 << " " << DebugString(true); |
| 1656 DCHECK(!new_path.empty()); | 1657 DCHECK(!new_path.empty()); |
| 1657 | 1658 |
| 1658 bound_net_log_.AddEvent( | 1659 bound_net_log_.AddEvent( |
| 1659 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, | 1660 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, |
| 1660 base::Bind(&ItemRenamedNetLogCallback, ¤t_path_, &new_path)); | 1661 base::Bind(&ItemRenamedNetLogCallback, ¤t_path_, &new_path)); |
| 1661 | 1662 |
| 1662 current_path_ = new_path; | 1663 current_path_ = new_path; |
| 1663 } | 1664 } |
| 1664 | 1665 |
| 1665 void DownloadItemImpl::AutoResumeIfValid() { | 1666 void DownloadItemImpl::AutoResumeIfValid() { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 case RESUME_MODE_USER_CONTINUE: | 1804 case RESUME_MODE_USER_CONTINUE: |
| 1804 return "USER_CONTINUE"; | 1805 return "USER_CONTINUE"; |
| 1805 case RESUME_MODE_USER_RESTART: | 1806 case RESUME_MODE_USER_RESTART: |
| 1806 return "USER_RESTART"; | 1807 return "USER_RESTART"; |
| 1807 } | 1808 } |
| 1808 NOTREACHED() << "Unknown resume mode " << mode; | 1809 NOTREACHED() << "Unknown resume mode " << mode; |
| 1809 return "unknown"; | 1810 return "unknown"; |
| 1810 } | 1811 } |
| 1811 | 1812 |
| 1812 } // namespace content | 1813 } // namespace content |
| OLD | NEW |