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

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

Issue 2742093002: Glue parallel download job and download file together. (Closed)
Patch Set: Rebase, and adjust unittests with recent landed CLs. Created 3 years, 9 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_factory.cc » ('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 4da7eb429ae6eca4a6b880e8924dbe5f79e7a054..400a3fde9aa58c8f14f2e872d4fce1dc100c35bd 100644
--- a/content/browser/download/download_job.cc
+++ b/content/browser/download/download_job.cc
@@ -4,7 +4,10 @@
#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 {
@@ -25,4 +28,25 @@ void DownloadJob::StartDownload() const {
download_item_->StartDownload();
}
+void DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
+ int64_t offset,
+ int64_t length) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DownloadFile* download_file = download_item_->download_file_.get();
+ if (!download_file) {
+ // TODO(xingliu): Handle early and late incoming streams, see crbug/702683.
+ VLOG(1) << "Download file is released when byte stream arrived. Discard "
+ "the byte stream.";
+ return;
+ }
+
+ // download_file_ is owned by download_item_ on the UI thread and is always
+ // deleted on the FILE thread after download_file_ is nulled out.
+ // So it's safe to use base::Unretained here.
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file),
+ base::Passed(&stream_reader), offset, length));
+}
+
} // namespace content
« no previous file with comments | « content/browser/download/download_job.h ('k') | content/browser/download/download_job_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698