| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 "\"%s\"" | 516 "\"%s\"" |
| 517 " }", | 517 " }", |
| 518 reinterpret_cast<const void*>(this), | 518 reinterpret_cast<const void*>(this), |
| 519 request() ? request()->url().spec().c_str() : "<NULL request>"); | 519 request() ? request()->url().spec().c_str() : "<NULL request>"); |
| 520 } | 520 } |
| 521 | 521 |
| 522 // static | 522 // static |
| 523 DownloadInterruptReason DownloadRequestCore::HandleRequestStatus( | 523 DownloadInterruptReason DownloadRequestCore::HandleRequestStatus( |
| 524 const net::URLRequestStatus& status) { | 524 const net::URLRequestStatus& status) { |
| 525 net::Error error_code = net::OK; | 525 net::Error error_code = net::OK; |
| 526 if (status.status() == net::URLRequestStatus::FAILED || | 526 if (!status.is_success()) { |
| 527 // Note cancels as failures too. | |
| 528 status.status() == net::URLRequestStatus::CANCELED) { | |
| 529 error_code = static_cast<net::Error>(status.error()); // Normal case. | 527 error_code = static_cast<net::Error>(status.error()); // Normal case. |
| 530 // Make sure that at least the fact of failure comes through. | 528 // Make sure that at least the fact of failure comes through. |
| 531 if (error_code == net::OK) | 529 if (error_code == net::OK) |
| 532 error_code = net::ERR_FAILED; | 530 error_code = net::ERR_FAILED; |
| 533 } | 531 } |
| 534 | 532 |
| 535 // ERR_CONTENT_LENGTH_MISMATCH and ERR_INCOMPLETE_CHUNKED_ENCODING are | 533 // ERR_CONTENT_LENGTH_MISMATCH is allowed since a number of servers in the |
| 536 // allowed since a number of servers in the wild close the connection too | 534 // wild close the connection too early by mistake. Other browsers - IE9, |
| 537 // early by mistake. Other browsers - IE9, Firefox 11.0, and Safari 5.1.4 - | 535 // Firefox 11.0, and Safari 5.1.4 - treat downloads as complete in both cases, |
| 538 // treat downloads as complete in both cases, so we follow their lead. | 536 // so we follow their lead. |
| 539 if (error_code == net::ERR_CONTENT_LENGTH_MISMATCH || | 537 if (error_code == net::ERR_CONTENT_LENGTH_MISMATCH) |
| 540 error_code == net::ERR_INCOMPLETE_CHUNKED_ENCODING) { | |
| 541 error_code = net::OK; | 538 error_code = net::OK; |
| 542 } | |
| 543 DownloadInterruptReason reason = ConvertNetErrorToInterruptReason( | 539 DownloadInterruptReason reason = ConvertNetErrorToInterruptReason( |
| 544 error_code, DOWNLOAD_INTERRUPT_FROM_NETWORK); | 540 error_code, DOWNLOAD_INTERRUPT_FROM_NETWORK); |
| 545 | 541 |
| 546 return reason; | 542 return reason; |
| 547 } | 543 } |
| 548 | 544 |
| 549 // static | 545 // static |
| 550 DownloadInterruptReason DownloadRequestCore::HandleSuccessfulServerResponse( | 546 DownloadInterruptReason DownloadRequestCore::HandleSuccessfulServerResponse( |
| 551 const net::HttpResponseHeaders& http_headers, | 547 const net::HttpResponseHeaders& http_headers, |
| 552 DownloadSaveInfo* save_info) { | 548 DownloadSaveInfo* save_info) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 return DOWNLOAD_INTERRUPT_REASON_NONE; | 627 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 632 } | 628 } |
| 633 | 629 |
| 634 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) | 630 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) |
| 635 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; | 631 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; |
| 636 | 632 |
| 637 return DOWNLOAD_INTERRUPT_REASON_NONE; | 633 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 638 } | 634 } |
| 639 | 635 |
| 640 } // namespace content | 636 } // namespace content |
| OLD | NEW |