OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_request_core.h" | 5 #include "content/browser/download/download_request_core.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 create_info->url_chain = request()->url_chain(); | 243 create_info->url_chain = request()->url_chain(); |
244 create_info->referrer_url = GURL(request()->referrer()); | 244 create_info->referrer_url = GURL(request()->referrer()); |
245 create_info->result = result; | 245 create_info->result = result; |
246 create_info->download_id = download_id_; | 246 create_info->download_id = download_id_; |
247 return create_info; | 247 return create_info; |
248 } | 248 } |
249 | 249 |
250 bool DownloadRequestCore::OnResponseStarted( | 250 bool DownloadRequestCore::OnResponseStarted( |
251 const std::string& override_mime_type) { | 251 const std::string& override_mime_type) { |
252 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 252 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
253 DVLOG(20) << __FUNCTION__ << "()" << DebugString(); | 253 DVLOG(20) << __func__ << "() " << DebugString(); |
254 download_start_time_ = base::TimeTicks::Now(); | 254 download_start_time_ = base::TimeTicks::Now(); |
255 | 255 |
256 DownloadInterruptReason result = | 256 DownloadInterruptReason result = |
257 request()->response_headers() | 257 request()->response_headers() |
258 ? HandleSuccessfulServerResponse(*request()->response_headers(), | 258 ? HandleSuccessfulServerResponse(*request()->response_headers(), |
259 save_info_.get()) | 259 save_info_.get()) |
260 : DOWNLOAD_INTERRUPT_REASON_NONE; | 260 : DOWNLOAD_INTERRUPT_REASON_NONE; |
261 | 261 |
262 std::unique_ptr<DownloadCreateInfo> create_info = | 262 std::unique_ptr<DownloadCreateInfo> create_info = |
263 CreateDownloadCreateInfo(result); | 263 CreateDownloadCreateInfo(result); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 RecordDownloadMimeType(create_info->mime_type); | 331 RecordDownloadMimeType(create_info->mime_type); |
332 RecordDownloadContentDisposition(create_info->content_disposition); | 332 RecordDownloadContentDisposition(create_info->content_disposition); |
333 | 333 |
334 delegate_->OnStart(std::move(create_info), std::move(stream_reader), | 334 delegate_->OnStart(std::move(create_info), std::move(stream_reader), |
335 base::ResetAndReturn(&on_started_callback_)); | 335 base::ResetAndReturn(&on_started_callback_)); |
336 return true; | 336 return true; |
337 } | 337 } |
338 | 338 |
339 bool DownloadRequestCore::OnRequestRedirected() { | 339 bool DownloadRequestCore::OnRequestRedirected() { |
340 DVLOG(20) << __FUNCTION__ << "() " << DebugString(); | 340 DVLOG(20) << __func__ << "() " << DebugString(); |
341 if (is_partial_request_) { | 341 if (is_partial_request_) { |
342 // A redirect while attempting a partial resumption indicates a potential | 342 // A redirect while attempting a partial resumption indicates a potential |
343 // middle box. Trigger another interruption so that the DownloadItem can | 343 // middle box. Trigger another interruption so that the DownloadItem can |
344 // retry. | 344 // retry. |
345 abort_reason_ = DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE; | 345 abort_reason_ = DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE; |
346 return false; | 346 return false; |
347 } | 347 } |
348 return true; | 348 return true; |
349 } | 349 } |
350 | 350 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 read_buffer_ = NULL; // Drop our reference. | 399 read_buffer_ = NULL; // Drop our reference. |
400 | 400 |
401 if (pause_count_ > 0) | 401 if (pause_count_ > 0) |
402 *defer = was_deferred_ = true; | 402 *defer = was_deferred_ = true; |
403 | 403 |
404 return true; | 404 return true; |
405 } | 405 } |
406 | 406 |
407 void DownloadRequestCore::OnWillAbort(DownloadInterruptReason reason) { | 407 void DownloadRequestCore::OnWillAbort(DownloadInterruptReason reason) { |
408 DVLOG(20) << __FUNCTION__ << "() reason=" << reason << " " << DebugString(); | 408 DVLOG(20) << __func__ << "() reason=" << reason << " " << DebugString(); |
409 DCHECK(!started_); | 409 DCHECK(!started_); |
410 abort_reason_ = reason; | 410 abort_reason_ = reason; |
411 } | 411 } |
412 | 412 |
413 void DownloadRequestCore::OnResponseCompleted( | 413 void DownloadRequestCore::OnResponseCompleted( |
414 const net::URLRequestStatus& status) { | 414 const net::URLRequestStatus& status) { |
415 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 415 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
416 int response_code = status.is_success() ? request()->GetResponseCode() : 0; | 416 int response_code = status.is_success() ? request()->GetResponseCode() : 0; |
417 DVLOG(20) << __FUNCTION__ << "()" << DebugString() | 417 DVLOG(20) << __func__ << "() " << DebugString() |
418 << " status.status() = " << status.status() | 418 << " status.status() = " << status.status() |
419 << " status.error() = " << status.error() | 419 << " status.error() = " << status.error() |
420 << " response_code = " << response_code; | 420 << " response_code = " << response_code; |
421 | 421 |
422 DownloadInterruptReason reason = HandleRequestStatus(status); | 422 DownloadInterruptReason reason = HandleRequestStatus(status); |
423 | 423 |
424 if (status.status() == net::URLRequestStatus::CANCELED) { | 424 if (status.status() == net::URLRequestStatus::CANCELED) { |
425 if (abort_reason_ != DOWNLOAD_INTERRUPT_REASON_NONE) { | 425 if (abort_reason_ != DOWNLOAD_INTERRUPT_REASON_NONE) { |
426 // If a more specific interrupt reason was specified before the request | 426 // If a more specific interrupt reason was specified before the request |
427 // was explicitly cancelled, then use it. | 427 // was explicitly cancelled, then use it. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 return DOWNLOAD_INTERRUPT_REASON_NONE; | 628 return DOWNLOAD_INTERRUPT_REASON_NONE; |
629 } | 629 } |
630 | 630 |
631 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) | 631 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) |
632 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; | 632 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; |
633 | 633 |
634 return DOWNLOAD_INTERRUPT_REASON_NONE; | 634 return DOWNLOAD_INTERRUPT_REASON_NONE; |
635 } | 635 } |
636 | 636 |
637 } // namespace content | 637 } // namespace content |
OLD | NEW |