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

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

Issue 8372034: Created an interface for DownloadFile, for use in unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up download file interface and unit test class. 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 755e6e9698b6ff1d36d8a1aed60e13e31a1247cd..e6a172a5f35cc47769c657d19dead864e92e8969 100644
--- a/content/browser/download/download_file_manager.cc
+++ b/content/browser/download/download_file_manager.cc
@@ -14,7 +14,7 @@
#include "base/utf_string_conversions.h"
#include "content/browser/download/download_buffer.h"
#include "content/browser/download/download_create_info.h"
-#include "content/browser/download/download_file.h"
+#include "content/browser/download/download_file_impl.h"
#include "content/browser/download/download_manager.h"
#include "content/browser/download/download_request_handle.h"
#include "content/browser/download/download_stats.h"
@@ -56,6 +56,15 @@ void DownloadFileManager::OnShutdown() {
STLDeleteValues(&downloads_);
}
+DownloadFile* DownloadFileManager::NewDownloadFile(
+ DownloadCreateInfo* info,
+ const DownloadRequestHandle& request_handle,
+ DownloadManager* download_manager) {
+ return new DownloadFileImpl(info,
+ new DownloadRequestHandle(request_handle),
+ download_manager);
+}
+
void DownloadFileManager::CreateDownloadFile(
DownloadCreateInfo* info, const DownloadRequestHandle& request_handle,
DownloadManager* download_manager, bool get_hash) {
@@ -66,10 +75,8 @@ void DownloadFileManager::CreateDownloadFile(
// Life of |info| ends here. No more references to it after this method.
scoped_ptr<DownloadCreateInfo> infop(info);
- scoped_ptr<DownloadFile>
- download_file(new DownloadFile(info,
- new DownloadRequestHandle(request_handle),
- download_manager));
+ scoped_ptr<DownloadFile> download_file(
+ NewDownloadFile(info, request_handle, download_manager));
if (net::OK != download_file->Initialize(get_hash)) {
request_handle.CancelRequest();
return;
@@ -89,7 +96,8 @@ void DownloadFileManager::CreateDownloadFile(
info->download_id.local()));
}
-DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) {
+DownloadFile* DownloadFileManager::GetDownloadFile(
+ DownloadId global_id) {
DownloadFileMap::iterator it = downloads_.find(global_id);
return it == downloads_.end() ? NULL : it->second;
}
@@ -118,7 +126,7 @@ void DownloadFileManager::UpdateInProgressDownloads() {
if (manager) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::UpdateDownload, manager,
- global_id.local(), download_file->bytes_so_far()));
+ global_id.local(), download_file->BytesSoFar()));
}
}
}
@@ -172,7 +180,7 @@ void DownloadFileManager::UpdateDownload(
DownloadManager* download_manager = download_file->GetDownloadManager();
had_error = true;
- int64 bytes_downloaded = download_file->bytes_so_far();
+ int64 bytes_downloaded = download_file->BytesSoFar();
// 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.
@@ -222,13 +230,13 @@ void DownloadFileManager::OnResponseCompleted(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnResponseCompleted,
download_manager, global_id.local(),
- download_file->bytes_so_far(), hash));
+ download_file->BytesSoFar(), hash));
} else {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnDownloadInterrupted,
download_manager, global_id.local(),
- download_file->bytes_so_far(), reason));
+ download_file->BytesSoFar(), reason));
}
// We need to keep the download around until the UI thread has finalized
// the name.
@@ -286,7 +294,7 @@ void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) {
for (std::set<DownloadFile*>::iterator i = to_remove.begin();
i != to_remove.end(); ++i) {
- downloads_.erase((*i)->global_id());
+ downloads_.erase((*i)->GlobalId());
delete *i;
}
}
@@ -406,7 +414,7 @@ void DownloadFileManager::CancelDownloadOnRename(
BrowserThread::UI, FROM_HERE,
base::Bind(&DownloadManager::OnDownloadInterrupted,
download_manager, global_id.local(),
- download_file->bytes_so_far(),
+ download_file->BytesSoFar(),
ConvertNetErrorToInterruptReason(
rename_error, DOWNLOAD_INTERRUPT_FROM_DISK)));
}

Powered by Google App Engine
This is Rietveld 408576698