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

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

Issue 1544603003: [Downloads] Do not store error responses during resumption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unify-downloader-core
Patch Set: Created 4 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/url_downloader.h" 5 #include "content/browser/download/url_downloader.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/threading/sequenced_task_runner_handle.h" 10 #include "base/threading/sequenced_task_runner_handle.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return; 139 return;
140 140
141 request_->set_delegate(this); 141 request_->set_delegate(this);
142 request_->Start(); 142 request_->Start();
143 } 143 }
144 144
145 void UrlDownloader::OnReceivedRedirect(net::URLRequest* request, 145 void UrlDownloader::OnReceivedRedirect(net::URLRequest* request,
146 const net::RedirectInfo& redirect_info, 146 const net::RedirectInfo& redirect_info,
147 bool* defer_redirect) { 147 bool* defer_redirect) {
148 DVLOG(1) << "OnReceivedRedirect: " << request_->url().spec(); 148 DVLOG(1) << "OnReceivedRedirect: " << request_->url().spec();
149 handler_.OnRequestRedirected(redirect_info);
150
151 // We are going to block redirects even if DownloadRequestCore allows it. No
152 // redirects are expected for download requests that are made without a
153 // renderer, which are currently exclusively resumption requests. Since there
154 // is no security policy being applied here, it's safer to block redirects and
155 // revisit if some previously unknown legitimate use case arises for redirects
156 // while resuming.
157 CallStartedCallbackOnFailure(DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE);
149 request_->CancelWithError(net::ERR_ABORTED); 158 request_->CancelWithError(net::ERR_ABORTED);
svaldez 2016/01/13 17:29:18 Might actually want to change this to a more appro
asanka 2016/01/28 02:24:17 Changed to ERR_UNSAFE_REDIRECT which is the error
150 } 159 }
151 160
152 void UrlDownloader::OnResponseStarted(net::URLRequest* request) { 161 void UrlDownloader::OnResponseStarted(net::URLRequest* request) {
153 DVLOG(1) << "OnResponseStarted: " << request_->url().spec(); 162 DVLOG(1) << "OnResponseStarted: " << request_->url().spec();
154 163
155 if (!request_->status().is_success()) { 164 if (!request_->status().is_success()) {
156 ResponseCompleted(); 165 ResponseCompleted();
157 return; 166 return;
158 } 167 }
159 168
160 scoped_ptr<DownloadCreateInfo> create_info; 169 scoped_ptr<DownloadCreateInfo> create_info;
161 scoped_ptr<ByteStreamReader> stream_reader; 170 scoped_ptr<ByteStreamReader> stream_reader;
162 171
163 handler_.OnResponseStarted(&create_info, &stream_reader); 172 DownloadInterruptReason result =
173 handler_.OnResponseStarted(&create_info, &stream_reader);
174 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) {
175 CallStartedCallbackOnFailure(result);
176 Done();
177 return;
178 }
164 179
165 create_info->download_id = download_id_; 180 create_info->download_id = download_id_;
166 create_info->request_handle.reset( 181 create_info->request_handle.reset(
167 new RequestHandle(weak_ptr_factory_.GetWeakPtr(), manager_, 182 new RequestHandle(weak_ptr_factory_.GetWeakPtr(), manager_,
168 base::SequencedTaskRunnerHandle::Get())); 183 base::SequencedTaskRunnerHandle::Get()));
169 BrowserThread::PostTask( 184 BrowserThread::PostTask(
170 BrowserThread::UI, FROM_HERE, 185 BrowserThread::UI, FROM_HERE,
171 base::Bind(&DownloadManagerImpl::StartDownload, manager_, 186 base::Bind(&DownloadManagerImpl::StartDownload, manager_,
172 base::Passed(&create_info), base::Passed(&stream_reader), 187 base::Passed(&create_info), base::Passed(&stream_reader),
173 base::ResetAndReturn(&on_started_callback_))); 188 base::ResetAndReturn(&on_started_callback_)));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // URLRequest reported an EOF. Call ResponseCompleted. 260 // URLRequest reported an EOF. Call ResponseCompleted.
246 DCHECK_EQ(0, bytes_read); 261 DCHECK_EQ(0, bytes_read);
247 ResponseCompleted(); 262 ResponseCompleted();
248 } 263 }
249 } 264 }
250 265
251 void UrlDownloader::ResponseCompleted() { 266 void UrlDownloader::ResponseCompleted() {
252 DVLOG(1) << "ResponseCompleted: " << request_->url().spec(); 267 DVLOG(1) << "ResponseCompleted: " << request_->url().spec();
253 268
254 handler_.OnResponseCompleted(request_->status()); 269 handler_.OnResponseCompleted(request_->status());
255 BrowserThread::PostTask( 270 Done();
256 BrowserThread::UI, FROM_HERE,
257 base::Bind(&DownloadManagerImpl::RemoveUrlDownloader, manager_, this));
258 } 271 }
259 272
260 void UrlDownloader::ResumeReading() { 273 void UrlDownloader::ResumeReading() {
261 if (request_->status().is_success()) { 274 if (request_->status().is_success()) {
262 StartReading(false); // Read the next chunk (OK to complete synchronously). 275 StartReading(false); // Read the next chunk (OK to complete synchronously).
263 } else { 276 } else {
264 ResponseCompleted(); 277 ResponseCompleted();
265 } 278 }
266 } 279 }
267 280
268 void UrlDownloader::CallStartedCallbackOnFailure( 281 void UrlDownloader::CallStartedCallbackOnFailure(
269 DownloadInterruptReason result) { 282 DownloadInterruptReason result) {
270 if (on_started_callback_.is_null()) 283 if (on_started_callback_.is_null())
271 return; 284 return;
272 BrowserThread::PostTask( 285 BrowserThread::PostTask(
273 BrowserThread::UI, FROM_HERE, 286 BrowserThread::UI, FROM_HERE,
274 base::Bind(base::ResetAndReturn(&on_started_callback_), nullptr, result)); 287 base::Bind(base::ResetAndReturn(&on_started_callback_), nullptr, result));
275 } 288 }
276 289
277 void UrlDownloader::PauseRequest() { 290 void UrlDownloader::PauseRequest() {
278 handler_.PauseRequest(); 291 handler_.PauseRequest();
279 } 292 }
280 293
281 void UrlDownloader::ResumeRequest() { 294 void UrlDownloader::ResumeRequest() {
282 handler_.ResumeRequest(); 295 handler_.ResumeRequest();
283 } 296 }
284 297
285 void UrlDownloader::CancelRequest() { 298 void UrlDownloader::CancelRequest() {
299 Done();
300 }
301
302 void UrlDownloader::Done() {
286 BrowserThread::PostTask( 303 BrowserThread::PostTask(
287 BrowserThread::UI, FROM_HERE, 304 BrowserThread::UI, FROM_HERE,
288 base::Bind(&DownloadManagerImpl::RemoveUrlDownloader, manager_, this)); 305 base::Bind(&DownloadManagerImpl::RemoveUrlDownloader, manager_, this));
289 } 306 }
290 307
291 } // namespace content 308 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698