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

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

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: Make windows compiler happy. Created 3 years, 10 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
Index: content/browser/download/download_item_impl.cc
diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc
index 47ad0ee6944fc98bafb52c0621adf81b0e10e239..b3649c822e07fb451a408e62478618603cae62ab 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -40,9 +40,11 @@
#include "content/browser/download/download_file.h"
#include "content/browser/download/download_interrupt_reasons_impl.h"
#include "content/browser/download/download_item_impl_delegate.h"
+#include "content/browser/download/download_job_factory.h"
#include "content/browser/download/download_net_log_parameters.h"
#include "content/browser/download/download_request_handle.h"
#include "content/browser/download/download_stats.h"
+#include "content/browser/download/download_url_job.h"
#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"
@@ -237,7 +239,6 @@ DownloadItemImpl::DownloadItemImpl(
std::unique_ptr<DownloadRequestHandleInterface> request_handle,
const net::NetLogWithSource& net_log)
: is_save_package_download_(true),
- request_handle_(std::move(request_handle)),
guid_(base::ToUpperASCII(base::GenerateGUID())),
download_id_(download_id),
target_path_(path),
@@ -251,6 +252,9 @@ DownloadItemImpl::DownloadItemImpl(
current_path_(path),
net_log_(net_log),
weak_ptr_factory_(this) {
+ job_ = base::MakeUnique<DownloadUrlJob>(std::move(request_handle));
+ job_->Attach(this);
+
delegate_->Attach();
Init(true /* actively downloading */, SRC_SAVE_PAGE_AS);
}
@@ -367,7 +371,7 @@ void DownloadItemImpl::Pause() {
case IN_PROGRESS_INTERNAL:
case TARGET_PENDING_INTERNAL:
- request_handle_->PauseRequest();
+ job_->Pause();
is_paused_ = true;
asanka 2017/02/16 16:27:39 Consider removing is_paused_ and having the job_ k
xingliu 2017/02/20 18:59:10 Done. Makes sense.
UpdateObservers();
return;
@@ -394,7 +398,7 @@ void DownloadItemImpl::Resume() {
case IN_PROGRESS_INTERNAL:
if (!is_paused_)
return;
- request_handle_->ResumeRequest();
+ job_->Resume();
is_paused_ = false;
UpdateObservers();
return;
@@ -772,9 +776,9 @@ WebContents* DownloadItemImpl::GetWebContents() const {
// paths that might be used by DownloadItems created from history import.
// Currently such items have null request_handle_s, where other items
// (regular and SavePackage downloads) have actual objects off the pointer.
- if (request_handle_)
- return request_handle_->GetWebContents();
- return NULL;
+ if (job_)
+ return job_->GetWebContents();
+ return nullptr;
}
void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) {
@@ -1172,15 +1176,14 @@ void DownloadItemImpl::Start(
DVLOG(20) << __func__ << "() this=" << DebugString(true);
download_file_ = std::move(file);
- request_handle_ = std::move(req_handle);
+ job_ = DownloadJobFactory::CreateJob(std::move(req_handle), new_create_info);
destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE;
if (state_ == CANCELLED_INTERNAL) {
// The download was in the process of resuming when it was cancelled. Don't
// proceed.
ReleaseDownloadFile(true);
- if (request_handle_)
- request_handle_->CancelRequest();
+ job_->Cancel(true);
return;
}
@@ -1232,13 +1235,18 @@ void DownloadItemImpl::Start(
// Successful download start.
DCHECK(download_file_.get());
- DCHECK(request_handle_.get());
+ DCHECK(job_.get());
if (state_ == RESUMING_INTERNAL)
UpdateValidatorsOnResumption(new_create_info);
TransitionTo(TARGET_PENDING_INTERNAL);
+ job_->Attach(this);
asanka 2017/02/16 16:27:39 Why is there a separate Attach() method? It would
xingliu 2017/02/20 18:59:10 Done. Move to pass the item in ctor.
+ job_->Start();
+}
+
+void DownloadItemImpl::InitializeDownloadFile() {
asanka 2017/02/16 16:27:39 This isn't so much initializing the download file,
xingliu 2017/02/20 18:59:10 Done, renamed to StartDownloadProgress.
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&DownloadFile::Initialize,
@@ -1635,8 +1643,8 @@ void DownloadItemImpl::InterruptWithPartialState(
SetHashState(std::move(hash_state));
}
- if (request_handle_)
- request_handle_->CancelRequest();
+ if (job_.get())
+ job_->Cancel(false);
if (reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED ||
reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) {
@@ -1776,7 +1784,7 @@ void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) {
DCHECK(current_path_.DirName() == target_path_.DirName())
<< "Current output directory must match target directory.";
DCHECK(download_file_) << "Output file must be owned by download item.";
- DCHECK(request_handle_) << "Download source must be active.";
+ DCHECK(job_) << "Must have active download job.";
DCHECK(!is_paused_) << "At the time a download enters IN_PROGRESS state, "
"it must not be paused.";
break;

Powered by Google App Engine
This is Rietveld 408576698