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

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: Removing Core. Created 5 years 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 6a98bc2f8a4a1f5e9eae6f63d78d6ee87f2117f6..fb6b06802c8849bf1467f6a88616b6721b0e81f4 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"
@@ -28,7 +29,6 @@
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
-#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/download_interrupt_reasons.h"
#include "content/public/browser/download_manager_delegate.h"
@@ -49,8 +49,10 @@
namespace content {
namespace {
-void BeginDownload(scoped_ptr<DownloadUrlParameters> params,
- uint32 download_id) {
+UrlDownloader* BeginDownload(
asanka 2015/12/08 21:53:56 You can return a scoped_ptr<UrlDownloader, DeleteO
svaldez 2015/12/09 17:20:41 We can't since using PostTask... with a scoped_ptr
asanka 2015/12/10 16:27:55 PostTaskAndReplyWithResult() correctly forwards mo
+ scoped_ptr<DownloadUrlParameters> params,
+ 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
@@ -120,19 +122,21 @@ 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(),
+ params->render_frame_host_routing_id(), params->prefer_cache(),
+ params->do_not_prompt_for_login(), save_info.Pass(), download_id,
+ params->callback());
+ return nullptr;
+ }
+ return UrlDownloader::BeginDownload(
+ download_manager, request.Pass(), params->referrer(), false,
+ params->prefer_cache(), true, save_info.Pass(), download_id,
+ params->callback())
+ .release();
}
class DownloadItemFactoryImpl : public DownloadItemFactory {
@@ -512,10 +516,12 @@ 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::PostTaskAndReplyWithResult(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&BeginDownload, base::Passed(&params), id,
+ weak_factory_.GetWeakPtr()),
+ base::Bind(&DownloadManagerImpl::AddUrlDownloader,
+ weak_factory_.GetWeakPtr()));
}
void DownloadManagerImpl::SetDownloadItemFactoryForTesting(
@@ -542,6 +548,23 @@ void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
delete download;
}
+void DownloadManagerImpl::AddUrlDownloader(UrlDownloader* downloader) {
+ if (downloader) {
+ url_downloaders_.push_back(
+ scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>(downloader));
+ }
+}
+
+void DownloadManagerImpl::RemoveUrlDownloader(UrlDownloader* downloader) {
+ for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end();
+ ++ptr) {
+ if (ptr->get() == downloader) {
+ url_downloaders_.erase(ptr);
+ return;
+ }
+ }
+}
+
namespace {
bool RemoveDownloadBetween(base::Time remove_begin,
@@ -612,9 +635,12 @@ 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::PostTaskAndReplyWithResult(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&BeginDownload, base::Passed(&params),
+ content::DownloadItem::kInvalidId, weak_factory_.GetWeakPtr()),
+ base::Bind(&DownloadManagerImpl::AddUrlDownloader,
+ weak_factory_.GetWeakPtr()));
}
void DownloadManagerImpl::AddObserver(Observer* observer) {

Powered by Google App Engine
This is Rietveld 408576698