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

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

Issue 2901383007: Don't create parallel request until download file is initialized (Closed)
Patch Set: Created 3 years, 7 months 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
« no previous file with comments | « content/browser/download/download_job.h ('k') | content/browser/download/download_job_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/download_job.cc
diff --git a/content/browser/download/download_job.cc b/content/browser/download/download_job.cc
index b7f5dfc5075e7dbcbdfb2c5ea1df8879efa982d7..64c3a098c35f67d21dcd7a074cc170bb45c5e590 100644
--- a/content/browser/download/download_job.cc
+++ b/content/browser/download/download_job.cc
@@ -5,14 +5,15 @@
#include "content/browser/download/download_job.h"
#include "base/bind_helpers.h"
-#include "content/browser/download/download_file.h"
#include "content/browser/download/download_item_impl.h"
#include "content/public/browser/browser_thread.h"
namespace content {
DownloadJob::DownloadJob(DownloadItemImpl* download_item)
- : download_item_(download_item), is_paused_(false) {}
+ : download_item_(download_item),
+ is_paused_(false),
+ weak_ptr_factory_(this) {}
DownloadJob::~DownloadJob() = default;
@@ -24,8 +25,25 @@ void DownloadJob::Resume(bool resume_request) {
is_paused_ = false;
}
-void DownloadJob::StartDownload() const {
- download_item_->StartDownload();
+void DownloadJob::Start(DownloadFile* download_file_,
+ const DownloadFile::InitializeCallback& callback,
+ const DownloadItem::ReceivedSlices& received_slices) {
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DownloadFile::Initialize,
+ // Safe because we control download file lifetime.
+ base::Unretained(download_file_),
+ base::Bind(&DownloadJob::OnDownloadFileInitialized,
+ weak_ptr_factory_.GetWeakPtr(), callback),
+ base::Bind(&DownloadJob::CancelRequestWithOffset,
+ weak_ptr_factory_.GetWeakPtr()),
+ received_slices, IsParallelizable()));
+}
+
+void DownloadJob::OnDownloadFileInitialized(
+ const DownloadFile::InitializeCallback& callback,
+ DownloadInterruptReason result) {
+ callback.Run(result);
}
bool DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
« no previous file with comments | « content/browser/download/download_job.h ('k') | content/browser/download/download_job_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698