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

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: Merged with trunk 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 55d4097d037df1cfc836f121369d273376b0d006..e37e5088b258e9c07ccb5988e0589032181bd38e 100644
--- a/content/browser/download/download_file_manager.cc
+++ b/content/browser/download/download_file_manager.cc
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/pickle.h"
#include "base/stl_util.h"
#include "base/utf_string_conversions.h"
#include "content/browser/download/base_file.h"
@@ -70,7 +71,8 @@ void DownloadFileManager::CreateDownloadFile(
scoped_ptr<DownloadFile> download_file(
new DownloadFileImpl(info,
new DownloadRequestHandle(request_handle),
- download_manager));
+ download_manager,
+ Pickle()));
if (net::OK != download_file->Initialize(get_hash)) {
request_handle.CancelRequest();
return;
@@ -118,9 +120,15 @@ void DownloadFileManager::UpdateInProgressDownloads() {
DownloadFile* download_file = i->second;
DownloadManager* manager = download_file->GetDownloadManager();
if (manager) {
+ Pickle hash_state;
+ download_file->GetSha256HashState(&hash_state);
+
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&DownloadManager::UpdateDownload, manager,
- global_id.local(), download_file->BytesSoFar()));
+ base::Bind(&DownloadManager::UpdateDownload,
+ manager,
+ global_id.local(),
+ download_file->BytesSoFar(),
+ hash_state));
}
}
}
@@ -175,6 +183,9 @@ void DownloadFileManager::UpdateDownload(
had_error = true;
int64 bytes_downloaded = download_file->BytesSoFar();
+ Pickle hash_state;
+ download_file->GetSha256HashState(&hash_state);
+
// 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.
@@ -185,9 +196,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,
+ hash_state,
ConvertNetErrorToInterruptReason(
- write_result, DOWNLOAD_INTERRUPT_FROM_DISK)));
+ write_result,
+ DOWNLOAD_INTERRUPT_FROM_DISK)));
}
}
}
@@ -215,22 +230,30 @@ 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->BytesSoFar(), hash));
} else {
+ Pickle hash_state;
+ download_file->GetSha256HashState(&hash_state);
+
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnDownloadInterrupted,
- download_manager, global_id.local(),
- download_file->BytesSoFar(), reason));
+ download_manager,
+ global_id.local(),
+ download_file->BytesSoFar(),
+ hash_state,
+ reason));
}
// We need to keep the download around until the UI thread has finalized
// the name.
@@ -404,13 +427,19 @@ void DownloadFileManager::CancelDownloadOnRename(
return;
}
+ Pickle hash_state;
+ download_file->GetSha256HashState(&hash_state);
+
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnDownloadInterrupted,
- download_manager, global_id.local(),
+ download_manager,
+ global_id.local(),
download_file->BytesSoFar(),
+ hash_state,
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