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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 case CANCELLED_INTERNAL: | 372 case CANCELLED_INTERNAL: |
373 case RESUMING_INTERNAL: | 373 case RESUMING_INTERNAL: |
374 return; | 374 return; |
375 | 375 |
376 case INTERRUPTED_INTERNAL: | 376 case INTERRUPTED_INTERNAL: |
377 auto_resume_count_ = 0; // User input resets the counter. | 377 auto_resume_count_ = 0; // User input resets the counter. |
378 ResumeInterruptedDownload(); | 378 ResumeInterruptedDownload(); |
379 return; | 379 return; |
380 | 380 |
381 case MAX_DOWNLOAD_INTERNAL_STATE: | 381 case MAX_DOWNLOAD_INTERNAL_STATE: |
382 case REMOVED_INTERNAL: | |
benjhayden
2014/11/13 18:01:59
Out of order?
Also, how do you ensure that this i
| |
382 NOTREACHED(); | 383 NOTREACHED(); |
383 } | 384 } |
384 } | 385 } |
385 | 386 |
386 void DownloadItemImpl::Cancel(bool user_cancel) { | 387 void DownloadItemImpl::Cancel(bool user_cancel) { |
387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
388 | 389 |
389 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 390 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
390 if (state_ != IN_PROGRESS_INTERNAL && | 391 if (state_ != IN_PROGRESS_INTERNAL && |
391 state_ != INTERRUPTED_INTERNAL && | 392 state_ != INTERRUPTED_INTERNAL && |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 !current_path_.empty()) { | 427 !current_path_.empty()) { |
427 BrowserThread::PostTask( | 428 BrowserThread::PostTask( |
428 BrowserThread::FILE, FROM_HERE, | 429 BrowserThread::FILE, FROM_HERE, |
429 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), current_path_)); | 430 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), current_path_)); |
430 current_path_.clear(); | 431 current_path_.clear(); |
431 } | 432 } |
432 | 433 |
433 TransitionTo(CANCELLED_INTERNAL, UPDATE_OBSERVERS); | 434 TransitionTo(CANCELLED_INTERNAL, UPDATE_OBSERVERS); |
434 } | 435 } |
435 | 436 |
437 void DownloadItemImpl::MarkRemoved() { | |
438 TransitionTo(REMOVED_INTERNAL, UPDATE_OBSERVERS); | |
439 } | |
440 | |
441 void DownloadItemImpl::UndoRemove() { | |
442 if (state_ != REMOVED_INTERNAL) { | |
arv (Not doing code reviews)
2014/11/13 19:02:30
Why not DCHECK if this stat cannot happen?
| |
443 NOTREACHED(); | |
444 return; | |
445 } | |
446 TransitionTo(prev_state_, UPDATE_OBSERVERS); | |
447 } | |
448 | |
436 void DownloadItemImpl::Remove() { | 449 void DownloadItemImpl::Remove() { |
437 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 450 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
439 | 452 |
440 delegate_->AssertStateConsistent(this); | 453 delegate_->AssertStateConsistent(this); |
441 Cancel(true); | 454 Cancel(true); |
442 delegate_->AssertStateConsistent(this); | 455 delegate_->AssertStateConsistent(this); |
443 | 456 |
444 NotifyRemoved(); | 457 NotifyRemoved(); |
445 delegate_->DownloadRemoved(this); | 458 delegate_->DownloadRemoved(this); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 case COMPLETE_INTERNAL: | 537 case COMPLETE_INTERNAL: |
525 case CANCELLED_INTERNAL: | 538 case CANCELLED_INTERNAL: |
526 return true; | 539 return true; |
527 | 540 |
528 case INTERRUPTED_INTERNAL: | 541 case INTERRUPTED_INTERNAL: |
529 return !CanResume(); | 542 return !CanResume(); |
530 | 543 |
531 case RESUMING_INTERNAL: | 544 case RESUMING_INTERNAL: |
532 return false; | 545 return false; |
533 | 546 |
547 case REMOVED_INTERNAL: | |
benjhayden
2014/11/13 18:01:59
How do you ensure that this isn't reached?
| |
534 case MAX_DOWNLOAD_INTERNAL_STATE: | 548 case MAX_DOWNLOAD_INTERNAL_STATE: |
535 break; | 549 break; |
536 } | 550 } |
537 NOTREACHED(); | 551 NOTREACHED(); |
538 return true; | 552 return true; |
539 } | 553 } |
540 | 554 |
541 const GURL& DownloadItemImpl::GetURL() const { | 555 const GURL& DownloadItemImpl::GetURL() const { |
542 return url_chain_.empty() ? GURL::EmptyGURL() : url_chain_.back(); | 556 return url_chain_.empty() ? GURL::EmptyGURL() : url_chain_.back(); |
543 } | 557 } |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1557 return true; | 1571 return true; |
1558 } | 1572 } |
1559 | 1573 |
1560 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state, | 1574 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state, |
1561 ShouldUpdateObservers notify_action) { | 1575 ShouldUpdateObservers notify_action) { |
1562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1563 | 1577 |
1564 if (state_ == new_state) | 1578 if (state_ == new_state) |
1565 return; | 1579 return; |
1566 | 1580 |
1567 DownloadInternalState old_state = state_; | 1581 prev_state_ = state_; |
benjhayden
2014/11/13 18:01:59
I might want to be a bit more conservative here. I
| |
1568 state_ = new_state; | 1582 state_ = new_state; |
1569 | 1583 |
1570 switch (state_) { | 1584 switch (state_) { |
1571 case COMPLETING_INTERNAL: | 1585 case COMPLETING_INTERNAL: |
1572 bound_net_log_.AddEvent( | 1586 bound_net_log_.AddEvent( |
1573 net::NetLog::TYPE_DOWNLOAD_ITEM_COMPLETING, | 1587 net::NetLog::TYPE_DOWNLOAD_ITEM_COMPLETING, |
1574 base::Bind(&ItemCompletingNetLogCallback, received_bytes_, &hash_)); | 1588 base::Bind(&ItemCompletingNetLogCallback, received_bytes_, &hash_)); |
1575 break; | 1589 break; |
1576 case COMPLETE_INTERNAL: | 1590 case COMPLETE_INTERNAL: |
1577 bound_net_log_.AddEvent( | 1591 bound_net_log_.AddEvent( |
1578 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED, | 1592 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED, |
1579 base::Bind(&ItemFinishedNetLogCallback, auto_opened_)); | 1593 base::Bind(&ItemFinishedNetLogCallback, auto_opened_)); |
1580 break; | 1594 break; |
1581 case INTERRUPTED_INTERNAL: | 1595 case INTERRUPTED_INTERNAL: |
1582 bound_net_log_.AddEvent( | 1596 bound_net_log_.AddEvent( |
1583 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED, | 1597 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED, |
1584 base::Bind(&ItemInterruptedNetLogCallback, last_reason_, | 1598 base::Bind(&ItemInterruptedNetLogCallback, last_reason_, |
1585 received_bytes_, &hash_state_)); | 1599 received_bytes_, &hash_state_)); |
1586 break; | 1600 break; |
1587 case IN_PROGRESS_INTERNAL: | 1601 case IN_PROGRESS_INTERNAL: |
1588 if (old_state == INTERRUPTED_INTERNAL) { | 1602 if (prev_state_ == INTERRUPTED_INTERNAL) { |
1589 bound_net_log_.AddEvent( | 1603 bound_net_log_.AddEvent( |
1590 net::NetLog::TYPE_DOWNLOAD_ITEM_RESUMED, | 1604 net::NetLog::TYPE_DOWNLOAD_ITEM_RESUMED, |
1591 base::Bind(&ItemResumingNetLogCallback, | 1605 base::Bind(&ItemResumingNetLogCallback, |
1592 false, last_reason_, received_bytes_, &hash_state_)); | 1606 false, last_reason_, received_bytes_, &hash_state_)); |
1593 } | 1607 } |
1594 break; | 1608 break; |
1595 case CANCELLED_INTERNAL: | 1609 case CANCELLED_INTERNAL: |
1596 bound_net_log_.AddEvent( | 1610 bound_net_log_.AddEvent( |
1597 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, | 1611 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, |
1598 base::Bind(&ItemCanceledNetLogCallback, received_bytes_, | 1612 base::Bind(&ItemCanceledNetLogCallback, received_bytes_, |
1599 &hash_state_)); | 1613 &hash_state_)); |
1600 break; | 1614 break; |
1601 default: | 1615 default: |
1602 break; | 1616 break; |
1603 } | 1617 } |
1604 | 1618 |
1605 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) | 1619 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) |
1606 << " " << InternalToExternalState(old_state) | 1620 << " " << InternalToExternalState(prev_state_) |
1607 << " " << InternalToExternalState(state_); | 1621 << " " << InternalToExternalState(state_); |
1608 | 1622 |
1609 bool is_done = (state_ != IN_PROGRESS_INTERNAL && | 1623 bool is_done = (state_ != IN_PROGRESS_INTERNAL && |
1610 state_ != COMPLETING_INTERNAL); | 1624 state_ != COMPLETING_INTERNAL); |
1611 bool was_done = (old_state != IN_PROGRESS_INTERNAL && | 1625 bool was_done = (prev_state_ != IN_PROGRESS_INTERNAL && |
1612 old_state != COMPLETING_INTERNAL); | 1626 prev_state_ != COMPLETING_INTERNAL); |
1613 // Termination | 1627 // Termination |
1614 if (is_done && !was_done) | 1628 if (is_done && !was_done) |
1615 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); | 1629 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); |
1616 | 1630 |
1617 // Resumption | 1631 // Resumption |
1618 if (was_done && !is_done) { | 1632 if (was_done && !is_done) { |
1619 std::string file_name(target_path_.BaseName().AsUTF8Unsafe()); | 1633 std::string file_name(target_path_.BaseName().AsUTF8Unsafe()); |
1620 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, | 1634 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, |
1621 base::Bind(&ItemActivatedNetLogCallback, | 1635 base::Bind(&ItemActivatedNetLogCallback, |
1622 this, SRC_ACTIVE_DOWNLOAD, | 1636 this, SRC_ACTIVE_DOWNLOAD, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1737 case COMPLETING_INTERNAL: | 1751 case COMPLETING_INTERNAL: |
1738 return IN_PROGRESS; | 1752 return IN_PROGRESS; |
1739 case COMPLETE_INTERNAL: | 1753 case COMPLETE_INTERNAL: |
1740 return COMPLETE; | 1754 return COMPLETE; |
1741 case CANCELLED_INTERNAL: | 1755 case CANCELLED_INTERNAL: |
1742 return CANCELLED; | 1756 return CANCELLED; |
1743 case INTERRUPTED_INTERNAL: | 1757 case INTERRUPTED_INTERNAL: |
1744 return INTERRUPTED; | 1758 return INTERRUPTED; |
1745 case RESUMING_INTERNAL: | 1759 case RESUMING_INTERNAL: |
1746 return INTERRUPTED; | 1760 return INTERRUPTED; |
1761 case REMOVED_INTERNAL: | |
1762 return REMOVED; | |
1747 case MAX_DOWNLOAD_INTERNAL_STATE: | 1763 case MAX_DOWNLOAD_INTERNAL_STATE: |
1748 break; | 1764 break; |
1749 } | 1765 } |
1750 NOTREACHED(); | 1766 NOTREACHED(); |
1751 return MAX_DOWNLOAD_STATE; | 1767 return MAX_DOWNLOAD_STATE; |
1752 } | 1768 } |
1753 | 1769 |
1754 // static | 1770 // static |
1755 DownloadItemImpl::DownloadInternalState | 1771 DownloadItemImpl::DownloadInternalState |
1756 DownloadItemImpl::ExternalToInternalState( | 1772 DownloadItemImpl::ExternalToInternalState( |
1757 DownloadState external_state) { | 1773 DownloadState external_state) { |
1758 switch (external_state) { | 1774 switch (external_state) { |
1759 case IN_PROGRESS: | 1775 case IN_PROGRESS: |
1760 return IN_PROGRESS_INTERNAL; | 1776 return IN_PROGRESS_INTERNAL; |
1761 case COMPLETE: | 1777 case COMPLETE: |
1762 return COMPLETE_INTERNAL; | 1778 return COMPLETE_INTERNAL; |
1763 case CANCELLED: | 1779 case CANCELLED: |
1764 return CANCELLED_INTERNAL; | 1780 return CANCELLED_INTERNAL; |
1765 case INTERRUPTED: | 1781 case INTERRUPTED: |
1766 return INTERRUPTED_INTERNAL; | 1782 return INTERRUPTED_INTERNAL; |
1783 case REMOVED: | |
1784 return REMOVED_INTERNAL; | |
1767 default: | 1785 default: |
1768 NOTREACHED(); | 1786 NOTREACHED(); |
1769 } | 1787 } |
1770 return MAX_DOWNLOAD_INTERNAL_STATE; | 1788 return MAX_DOWNLOAD_INTERNAL_STATE; |
1771 } | 1789 } |
1772 | 1790 |
1773 const char* DownloadItemImpl::DebugDownloadStateString( | 1791 const char* DownloadItemImpl::DebugDownloadStateString( |
1774 DownloadInternalState state) { | 1792 DownloadInternalState state) { |
1775 switch (state) { | 1793 switch (state) { |
1776 case IN_PROGRESS_INTERNAL: | 1794 case IN_PROGRESS_INTERNAL: |
1777 return "IN_PROGRESS"; | 1795 return "IN_PROGRESS"; |
1778 case COMPLETING_INTERNAL: | 1796 case COMPLETING_INTERNAL: |
1779 return "COMPLETING"; | 1797 return "COMPLETING"; |
1780 case COMPLETE_INTERNAL: | 1798 case COMPLETE_INTERNAL: |
1781 return "COMPLETE"; | 1799 return "COMPLETE"; |
1782 case CANCELLED_INTERNAL: | 1800 case CANCELLED_INTERNAL: |
1783 return "CANCELLED"; | 1801 return "CANCELLED"; |
1784 case INTERRUPTED_INTERNAL: | 1802 case INTERRUPTED_INTERNAL: |
1785 return "INTERRUPTED"; | 1803 return "INTERRUPTED"; |
1786 case RESUMING_INTERNAL: | 1804 case RESUMING_INTERNAL: |
1787 return "RESUMING"; | 1805 return "RESUMING"; |
1806 case REMOVED_INTERNAL: | |
1807 return "REMOVED"; | |
1788 case MAX_DOWNLOAD_INTERNAL_STATE: | 1808 case MAX_DOWNLOAD_INTERNAL_STATE: |
1789 break; | 1809 break; |
1790 }; | 1810 }; |
1791 NOTREACHED() << "Unknown download state " << state; | 1811 NOTREACHED() << "Unknown download state " << state; |
1792 return "unknown"; | 1812 return "unknown"; |
1793 } | 1813 } |
1794 | 1814 |
1795 const char* DownloadItemImpl::DebugResumeModeString(ResumeMode mode) { | 1815 const char* DownloadItemImpl::DebugResumeModeString(ResumeMode mode) { |
1796 switch (mode) { | 1816 switch (mode) { |
1797 case RESUME_MODE_INVALID: | 1817 case RESUME_MODE_INVALID: |
1798 return "INVALID"; | 1818 return "INVALID"; |
1799 case RESUME_MODE_IMMEDIATE_CONTINUE: | 1819 case RESUME_MODE_IMMEDIATE_CONTINUE: |
1800 return "IMMEDIATE_CONTINUE"; | 1820 return "IMMEDIATE_CONTINUE"; |
1801 case RESUME_MODE_IMMEDIATE_RESTART: | 1821 case RESUME_MODE_IMMEDIATE_RESTART: |
1802 return "IMMEDIATE_RESTART"; | 1822 return "IMMEDIATE_RESTART"; |
1803 case RESUME_MODE_USER_CONTINUE: | 1823 case RESUME_MODE_USER_CONTINUE: |
1804 return "USER_CONTINUE"; | 1824 return "USER_CONTINUE"; |
1805 case RESUME_MODE_USER_RESTART: | 1825 case RESUME_MODE_USER_RESTART: |
1806 return "USER_RESTART"; | 1826 return "USER_RESTART"; |
1807 } | 1827 } |
1808 NOTREACHED() << "Unknown resume mode " << mode; | 1828 NOTREACHED() << "Unknown resume mode " << mode; |
1809 return "unknown"; | 1829 return "unknown"; |
1810 } | 1830 } |
1811 | 1831 |
1812 } // namespace content | 1832 } // namespace content |
OLD | NEW |