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

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

Issue 2752603002: Propagate server response error and interrupt the download. (Closed)
Patch Set: 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_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
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(&params), 50 base::Bind(&CreateUrlDownloader, base::Passed(&params),
45 weak_factory_.GetWeakPtr()), 51 weak_factory_.GetWeakPtr()),
46 base::Bind(&DownloadWorker::AddUrlDownloader, 52 base::Bind(&DownloadWorker::AddUrlDownloader,
47 weak_factory_.GetWeakPtr())); 53 weak_factory_.GetWeakPtr()));
48 } 54 }
49 55
50 void DownloadWorker::Pause() { 56 void DownloadWorker::Pause() {
David Trainor- moved to gerrit 2017/03/14 18:01:43 Do we need to propagate any request state changes
xingliu 2017/03/14 21:33:21 Currently we don't, may added if we need more comp
51 request_handle_->PauseRequest(); 57 if (request_handle_)
58 request_handle_->PauseRequest();
52 } 59 }
53 60
54 void DownloadWorker::Resume() { 61 void DownloadWorker::Resume() {
55 request_handle_->ResumeRequest(); 62 if (request_handle_)
63 request_handle_->ResumeRequest();
56 } 64 }
57 65
58 void DownloadWorker::Cancel() { 66 void DownloadWorker::Cancel() {
59 request_handle_->CancelRequest(); 67 if (request_handle_)
68 request_handle_->CancelRequest();
60 } 69 }
61 70
62 void DownloadWorker::OnUrlDownloaderStarted( 71 void DownloadWorker::OnUrlDownloaderStarted(
63 std::unique_ptr<DownloadCreateInfo> create_info, 72 std::unique_ptr<DownloadCreateInfo> create_info,
64 std::unique_ptr<ByteStreamReader> stream_reader, 73 std::unique_ptr<ByteStreamReader> stream_reader,
65 const DownloadUrlParameters::OnStartedCallback& callback) { 74 const DownloadUrlParameters::OnStartedCallback& callback) {
66 // |callback| is not used in subsequent requests. 75 // |callback| is not used in subsequent requests.
67 DCHECK(callback.is_null()); 76 DCHECK(callback.is_null());
68 77
69 // TODO(xingliu): Pass the |stream_reader| to parallel job and handle failed 78 // If the server gave us a different part of the content, due to "If-Match" or
70 // request. 79 // "If-Unmodified-Since" headers, reports an error, which results in the
80 // download to be restarted.
81 if (create_info->save_info->offset != offset() ||
David Trainor- moved to gerrit 2017/03/14 18:01:43 Just want to make sure, do we log this properly so
asanka 2017/03/14 19:52:10 DownloadRequestCore::OnResponseStarted() already h
xingliu 2017/03/14 21:33:21 Make sense. Added log and TODO and remove the rewr
David Trainor- moved to gerrit 2017/03/17 07:29:46 Sounds good! Just checking we have something in p
David Trainor- moved to gerrit 2017/03/17 07:29:46 Yeah once the etag is mismatched I assume we have
82 create_info->save_info->length != length()) {
83 create_info->result = DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE;
84 }
85
71 if (create_info->result != 86 if (create_info->result !=
72 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) { 87 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) {
73 VLOG(kVerboseLevel) << "Parallel download sub request failed. reason = " 88 VLOG(kVerboseLevel) << "Parallel download sub-request failed. reason = "
74 << create_info->result; 89 << create_info->result;
75 NOTIMPLEMENTED(); 90 if (delegate_)
91 delegate_->OnServerResponseError(this, create_info->result);
76 return; 92 return;
77 } 93 }
78 94
79 request_handle_ = std::move(create_info->request_handle); 95 request_handle_ = std::move(create_info->request_handle);
80 } 96 }
81 97
82 void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) { 98 void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) {
83 // Release the |url_downloader_|, the object will be deleted on IO thread. 99 // Release the |url_downloader_|, the object will be deleted on IO thread.
84 url_downloader_.reset(); 100 url_downloader_.reset();
85 } 101 }
86 102
87 void DownloadWorker::AddUrlDownloader( 103 void DownloadWorker::AddUrlDownloader(
88 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> 104 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
89 downloader) { 105 downloader) {
90 url_downloader_ = std::move(downloader); 106 url_downloader_ = std::move(downloader);
91 } 107 }
92 108
93 } // namespace content 109 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698