Allow interrupted download to resume if network service is enabled
This CL adds the logic to resume an interrupted download with network service
A helper method is introduced so we can reuse some code.
BUG=715630
Change-Id: I5b3ab183e4db42ad3e9d864cd9e9634552cf90cc
Reviewed-on: https://chromium-review.googlesource.com/721576
Reviewed-by: David Trainor <[email protected]>
Commit-Queue: Min Qin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#509251}
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index 68293acda..ee4db8fe 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -594,15 +594,10 @@
void DownloadManagerImpl::ResumeInterruptedDownload(
std::unique_ptr<content::DownloadUrlParameters> params,
uint32_t id) {
- BrowserThread::PostTaskAndReplyWithResult(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&BeginDownload, base::Passed(¶ms),
- browser_context_->GetResourceContext(), id,
- weak_factory_.GetWeakPtr()),
- base::Bind(&DownloadManagerImpl::AddUrlDownloadHandler,
- weak_factory_.GetWeakPtr()));
+ BeginDownloadInternal(std::move(params), id);
}
+
void DownloadManagerImpl::SetDownloadItemFactoryForTesting(
std::unique_ptr<DownloadItemFactory> item_factory) {
item_factory_ = std::move(item_factory);
@@ -731,34 +726,7 @@
DCHECK_EQ("POST", params->method());
}
- // TODO(qinmin): remove false from the if statement once download works when
- // network service is enabled, or once we disable the tests that are currently
- // passing with the URLRequest code path.
- if (base::FeatureList::IsEnabled(features::kNetworkService)) {
- std::unique_ptr<ResourceRequest> request = CreateResourceRequest(
- params.get());
- StoragePartitionImpl* storage_partition =
- GetStoragePartition(browser_context_, params->render_process_host_id(),
- params->render_frame_host_routing_id());
- BrowserThread::PostTaskAndReplyWithResult(
- BrowserThread::IO, FROM_HERE,
- base::BindOnce(
- &BeginResourceDownload, std::move(params), std::move(request),
- storage_partition->url_loader_factory_getter(),
- base::WrapRefCounted(storage_partition->GetFileSystemContext()),
- content::DownloadItem::kInvalidId, weak_factory_.GetWeakPtr()),
- base::BindOnce(&DownloadManagerImpl::AddUrlDownloadHandler,
- weak_factory_.GetWeakPtr()));
- } else {
- BrowserThread::PostTaskAndReplyWithResult(
- BrowserThread::IO, FROM_HERE,
- base::BindOnce(&BeginDownload, std::move(params),
- browser_context_->GetResourceContext(),
- content::DownloadItem::kInvalidId,
- weak_factory_.GetWeakPtr()),
- base::BindOnce(&DownloadManagerImpl::AddUrlDownloadHandler,
- weak_factory_.GetWeakPtr()));
- }
+ BeginDownloadInternal(std::move(params), content::DownloadItem::kInvalidId);
}
void DownloadManagerImpl::AddObserver(Observer* observer) {
@@ -903,4 +871,33 @@
delegate_->ShowDownloadInShell(download);
}
+void DownloadManagerImpl::BeginDownloadInternal(
+ std::unique_ptr<content::DownloadUrlParameters> params,
+ uint32_t id) {
+ if (base::FeatureList::IsEnabled(features::kNetworkService)) {
+ std::unique_ptr<ResourceRequest> request = CreateResourceRequest(
+ params.get());
+ StoragePartitionImpl* storage_partition =
+ GetStoragePartition(browser_context_, params->render_process_host_id(),
+ params->render_frame_host_routing_id());
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::IO, FROM_HERE,
+ base::BindOnce(
+ &BeginResourceDownload, std::move(params), std::move(request),
+ storage_partition->url_loader_factory_getter(),
+ base::WrapRefCounted(storage_partition->GetFileSystemContext()),
+ id, weak_factory_.GetWeakPtr()),
+ base::BindOnce(&DownloadManagerImpl::AddUrlDownloadHandler,
+ weak_factory_.GetWeakPtr()));
+ } else {
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::IO, FROM_HERE,
+ base::BindOnce(&BeginDownload, std::move(params),
+ browser_context_->GetResourceContext(), id,
+ weak_factory_.GetWeakPtr()),
+ base::BindOnce(&DownloadManagerImpl::AddUrlDownloadHandler,
+ weak_factory_.GetWeakPtr()));
+ }
+}
+
} // namespace content