| OLD | NEW |
| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } | 21 } |
| 22 | 22 |
| 23 void DownloadJob::Resume(bool resume_request) { | 23 void DownloadJob::Resume(bool resume_request) { |
| 24 is_paused_ = false; | 24 is_paused_ = false; |
| 25 } | 25 } |
| 26 | 26 |
| 27 void DownloadJob::StartDownload() const { | 27 void DownloadJob::StartDownload() const { |
| 28 download_item_->StartDownload(); | 28 download_item_->StartDownload(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void DownloadJob::Interrupt(DownloadInterruptReason reason) { | |
| 32 download_item_->InterruptAndDiscardPartialState(reason); | |
| 33 download_item_->UpdateObservers(); | |
| 34 } | |
| 35 | |
| 36 bool DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, | 31 bool DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, |
| 37 int64_t offset, | 32 int64_t offset, |
| 38 int64_t length) { | 33 int64_t length) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 34 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 40 DownloadFile* download_file = download_item_->download_file_.get(); | 35 DownloadFile* download_file = download_item_->download_file_.get(); |
| 41 if (!download_file) | 36 if (!download_file) |
| 42 return false; | 37 return false; |
| 43 | 38 |
| 44 // download_file_ is owned by download_item_ on the UI thread and is always | 39 // download_file_ is owned by download_item_ on the UI thread and is always |
| 45 // deleted on the FILE thread after download_file_ is nulled out. | 40 // deleted on the FILE thread after download_file_ is nulled out. |
| 46 // So it's safe to use base::Unretained here. | 41 // So it's safe to use base::Unretained here. |
| 47 BrowserThread::PostTask( | 42 BrowserThread::PostTask( |
| 48 BrowserThread::FILE, FROM_HERE, | 43 BrowserThread::FILE, FROM_HERE, |
| 49 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file), | 44 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file), |
| 50 base::Passed(&stream_reader), offset, length)); | 45 base::Passed(&stream_reader), offset, length)); |
| 51 return true; | 46 return true; |
| 52 } | 47 } |
| 53 | 48 |
| 54 void DownloadJob::SetPotentialFileLength(int64_t length) { | |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 56 DownloadFile* download_file = download_item_->download_file_.get(); | |
| 57 if (download_file) { | |
| 58 BrowserThread::PostTask( | |
| 59 BrowserThread::FILE, FROM_HERE, | |
| 60 base::Bind(&DownloadFile::SetPotentialFileLength, | |
| 61 base::Unretained(download_file), length)); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void DownloadJob::CancelRequestWithOffset(int64_t offset) {} | 49 void DownloadJob::CancelRequestWithOffset(int64_t offset) {} |
| 66 | 50 |
| 67 bool DownloadJob::IsParallelizable() const { | 51 bool DownloadJob::IsParallelizable() const { |
| 68 return false; | 52 return false; |
| 69 } | 53 } |
| 70 | 54 |
| 71 } // namespace content | 55 } // namespace content |
| OLD | NEW |