Index: chrome/browser/download/download_manager.cc |
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc |
index 5fcd9d4ab86fc2a6d7461d9cd499656e6610a8f1..22ba91fb64a61e6c1bc5b2137d5409648730b9a5 100644 |
--- a/chrome/browser/download/download_manager.cc |
+++ b/chrome/browser/download/download_manager.cc |
@@ -611,24 +611,7 @@ void DownloadManager::UpdateDownload(int32 download_id, int64 size) { |
void DownloadManager::OnResponseCompleted(int32 download_id, |
int64 size, |
- int os_error, |
const std::string& hash) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- // ERR_CONNECTION_CLOSED is allowed since a number of servers in the wild |
- // advertise a larger Content-Length than the amount of bytes in the message |
- // body, and then close the connection. Other browsers - IE8, Firefox 4.0.1, |
- // and Safari 5.0.4 - treat the download as complete in this case, so we |
- // follow their lead. |
- if (os_error == 0 || os_error == net::ERR_CONNECTION_CLOSED) { |
- OnAllDataSaved(download_id, size, hash); |
- } else { |
- OnDownloadError(download_id, size, os_error); |
- } |
-} |
- |
-void DownloadManager::OnAllDataSaved(int32 download_id, |
- int64 size, |
- const std::string& hash) { |
VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id |
<< " size = " << size; |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -805,23 +788,33 @@ void DownloadManager::OnDownloadRenamedToFinalName(int download_id, |
} |
void DownloadManager::DownloadCancelled(int32 download_id) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DownloadMap::iterator it = in_progress_.find(download_id); |
- if (it == in_progress_.end()) |
+ DownloadItem* download = GetActiveDownload(download_id); |
+ |
+ // A cancel at the right time could remove the download from the |
+ // |active_downloads_| map before we get here. |
+ if (!download) |
return; |
- DownloadItem* download = it->second; |
- VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id |
- << " download = " << download->DebugString(true); |
+ RemoveFromActiveList(download); |
- // Clean up will happen when the history system create callback runs if we |
- // don't have a valid db_handle yet. |
- if (download->db_handle() != DownloadHistory::kUninitializedHandle) { |
- in_progress_.erase(it); |
- active_downloads_.erase(download_id); |
- UpdateAppIcon(); // Reflect removal from in_progress_. |
- download_history_->UpdateEntry(download); |
- } |
+ DownloadCancelledInternal(download_id, download->request_handle()); |
+} |
+ |
+void DownloadManager::OnDownloadError(int32 download_id, |
+ int64 size, |
+ int error) { |
+ DownloadItem* download = GetActiveDownload(download_id); |
+ |
cbentzel
2011/08/16 15:50:36
Nit: extra new line.
ahendrickson
2011/08/18 21:52:01
Done.
|
+ if (!download) |
+ return; |
+ |
+ VLOG(20) << __FUNCTION__ << "()" << " Error " << error |
+ << " at offset " << download->received_bytes() |
+ << " size = " << size; |
+ |
+ RemoveFromActiveList(download); |
+ |
cbentzel
2011/08/16 15:50:36
Nit: extra new line
ahendrickson
2011/08/18 21:52:01
Done.
|
+ download->Interrupted(size, error); |
cbentzel
2011/08/16 15:50:36
Nit: extra new line
ahendrickson
2011/08/18 21:52:01
Done.
|
DownloadCancelledInternal(download_id, download->request_handle()); |
} |
@@ -837,40 +830,35 @@ void DownloadManager::DownloadCancelledInternal( |
file_manager_, &DownloadFileManager::CancelDownload, download_id)); |
} |
-void DownloadManager::OnDownloadError(int32 download_id, |
- int64 size, |
- int os_error) { |
+DownloadItem* DownloadManager::GetActiveDownload(int32 download_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DownloadMap::iterator it = active_downloads_.find(download_id); |
- // A cancel at the right time could remove the download from the |
- // |active_downloads_| map before we get here. |
if (it == active_downloads_.end()) |
- return; |
+ return NULL; |
DownloadItem* download = it->second; |
- VLOG(20) << __FUNCTION__ << "()" << " Error " << os_error |
- << " at offset " << download->received_bytes() |
- << " for download = " << download->DebugString(true); |
+ DCHECK(download); |
+ DCHECK_EQ(download_id, download->id()); |
- download->Interrupted(size, os_error); |
+ VLOG(20) << __FUNCTION__ << "()" |
+ << " download = " << download->DebugString(true); |
+ |
+ return download; |
+} |
+ |
+void DownloadManager::RemoveFromActiveList(DownloadItem* download) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ DCHECK(download); |
- // TODO(ahendrickson) - Remove this when we add resuming of interrupted |
- // downloads, as we will keep the download item around in that case. |
- // |
// Clean up will happen when the history system create callback runs if we |
// don't have a valid db_handle yet. |
if (download->db_handle() != DownloadHistory::kUninitializedHandle) { |
- in_progress_.erase(download_id); |
- active_downloads_.erase(download_id); |
+ in_progress_.erase(download->id()); |
+ active_downloads_.erase(download->id()); |
UpdateAppIcon(); // Reflect removal from in_progress_. |
download_history_->UpdateEntry(download); |
} |
- |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- NewRunnableMethod( |
- file_manager_, &DownloadFileManager::CancelDownload, download_id)); |
} |
void DownloadManager::UpdateAppIcon() { |
@@ -1076,6 +1064,9 @@ void DownloadManager::FileSelectionCanceled(void* params) { |
VLOG(20) << __FUNCTION__ << "()" |
<< " download = " << download->DebugString(true); |
+ // TODO(ahendrickson) -- This currently has no effect. |
+ RemoveFromActiveList(download); |
+ |
DownloadCancelledInternal(download_id, download->request_handle()); |
} |