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

Side by Side Diff: content/browser/download/download_job.cc

Issue 2742093002: Glue parallel download job and download file together. (Closed)
Patch Set: Work on feedback. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/download/download_job.h" 5 #include "content/browser/download/download_job.h"
6 6
7 #include "base/bind_helpers.h"
8 #include "content/browser/download/download_file.h"
7 #include "content/browser/download/download_item_impl.h" 9 #include "content/browser/download/download_item_impl.h"
10 #include "content/public/browser/browser_thread.h"
8 11
9 namespace content { 12 namespace content {
10 13
11 DownloadJob::DownloadJob(DownloadItemImpl* download_item) 14 DownloadJob::DownloadJob(DownloadItemImpl* download_item)
12 : download_item_(download_item), is_paused_(false) {} 15 : download_item_(download_item), is_paused_(false) {}
13 16
14 DownloadJob::~DownloadJob() = default; 17 DownloadJob::~DownloadJob() = default;
15 18
16 void DownloadJob::Pause() { 19 void DownloadJob::Pause() {
17 is_paused_ = true; 20 is_paused_ = true;
18 } 21 }
19 22
20 void DownloadJob::Resume(bool resume_request) { 23 void DownloadJob::Resume(bool resume_request) {
21 is_paused_ = false; 24 is_paused_ = false;
22 } 25 }
23 26
24 void DownloadJob::StartDownload() const { 27 void DownloadJob::StartDownload() const {
25 download_item_->StartDownload(); 28 download_item_->StartDownload();
26 } 29 }
27 30
31 void DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
32 int64_t offset,
33 int64_t length) {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI);
35 DownloadFile* download_file = download_item_->download_file_.get();
36 if (!download_file) {
37 VLOG(1) << "Download file is released when byte stream arrived. Discard "
38 "the byte stream.";
39 return;
40 }
41
42 // download_file_ is owned by download_item_ on the UI thread and is always
43 // deleted on the FILE thread after download_file_ is nulled out.
44 // So it's safe to use base::Unretained here.
45 BrowserThread::PostTask(
46 BrowserThread::FILE, FROM_HERE,
47 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file),
48 base::Passed(&stream_reader), offset, length));
49 }
50
28 } // namespace content 51 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698