Index: content/browser/download/download_item.cc |
=================================================================== |
--- content/browser/download/download_item.cc (revision 102135) |
+++ content/browser/download/download_item.cc (working copy) |
@@ -353,27 +353,24 @@ |
UpdateObservers(); |
} |
-void DownloadItem::Cancel() { |
+// Triggered by a user action. |
+void DownloadItem::Cancel(bool update_history) { |
// TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
- // Small downloads might be complete before we have a chance to run. |
- if (!IsInProgress()) |
+ VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
+ if (!IsPartialDownload()) { |
+ // Small downloads might be complete before this method has |
+ // a chance to run. |
return; |
+ } |
- TransitionTo(CANCELLED); |
- |
download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT); |
- // History insertion is the point at which we have finalized download |
- // details and persist them if something goes wrong. Before history |
- // insertion, interrupt or cancel results in download removal. |
- if (db_handle() == DownloadItem::kUninitializedHandle) { |
- download_manager_->RemoveDownload(this); |
- // We are now deleted; no further code should be executed on this |
- // object. |
- } |
+ TransitionTo(CANCELLED); |
+ StopProgressTimer(); |
+ if (update_history) |
+ download_manager_->DownloadCancelledInternal(this); |
} |
void DownloadItem::MarkAsComplete() { |
@@ -432,22 +429,10 @@ |
} |
void DownloadItem::TransitionTo(DownloadState new_state) { |
- DownloadState old_state = state_; |
- if (old_state == new_state) |
+ if (state_ == new_state) |
return; |
- // Check for disallowed state transitions. |
- CHECK(!(old_state == IN_PROGRESS && new_state == REMOVING)); |
- |
state_ = new_state; |
- |
- // Do special operations for transitions from an active state. |
- if (old_state == IN_PROGRESS && |
- (new_state == CANCELLED || new_state == INTERRUPTED)) { |
- download_manager_->DownloadStopped(this); |
- StopProgressTimer(); |
- } |
- |
UpdateObservers(); |
} |
@@ -469,32 +454,20 @@ |
state_info_.target_name = full_path_.BaseName(); |
} |
-void DownloadItem::Interrupt(int64 size, net::Error net_error) { |
+void DownloadItem::Interrupted(int64 size, net::Error net_error) { |
// TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
- // Small downloads might be complete before we have a chance to run. |
if (!IsInProgress()) |
return; |
- UpdateSize(size); |
last_error_ = net_error; |
- |
- TransitionTo(INTERRUPTED); |
- |
+ UpdateSize(size); |
+ StopProgressTimer(); |
download_stats::RecordDownloadInterrupted(net_error, |
received_bytes_, |
total_bytes_); |
- |
- // History insertion is the point at which we have finalized download |
- // details and persist them if something goes wrong. Before history |
- // insertion, interrupt or cancel results in download removal. |
- if (db_handle() == DownloadItem::kUninitializedHandle) { |
- download_manager_->RemoveDownload(this); |
- // We are now deleted; no further code should be executed on this |
- // object. |
- } |
+ TransitionTo(INTERRUPTED); |
} |
void DownloadItem::Delete(DeleteReason reason) { |
@@ -525,14 +498,11 @@ |
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
download_manager_->AssertQueueStateConsistent(this); |
- if (IsInProgress()) { |
- TransitionTo(CANCELLED); |
- download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT); |
- } |
+ Cancel(true); |
download_manager_->AssertQueueStateConsistent(this); |
- download_stats::RecordDownloadCount(download_stats::REMOVED_COUNT); |
- download_manager_->RemoveDownload(this); |
+ TransitionTo(REMOVING); |
+ download_manager_->RemoveDownload(db_handle_); |
// We have now been deleted. |
} |