| 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 // File method ordering: Methods in this file are in the same order as | 5 // File method ordering: Methods in this file are in the same order as |
| 6 // in download_item_impl.h, with the following exception: The public | 6 // in download_item_impl.h, with the following exception: The public |
| 7 // interface Start is placed in chronological order with the other | 7 // interface Start is placed in chronological order with the other |
| 8 // (private) routines that together define a DownloadItem's state | 8 // (private) routines that together define a DownloadItem's state |
| 9 // transitions as the download progresses. See "Download progression | 9 // transitions as the download progresses. See "Download progression |
| 10 // cascade" later in this file. | 10 // cascade" later in this file. |
| (...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 // DownloadResourceHandler::OnResponseStarted. | 1417 // DownloadResourceHandler::OnResponseStarted. |
| 1418 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 1418 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 1419 Interrupt(interrupt_reason); | 1419 Interrupt(interrupt_reason); |
| 1420 } | 1420 } |
| 1421 | 1421 |
| 1422 // **** End of Download progression cascade | 1422 // **** End of Download progression cascade |
| 1423 | 1423 |
| 1424 // An error occurred somewhere. | 1424 // An error occurred somewhere. |
| 1425 void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) { | 1425 void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) { |
| 1426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1427 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, reason); |
| 1427 | 1428 |
| 1428 // Somewhat counter-intuitively, it is possible for us to receive an | 1429 // Somewhat counter-intuitively, it is possible for us to receive an |
| 1429 // interrupt after we've already been interrupted. The generation of | 1430 // interrupt after we've already been interrupted. The generation of |
| 1430 // interrupts from the file thread Renames and the generation of | 1431 // interrupts from the file thread Renames and the generation of |
| 1431 // interrupts from disk writes go through two different mechanisms (driven | 1432 // interrupts from disk writes go through two different mechanisms (driven |
| 1432 // by rename requests from UI thread and by write requests from IO thread, | 1433 // by rename requests from UI thread and by write requests from IO thread, |
| 1433 // respectively), and since we choose not to keep state on the File thread, | 1434 // respectively), and since we choose not to keep state on the File thread, |
| 1434 // this is the place where the races collide. It's also possible for | 1435 // this is the place where the races collide. It's also possible for |
| 1435 // interrupts to race with cancels. | 1436 // interrupts to race with cancels. |
| 1436 | 1437 |
| 1437 // Whatever happens, the first one to hit the UI thread wins. | 1438 // Whatever happens, the first one to hit the UI thread wins. |
| 1438 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL) | 1439 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL) |
| 1439 return; | 1440 return; |
| 1440 | 1441 |
| 1441 last_reason_ = reason; | 1442 last_reason_ = reason; |
| 1442 | 1443 |
| 1443 ResumeMode resume_mode = GetResumeMode(); | 1444 ResumeMode resume_mode = GetResumeMode(); |
| 1444 | 1445 |
| 1445 if (state_ == IN_PROGRESS_INTERNAL) { | 1446 if (state_ == IN_PROGRESS_INTERNAL) { |
| 1446 // Cancel (delete file) if we're going to restart; no point in leaving | 1447 // Cancel (delete file) if: |
| 1447 // data around we aren't going to use. Also cancel if resumption isn't | 1448 // 1) we're going to restart. |
| 1448 // enabled for the same reason. | 1449 // 2) Resumption isn't possible (download was cancelled or blocked due to |
| 1450 // security restrictions). |
| 1451 // 3) Resumption isn't enabled. |
| 1452 // No point in leaving data around we aren't going to use. |
| 1449 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || | 1453 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || |
| 1450 resume_mode == RESUME_MODE_USER_RESTART || | 1454 resume_mode == RESUME_MODE_USER_RESTART || |
| 1455 resume_mode == RESUME_MODE_INVALID || |
| 1451 !IsDownloadResumptionEnabled()); | 1456 !IsDownloadResumptionEnabled()); |
| 1452 | 1457 |
| 1453 // Cancel the originating URL request. | 1458 // Cancel the originating URL request. |
| 1454 request_handle_->CancelRequest(); | 1459 request_handle_->CancelRequest(); |
| 1455 } else { | 1460 } else { |
| 1456 DCHECK(!download_file_.get()); | 1461 DCHECK(!download_file_.get()); |
| 1457 } | 1462 } |
| 1458 | 1463 |
| 1459 // Reset all data saved, as even if we did save all the data we're going | 1464 // Reset all data saved, as even if we did save all the data we're going |
| 1460 // to go through another round of downloading when we resume. | 1465 // to go through another round of downloading when we resume. |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 case RESUME_MODE_USER_CONTINUE: | 1787 case RESUME_MODE_USER_CONTINUE: |
| 1783 return "USER_CONTINUE"; | 1788 return "USER_CONTINUE"; |
| 1784 case RESUME_MODE_USER_RESTART: | 1789 case RESUME_MODE_USER_RESTART: |
| 1785 return "USER_RESTART"; | 1790 return "USER_RESTART"; |
| 1786 } | 1791 } |
| 1787 NOTREACHED() << "Unknown resume mode " << mode; | 1792 NOTREACHED() << "Unknown resume mode " << mode; |
| 1788 return "unknown"; | 1793 return "unknown"; |
| 1789 } | 1794 } |
| 1790 | 1795 |
| 1791 } // namespace content | 1796 } // namespace content |
| OLD | NEW |