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

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

Issue 2767593003: Handle early pause, cancel for parallel requests. (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" 7 #include "base/bind_helpers.h"
8 #include "content/browser/download/download_file.h" 8 #include "content/browser/download/download_file.h"
9 #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" 10 #include "content/public/browser/browser_thread.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 DownloadJob::DownloadJob(DownloadItemImpl* download_item) 14 DownloadJob::DownloadJob(DownloadItemImpl* download_item)
15 : download_item_(download_item), is_paused_(false) {} 15 : download_item_(download_item), is_paused_(false), is_canceled_(false) {}
16 16
17 DownloadJob::~DownloadJob() = default; 17 DownloadJob::~DownloadJob() = default;
18 18
19 void DownloadJob::Cancel(bool user_cancel) {
20 is_canceled_ = true;
21 }
22
19 void DownloadJob::Pause() { 23 void DownloadJob::Pause() {
20 is_paused_ = true; 24 is_paused_ = true;
21 } 25 }
22 26
23 void DownloadJob::Resume(bool resume_request) { 27 void DownloadJob::Resume(bool resume_request) {
24 is_paused_ = false; 28 is_paused_ = false;
25 } 29 }
26 30
27 void DownloadJob::StartDownload() const { 31 void DownloadJob::StartDownload() const {
28 download_item_->StartDownload(); 32 download_item_->StartDownload();
29 } 33 }
30 34
31 void DownloadJob::Interrupt(DownloadInterruptReason reason) { 35 void DownloadJob::Interrupt(DownloadInterruptReason reason) {
32 download_item_->InterruptAndDiscardPartialState(reason); 36 download_item_->InterruptAndDiscardPartialState(reason);
33 download_item_->UpdateObservers(); 37 download_item_->UpdateObservers();
34 } 38 }
35 39
36 void DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, 40 bool DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
37 int64_t offset, 41 int64_t offset,
38 int64_t length) { 42 int64_t length) {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI); 43 DCHECK_CURRENTLY_ON(BrowserThread::UI);
40 DownloadFile* download_file = download_item_->download_file_.get(); 44 DownloadFile* download_file = download_item_->download_file_.get();
41 if (!download_file) { 45 if (!download_file)
42 // TODO(xingliu): Handle early and late incoming streams, see crbug/702683. 46 return false;
43 VLOG(1) << "Download file is released when byte stream arrived. Discard "
44 "the byte stream.";
45 return;
46 }
47 47
48 // download_file_ is owned by download_item_ on the UI thread and is always 48 // download_file_ is owned by download_item_ on the UI thread and is always
49 // deleted on the FILE thread after download_file_ is nulled out. 49 // deleted on the FILE thread after download_file_ is nulled out.
50 // So it's safe to use base::Unretained here. 50 // So it's safe to use base::Unretained here.
51 BrowserThread::PostTask( 51 BrowserThread::PostTask(
52 BrowserThread::FILE, FROM_HERE, 52 BrowserThread::FILE, FROM_HERE,
53 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file), 53 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file),
54 base::Passed(&stream_reader), offset, length)); 54 base::Passed(&stream_reader), offset, length));
55 return true;
55 } 56 }
56 57
57 } // namespace content 58 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698