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

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

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Randy's comments. Created 9 years, 1 month 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
Index: content/browser/download/download_file_manager.cc
diff --git a/content/browser/download/download_file_manager.cc b/content/browser/download/download_file_manager.cc
index 97a428075a882589d4a328a6a9a67a7c5054d251..4c09fedf5c0794687899738f6910828ea2549782 100644
--- a/content/browser/download/download_file_manager.cc
+++ b/content/browser/download/download_file_manager.cc
@@ -70,7 +70,8 @@ void DownloadFileManager::CreateDownloadFile(
scoped_ptr<DownloadFile>
download_file(new DownloadFile(info,
new DownloadRequestHandle(request_handle),
- download_manager));
+ download_manager,
+ ""));
Randy Smith (Not in Mondays) 2011/11/16 21:40:25 I'm finding myself a bit uncomfortable about the i
ahendrickson 2011/11/19 20:18:04 We're now using Pickle's instead of strings.
if (net::OK != download_file->Initialize(get_hash)) {
request_handle.CancelRequest();
return;
@@ -117,9 +118,15 @@ void DownloadFileManager::UpdateInProgressDownloads() {
DownloadFile* download_file = i->second;
DownloadManager* manager = download_file->GetDownloadManager();
if (manager) {
+ std::string partial_hash;
+ if (!download_file->GetSha256Hash(&partial_hash) ||
+ BaseFile::IsEmptySha256Hash(partial_hash)) {
+ partial_hash.clear();
+ }
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::UpdateDownload, manager,
- global_id.local(), download_file->bytes_so_far()));
+ global_id.local(), download_file->bytes_so_far(),
+ partial_hash));
}
}
}
@@ -174,6 +181,12 @@ void DownloadFileManager::UpdateDownload(
had_error = true;
int64 bytes_downloaded = download_file->bytes_so_far();
+ std::string partial_hash;
+ if (!download_file->GetSha256Hash(&partial_hash) ||
+ BaseFile::IsEmptySha256Hash(partial_hash)) {
+ partial_hash.clear();
+ }
+
// Calling this here in case we get more data, to avoid
// processing data after an error. That could lead to
// files that are corrupted if the later processing succeeded.
@@ -184,9 +197,13 @@ void DownloadFileManager::UpdateDownload(
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnDownloadInterrupted,
- download_manager, global_id.local(), bytes_downloaded,
+ download_manager,
+ global_id.local(),
+ bytes_downloaded,
+ partial_hash,
ConvertNetErrorToInterruptReason(
- write_result, DOWNLOAD_INTERRUPT_FROM_DISK)));
+ write_result,
+ DOWNLOAD_INTERRUPT_FROM_DISK)));
}
}
}
@@ -214,22 +231,33 @@ void DownloadFileManager::OnResponseCompleted(
return;
}
- std::string hash;
- if (!download_file->GetSha256Hash(&hash) || BaseFile::IsEmptySha256Hash(hash))
- hash.clear();
-
if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) {
+ std::string hash;
+ if (!download_file->GetSha256Hash(&hash) ||
+ BaseFile::IsEmptySha256Hash(hash)) {
+ hash.clear();
+ }
+
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnResponseCompleted,
download_manager, global_id.local(),
download_file->bytes_so_far(), hash));
} else {
+ std::string partial_hash;
+ if (!download_file->GetSha256Hash(&partial_hash) ||
+ BaseFile::IsEmptySha256Hash(partial_hash)) {
+ partial_hash.clear();
Randy Smith (Not in Mondays) 2011/11/16 21:40:25 Why duplicate this code? Can it be hoisted out of
ahendrickson 2011/11/19 20:18:04 One is now a Pickle, but the other is a string.
+ }
+
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnDownloadInterrupted,
- download_manager, global_id.local(),
- download_file->bytes_so_far(), reason));
+ download_manager,
+ global_id.local(),
+ download_file->bytes_so_far(),
+ partial_hash,
+ reason));
}
// We need to keep the download around until the UI thread has finalized
// the name.
@@ -403,13 +431,22 @@ void DownloadFileManager::CancelDownloadOnRename(
return;
}
+ std::string partial_hash;
+ if (!download_file->GetSha256Hash(&partial_hash) ||
+ BaseFile::IsEmptySha256Hash(partial_hash)) {
+ partial_hash.clear();
+ }
+
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnDownloadInterrupted,
- download_manager, global_id.local(),
+ download_manager,
+ global_id.local(),
download_file->bytes_so_far(),
+ partial_hash,
ConvertNetErrorToInterruptReason(
- rename_error, DOWNLOAD_INTERRUPT_FROM_DISK)));
+ rename_error,
+ DOWNLOAD_INTERRUPT_FROM_DISK)));
}
void DownloadFileManager::EraseDownload(DownloadId global_id) {

Powered by Google App Engine
This is Rietveld 408576698