Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Unified Diff: content/browser/download/download_item.cc

Issue 7983037: Revert 102126 - Make cancel remove cancelled download from active queues at time of cancel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/download/download_item.h ('k') | content/browser/download/download_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
}
« no previous file with comments | « content/browser/download/download_item.h ('k') | content/browser/download/download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698