Chromium Code Reviews| Index: content/browser/download/download_item_impl.cc |
| diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc |
| index f2494eb3fc479ad88b90c3c71d59901c646be2cd..9364ec21aca10c2100a02a51d26422723883a74e 100644 |
| --- a/content/browser/download/download_item_impl.cc |
| +++ b/content/browser/download/download_item_impl.cc |
| @@ -571,11 +571,11 @@ std::string DownloadItemImpl::GetRemoteAddress() const { |
| bool DownloadItemImpl::HasUserGesture() const { |
| return has_user_gesture_; |
| -}; |
| +} |
| ui::PageTransition DownloadItemImpl::GetTransitionType() const { |
| return transition_type_; |
| -}; |
| +} |
| const std::string& DownloadItemImpl::GetLastModifiedTime() const { |
| return last_modified_time_; |
| @@ -856,7 +856,7 @@ DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const { |
| bool user_action_required = |
| (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_); |
| - switch(last_reason_) { |
| + switch (last_reason_) { |
| case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: |
| case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: |
| break; |
| @@ -917,7 +917,6 @@ DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const { |
| case DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED: |
| case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM: |
| case DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN: |
| - // Unhandled. |
| return RESUME_MODE_INVALID; |
| } |
| @@ -1254,22 +1253,29 @@ void DownloadItemImpl::OnDownloadTargetDetermined( |
| const base::FilePath& target_path, |
| TargetDisposition disposition, |
| DownloadDangerType danger_type, |
| - const base::FilePath& intermediate_path) { |
| + const base::FilePath& intermediate_path, |
| + DownloadInterruptReason interrupt_reason) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| DCHECK(state_ == TARGET_PENDING_INTERNAL || |
| state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); |
| - // If the |target_path| is empty, then we consider this download to be |
| - // canceled. |
| - if (target_path.empty()) { |
| + if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED || |
| + target_path.empty()) { |
| Cancel(true); |
| return; |
| } |
| + if (interrupt_reason != DOWNLOAD_INTERRUPT_REASON_NONE) { |
| + InterruptAndDiscardPartialState(interrupt_reason); |
| + UpdateObservers(); |
| + return; |
| + } |
| + |
| DVLOG(20) << __func__ << "() target_path:" << target_path.value() |
|
svaldez
2016/10/28 17:29:36
Should be moved up since otherwise this will never
asanka
2016/11/07 19:50:15
Done.
|
| << " disposition:" << disposition << " danger_type:" << danger_type |
| + << " interrupt_reason:" |
| + << DownloadInterruptReasonToString(interrupt_reason) |
| << " this:" << DebugString(true); |
| - |
| target_path_ = target_path; |
| target_disposition_ = disposition; |
| SetDangerType(danger_type); |
| @@ -1560,8 +1566,10 @@ void DownloadItemImpl::InterruptWithPartialState( |
| if (download_file_) { |
| ResumeMode resume_mode = GetResumeMode(); |
| - ReleaseDownloadFile(resume_mode != RESUME_MODE_IMMEDIATE_CONTINUE && |
| - resume_mode != RESUME_MODE_USER_CONTINUE); |
| + bool destroy_file = bytes_so_far == 0 || |
| + (resume_mode != RESUME_MODE_IMMEDIATE_CONTINUE && |
| + resume_mode != RESUME_MODE_USER_CONTINUE); |
| + ReleaseDownloadFile(destroy_file); |
| } |
| break; |
| @@ -1622,6 +1630,7 @@ void DownloadItemImpl::InterruptWithPartialState( |
| } |
| RecordDownloadCount(CANCELLED_COUNT); |
| + DCHECK_EQ(last_reason_, reason); |
| TransitionTo(CANCELLED_INTERNAL); |
| return; |
| } |
| @@ -1630,6 +1639,10 @@ void DownloadItemImpl::InterruptWithPartialState( |
| if (!GetWebContents()) |
| RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); |
| + // TODO(asanka): This is not good. We can transition to interrupted from |
| + // target-pending, which is something we don't want to do. Perhaps we should |
| + // explicitly transition to target-resolved prior to switching to interrupted. |
| + DCHECK_EQ(last_reason_, reason); |
| TransitionTo(INTERRUPTED_INTERNAL); |
| AutoResumeIfValid(); |
| } |
| @@ -2077,7 +2090,7 @@ const char* DownloadItemImpl::DebugDownloadStateString( |
| return "RESUMING"; |
| case MAX_DOWNLOAD_INTERNAL_STATE: |
| break; |
| - }; |
| + } |
| NOTREACHED() << "Unknown download state " << state; |
| return "unknown"; |
| } |