| 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_worker.h" | 5 #include "content/browser/download/download_worker.h" |
| 6 | 6 |
| 7 #include "content/browser/download/download_create_info.h" | 7 #include "content/browser/download/download_create_info.h" |
| 8 #include "content/public/browser/download_interrupt_reasons.h" | 8 #include "content/public/browser/download_interrupt_reasons.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 params.get()); | 25 params.get()); |
| 26 | 26 |
| 27 return std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>( | 27 return std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>( |
| 28 UrlDownloader::BeginDownload(delegate, std::move(url_request), | 28 UrlDownloader::BeginDownload(delegate, std::move(url_request), |
| 29 params->referrer()) | 29 params->referrer()) |
| 30 .release()); | 30 .release()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 DownloadWorker::DownloadWorker() : weak_factory_(this) {} | 35 DownloadWorker::DownloadWorker(DownloadWorker::Delegate* delegate, |
| 36 int64_t offset, |
| 37 int64_t length) |
| 38 : delegate_(delegate), |
| 39 offset_(offset), |
| 40 length_(length), |
| 41 weak_factory_(this) {} |
| 36 | 42 |
| 37 DownloadWorker::~DownloadWorker() = default; | 43 DownloadWorker::~DownloadWorker() = default; |
| 38 | 44 |
| 39 void DownloadWorker::SendRequest( | 45 void DownloadWorker::SendRequest( |
| 40 std::unique_ptr<DownloadUrlParameters> params) { | 46 std::unique_ptr<DownloadUrlParameters> params) { |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 42 BrowserThread::PostTaskAndReplyWithResult( | 48 BrowserThread::PostTaskAndReplyWithResult( |
| 43 BrowserThread::IO, FROM_HERE, | 49 BrowserThread::IO, FROM_HERE, |
| 44 base::Bind(&CreateUrlDownloader, base::Passed(¶ms), | 50 base::Bind(&CreateUrlDownloader, base::Passed(¶ms), |
| 45 weak_factory_.GetWeakPtr()), | 51 weak_factory_.GetWeakPtr()), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 70 // request. | 76 // request. |
| 71 if (create_info->result != | 77 if (create_info->result != |
| 72 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) { | 78 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 73 VLOG(kVerboseLevel) << "Parallel download sub request failed. reason = " | 79 VLOG(kVerboseLevel) << "Parallel download sub request failed. reason = " |
| 74 << create_info->result; | 80 << create_info->result; |
| 75 NOTIMPLEMENTED(); | 81 NOTIMPLEMENTED(); |
| 76 return; | 82 return; |
| 77 } | 83 } |
| 78 | 84 |
| 79 request_handle_ = std::move(create_info->request_handle); | 85 request_handle_ = std::move(create_info->request_handle); |
| 86 if (delegate_) |
| 87 delegate_->OnByteStreamReady(this, std::move(stream_reader)); |
| 80 } | 88 } |
| 81 | 89 |
| 82 void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) { | 90 void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) { |
| 83 // Release the |url_downloader_|, the object will be deleted on IO thread. | 91 // Release the |url_downloader_|, the object will be deleted on IO thread. |
| 84 url_downloader_.reset(); | 92 url_downloader_.reset(); |
| 85 } | 93 } |
| 86 | 94 |
| 87 void DownloadWorker::AddUrlDownloader( | 95 void DownloadWorker::AddUrlDownloader( |
| 88 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> | 96 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> |
| 89 downloader) { | 97 downloader) { |
| 90 url_downloader_ = std::move(downloader); | 98 url_downloader_ = std::move(downloader); |
| 91 } | 99 } |
| 92 | 100 |
| 93 } // namespace content | 101 } // namespace content |
| OLD | NEW |