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

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

Issue 1418663010: Adding WebContent-free Download (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing Mock for GetBrowserContext. Created 5 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_manager_impl.cc
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index 7562c0f3619b30e5e4e6ea0aa4dfc9c50570710f..1e0c2e1088b2cd89db66b2d7ab06bc2f29f578ff 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -11,6 +11,7 @@
#include "base/debug/alias.h"
#include "base/i18n/case_conversion.h"
#include "base/logging.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
@@ -24,6 +25,7 @@
#include "content/browser/download/download_item_factory.h"
#include "content/browser/download/download_item_impl.h"
#include "content/browser/download/download_stats.h"
+#include "content/browser/download/url_downloader.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
@@ -50,7 +52,8 @@ namespace content {
namespace {
void BeginDownload(scoped_ptr<DownloadUrlParameters> params,
- uint32 download_id) {
+ uint32 download_id,
+ base::WeakPtr<DownloadManagerImpl> download_manager) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and
// DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so
@@ -121,19 +124,20 @@ void BeginDownload(scoped_ptr<DownloadUrlParameters> params,
save_info->prompt_for_save_location = params->prompt();
save_info->file = params->GetFile();
- ResourceDispatcherHost::Get()->BeginDownload(
- request.Pass(),
- params->referrer(),
- params->content_initiated(),
- params->resource_context(),
- params->render_process_host_id(),
- params->render_view_host_routing_id(),
- params->render_frame_host_routing_id(),
- params->prefer_cache(),
- params->do_not_prompt_for_login(),
- save_info.Pass(),
- download_id,
- params->callback());
+ if (params->render_process_host_id() != -1) {
+ ResourceDispatcherHost::Get()->BeginDownload(
+ request.Pass(), params->referrer(), params->content_initiated(),
+ params->resource_context(), params->render_process_host_id(),
+ params->render_view_host_routing_id(),
asanka 2015/11/25 15:53:57 We'd need to check what the status is for download
svaldez 2015/11/25 17:53:28 Shouldn't the status already be checked when we in
asanka 2015/11/25 19:43:11 Sorry, I meant check with the PlzNavigate folks on
+ params->render_frame_host_routing_id(), params->prefer_cache(),
+ params->do_not_prompt_for_login(), save_info.Pass(), download_id,
+ params->callback());
+ } else {
+ UrlDownloader::BeginDownload(
+ download_manager, request.Pass(), params->referrer(), false,
+ params->resource_context(), params->prefer_cache(), true,
+ save_info.Pass(), download_id, params->callback());
+ }
}
class MapValueIteratorAdapter {
@@ -537,10 +541,9 @@ void DownloadManagerImpl::ResumeInterruptedDownload(
scoped_ptr<content::DownloadUrlParameters> params,
uint32 id) {
RecordDownloadSource(INITIATED_BY_RESUMPTION);
- BrowserThread::PostTask(
- BrowserThread::IO,
- FROM_HERE,
- base::Bind(&BeginDownload, base::Passed(&params), id));
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&BeginDownload, base::Passed(&params), id,
+ weak_factory_.GetWeakPtr()));
}
void DownloadManagerImpl::SetDownloadItemFactoryForTesting(
@@ -637,9 +640,10 @@ void DownloadManagerImpl::DownloadUrl(
DCHECK(params->prefer_cache());
DCHECK_EQ("POST", params->method());
}
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
- &BeginDownload, base::Passed(&params),
- content::DownloadItem::kInvalidId));
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&BeginDownload, base::Passed(&params),
+ content::DownloadItem::kInvalidId,
+ weak_factory_.GetWeakPtr()));
}
void DownloadManagerImpl::AddObserver(Observer* observer) {

Powered by Google App Engine
This is Rietveld 408576698