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

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

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: Make windows compiler happy. Created 3 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/download/download_url_task.h"
6
7 #include "content/browser/download/download_create_info.h"
8 #include "content/public/browser/web_contents.h"
9
10 namespace content {
11 namespace {
12
13 const int kVerboseLevel = 1;
14
15 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
16 CreateUrlDownloader(std::unique_ptr<DownloadUrlParameters> params,
17 base::WeakPtr<UrlDownloader::Delegate> delegate) {
18 DCHECK_CURRENTLY_ON(BrowserThread::IO);
19
20 // Build the URLRequest, BlobDataHandle is hold in original request for image
21 // download.
22 std::unique_ptr<net::URLRequest> url_request =
23 DownloadRequestCore::CreateRequestOnIOThread(DownloadItem::kInvalidId,
24 params.get());
25
26 return std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>(
27 UrlDownloader::BeginDownload(delegate, std::move(url_request),
28 params->referrer())
29 .release());
30 }
31
32 } // namespace
33
34 DownloadUrlTask::DownloadUrlTask() : weak_factory_(this) {}
35
36 DownloadUrlTask::~DownloadUrlTask() = default;
37
38 void DownloadUrlTask::SendRequest(
39 std::unique_ptr<DownloadUrlParameters> params) {
40 DCHECK_CURRENTLY_ON(BrowserThread::UI);
41 BrowserThread::PostTaskAndReplyWithResult(
42 BrowserThread::IO, FROM_HERE,
43 base::Bind(&CreateUrlDownloader, base::Passed(&params),
44 weak_factory_.GetWeakPtr()),
45 base::Bind(&DownloadUrlTask::AddUrlDownloader,
46 weak_factory_.GetWeakPtr()));
47 }
48
49 void DownloadUrlTask::Pause() {
50 request_handle_->PauseRequest();
51 }
52
53 void DownloadUrlTask::Resume() {
54 request_handle_->ResumeRequest();
55 }
56
57 void DownloadUrlTask::Cancel() {
58 request_handle_->CancelRequest();
59 }
60
61 void DownloadUrlTask::OnUrlDownloaderStarted(
62 std::unique_ptr<DownloadCreateInfo> create_info,
63 std::unique_ptr<ByteStreamReader> stream_reader,
64 const DownloadUrlParameters::OnStartedCallback& callback) {
65 // |callback| is not used in subsequent requests.
66 DCHECK(callback.is_null());
67
68 // TODO(xingliu): Pass the |stream_reader| to parallel job and handle failed
69 // request.
70 if (create_info->result !=
71 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) {
72 VLOG(kVerboseLevel) << "Parallel download sub request failed. reason = "
73 << create_info->result;
74 NOTIMPLEMENTED();
75 return;
76 }
77
78 request_handle_ = std::move(create_info->request_handle);
79 }
80
81 void DownloadUrlTask::OnUrlDownloaderStopped(UrlDownloader* downloader) {
82 // Release the |url_downloader_|, the object will be deleted on IO thread.
83 url_downloader_.reset();
84 }
85
86 void DownloadUrlTask::AddUrlDownloader(
87 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
88 downloader) {
89 url_downloader_ = std::move(downloader);
90 }
91
92 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698