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

Side by Side 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, 6 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 7 #include "base/bind_helpers.h"
8 #include "content/browser/download/download_file.h"
9 #include "content/browser/download/download_item_impl.h" 8 #include "content/browser/download/download_item_impl.h"
10 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
11 10
12 namespace content { 11 namespace content {
13 12
14 DownloadJob::DownloadJob(DownloadItemImpl* download_item) 13 DownloadJob::DownloadJob(DownloadItemImpl* download_item)
15 : download_item_(download_item), is_paused_(false) {} 14 : download_item_(download_item),
15 is_paused_(false),
16 weak_ptr_factory_(this) {}
16 17
17 DownloadJob::~DownloadJob() = default; 18 DownloadJob::~DownloadJob() = default;
18 19
19 void DownloadJob::Pause() { 20 void DownloadJob::Pause() {
20 is_paused_ = true; 21 is_paused_ = true;
21 } 22 }
22 23
23 void DownloadJob::Resume(bool resume_request) { 24 void DownloadJob::Resume(bool resume_request) {
24 is_paused_ = false; 25 is_paused_ = false;
25 } 26 }
26 27
27 void DownloadJob::StartDownload() const { 28 void DownloadJob::Start(DownloadFile* download_file_,
28 download_item_->StartDownload(); 29 const DownloadFile::InitializeCallback& callback,
30 const DownloadItem::ReceivedSlices& received_slices) {
31 BrowserThread::PostTask(
32 BrowserThread::FILE, FROM_HERE,
33 base::Bind(&DownloadFile::Initialize,
34 // Safe because we control download file lifetime.
35 base::Unretained(download_file_),
36 base::Bind(&DownloadJob::OnDownloadFileInitialized,
37 weak_ptr_factory_.GetWeakPtr(), callback),
38 base::Bind(&DownloadJob::CancelRequestWithOffset,
39 weak_ptr_factory_.GetWeakPtr()),
40 received_slices, IsParallelizable()));
41 }
42
43 void DownloadJob::OnDownloadFileInitialized(
44 const DownloadFile::InitializeCallback& callback,
45 DownloadInterruptReason result) {
46 callback.Run(result);
29 } 47 }
30 48
31 bool DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, 49 bool DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
32 int64_t offset, 50 int64_t offset,
33 int64_t length) { 51 int64_t length) {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI); 52 DCHECK_CURRENTLY_ON(BrowserThread::UI);
35 DownloadFile* download_file = download_item_->download_file_.get(); 53 DownloadFile* download_file = download_item_->download_file_.get();
36 if (!download_file) 54 if (!download_file)
37 return false; 55 return false;
38 56
39 // download_file_ is owned by download_item_ on the UI thread and is always 57 // download_file_ is owned by download_item_ on the UI thread and is always
40 // deleted on the FILE thread after download_file_ is nulled out. 58 // deleted on the FILE thread after download_file_ is nulled out.
41 // So it's safe to use base::Unretained here. 59 // So it's safe to use base::Unretained here.
42 BrowserThread::PostTask( 60 BrowserThread::PostTask(
43 BrowserThread::FILE, FROM_HERE, 61 BrowserThread::FILE, FROM_HERE,
44 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file), 62 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file),
45 base::Passed(&stream_reader), offset, length)); 63 base::Passed(&stream_reader), offset, length));
46 return true; 64 return true;
47 } 65 }
48 66
49 void DownloadJob::CancelRequestWithOffset(int64_t offset) { 67 void DownloadJob::CancelRequestWithOffset(int64_t offset) {
50 NOTREACHED(); 68 NOTREACHED();
51 } 69 }
52 70
53 bool DownloadJob::IsParallelizable() const { 71 bool DownloadJob::IsParallelizable() const {
54 return false; 72 return false;
55 } 73 }
56 74
57 } // namespace content 75 } // namespace content
OLDNEW
« 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