Chromium Code Reviews| 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" | |
| 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 return; | |
|
David Trainor- moved to gerrit
2017/03/14 17:59:10
When do we expect this to happen?
xingliu
2017/03/14 18:26:31
Done, added a VLOG.
download_file is invalidated
David Trainor- moved to gerrit
2017/03/17 07:15:27
sg. add a TODO to investigate/file a bug?
xingliu
2017/03/17 19:08:25
Done.
| |
| 38 | |
| 39 // The life cycle of download file is controlled by download item, so it's | |
| 40 // safe to use base::Unretained here. | |
| 41 BrowserThread::PostTask( | |
| 42 BrowserThread::FILE, FROM_HERE, | |
| 43 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file), | |
| 44 base::Passed(&stream_reader), offset, length)); | |
| 45 } | |
| 46 | |
| 28 } // namespace content | 47 } // namespace content |
| OLD | NEW |