summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 17:25:09 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 17:25:09 +0000
commit4c402bfd7602197a2d19fe68c9d89a5f6484b4e3 (patch)
treeb8ec5339aee9a28b3ee7de388006245be2ee6116
parent22aa4b67754f518c46bec79c9bedc22a82396e95 (diff)
downloadchromium_src-4c402bfd7602197a2d19fe68c9d89a5f6484b4e3.zip
chromium_src-4c402bfd7602197a2d19fe68c9d89a5f6484b4e3.tar.gz
chromium_src-4c402bfd7602197a2d19fe68c9d89a5f6484b4e3.tar.bz2
Fix a race condition after my latest download cleanup change.
We need to pause the download request until the on-disk file is actually created. Otherwise all data received from network would be discarded. BUG=54131 TEST=see bug Review URL: http://codereview.chromium.org/3333007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58374 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/download/download_file_manager.cc13
-rw-r--r--chrome/browser/download/download_file_manager.h4
-rw-r--r--chrome/browser/renderer_host/download_resource_handler.cc5
3 files changed, 22 insertions, 0 deletions
diff --git a/chrome/browser/download/download_file_manager.cc b/chrome/browser/download/download_file_manager.cc
index 3c1edf9..df28bbf 100644
--- a/chrome/browser/download/download_file_manager.cc
+++ b/chrome/browser/download/download_file_manager.cc
@@ -96,6 +96,12 @@ void DownloadFileManager::CreateDownloadFile(
// TODO(phajdan.jr): fix the duplication of path info below.
info->path = info->save_info.file_path;
+ // The file is now ready, we can un-pause the request and start saving data.
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &DownloadFileManager::ResumeDownloadRequest,
+ info->child_id, info->request_id));
+
StartUpdateTimer();
ChromeThread::PostTask(
@@ -104,6 +110,13 @@ void DownloadFileManager::CreateDownloadFile(
&DownloadManager::StartDownload, info));
}
+void DownloadFileManager::ResumeDownloadRequest(int child_id, int request_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+
+ // This balances the pause in DownloadResourceHandler::OnResponseStarted.
+ resource_dispatcher_host_->PauseRequest(child_id, request_id, false);
+}
+
DownloadFile* DownloadFileManager::GetDownloadFile(int id) {
DownloadFileMap::iterator it = downloads_.find(id);
return it == downloads_.end() ? NULL : it->second;
diff --git a/chrome/browser/download/download_file_manager.h b/chrome/browser/download/download_file_manager.h
index d51d35f..9b909d9 100644
--- a/chrome/browser/download/download_file_manager.h
+++ b/chrome/browser/download/download_file_manager.h
@@ -130,6 +130,10 @@ class DownloadFileManager
void CreateDownloadFile(DownloadCreateInfo* info,
DownloadManager* download_manager);
+ // Tells the ResourceDispatcherHost to resume a download request
+ // that was paused to wait for the on-disk file to be created.
+ void ResumeDownloadRequest(int child_id, int request_id);
+
// Called only on the download thread.
DownloadFile* GetDownloadFile(int id);
diff --git a/chrome/browser/renderer_host/download_resource_handler.cc b/chrome/browser/renderer_host/download_resource_handler.cc
index b1cf07e..3e5f3c0 100644
--- a/chrome/browser/renderer_host/download_resource_handler.cc
+++ b/chrome/browser/renderer_host/download_resource_handler.cc
@@ -95,6 +95,11 @@ bool DownloadResourceHandler::OnResponseStarted(int request_id,
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(
download_file_manager_, &DownloadFileManager::StartDownload, info));
+
+ // We can't start saving the data before we create the file on disk.
+ // The request will be un-paused in DownloadFileManager::CreateDownloadFile.
+ rdh_->PauseRequest(global_id_.child_id, global_id_.request_id, true);
+
return true;
}