Chromium Code Reviews| Index: content/browser/download/download_item.cc |
| diff --git a/content/browser/download/download_item.cc b/content/browser/download/download_item.cc |
| index 080987289601b82facb9fbacb99319b1b820f7ad..2868e341fffcacddfa96a8e0ee80138824c7537d 100644 |
| --- a/content/browser/download/download_item.cc |
| +++ b/content/browser/download/download_item.cc |
| @@ -321,6 +321,19 @@ void DownloadItem::UpdateSize(int64 bytes_so_far) { |
| total_bytes_ = 0; |
| } |
| +void DownloadItem::StopInternal(DownloadState target_state) { |
|
benjhayden
2011/09/12 18:13:38
Would you rather do this stuff inside TransitionTo
Randy Smith (Not in Mondays)
2011/09/12 19:43:23
Hmmm. I'm torn. I had originally conceptualized
|
| + // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| + CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(target_state == CANCELLED || target_state == INTERRUPTED); |
|
benjhayden
2011/09/12 18:13:38
Should this be CHECK?
Randy Smith (Not in Mondays)
2011/09/12 19:43:23
Moot (since I'm nuking StopInternal) but I'm not i
Randy Smith (Not in Mondays)
2011/09/12 19:44:36
Sorry, mistyped--I meant "I'm not inclined to make
|
| + |
| + VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
| + DCHECK(IsInProgress()); |
|
benjhayden
2011/09/12 18:13:38
Should this be CHECK?
Randy Smith (Not in Mondays)
2011/09/12 19:43:23
See above.
|
| + |
| + TransitionTo(target_state); |
| + download_manager_->DownloadStopped(this); |
| + StopProgressTimer(); |
| +} |
| + |
| void DownloadItem::StartProgressTimer() { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -352,24 +365,28 @@ void DownloadItem::Update(int64 bytes_so_far) { |
| UpdateObservers(); |
| } |
| -// Triggered by a user action. |
| -void DownloadItem::Cancel(bool update_history) { |
| +// May be triggered by user action or because of various kinds of error. |
|
benjhayden
2011/09/12 18:13:38
What kinds of errors would go through here instead
Randy Smith (Not in Mondays)
2011/09/12 19:43:23
I think this comment was based on a previous incar
|
| +void DownloadItem::Cancel() { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - |
| VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
| - if (!IsPartialDownload()) { |
| - // Small downloads might be complete before this method has |
| - // a chance to run. |
| + |
| + // Small downloads might be complete before we have a chance to run. |
| + if (!IsInProgress()) |
| return; |
| - } |
| + |
| + StopInternal(CANCELLED); |
| download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT); |
| - TransitionTo(CANCELLED); |
| - StopProgressTimer(); |
| - if (update_history) |
| - download_manager_->DownloadCancelledInternal(this); |
| + // 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. |
| + } |
| } |
| void DownloadItem::MarkAsComplete() { |
| @@ -453,20 +470,32 @@ void DownloadItem::UpdateTarget() { |
| state_info_.target_name = full_path_.BaseName(); |
| } |
| -void DownloadItem::Interrupted(int64 size, net::Error net_error) { |
| +void DownloadItem::Interrupt(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; |
| - last_error_ = net_error; |
| UpdateSize(size); |
| - StopProgressTimer(); |
| + last_error_ = net_error; |
| + |
| + StopInternal(INTERRUPTED); |
| + |
| download_stats::RecordDownloadInterrupted(net_error, |
| received_bytes_, |
| total_bytes_); |
| - TransitionTo(INTERRUPTED); |
| + |
| + // 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. |
| + } |
| } |
| void DownloadItem::Delete(DeleteReason reason) { |
| @@ -497,11 +526,14 @@ void DownloadItem::Remove() { |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| download_manager_->AssertQueueStateConsistent(this); |
| - Cancel(true); |
| + if (IsInProgress()) { |
| + StopInternal(CANCELLED); |
| + download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT); |
|
benjhayden
2011/09/12 18:13:38
Want to do this in StopInternal()?
Randy Smith (Not in Mondays)
2011/09/12 19:43:23
I'm disinclined. I'd have to have a conditional (
|
| + } |
| download_manager_->AssertQueueStateConsistent(this); |
| + download_stats::RecordDownloadCount(download_stats::REMOVED_COUNT); |
| - TransitionTo(REMOVING); |
| - download_manager_->RemoveDownload(db_handle_); |
| + download_manager_->RemoveDownload(this); |
| // We have now been deleted. |
| } |