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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 std::string DownloadItemImpl::GetOriginalMimeType() const { | 589 std::string DownloadItemImpl::GetOriginalMimeType() const { |
590 return original_mime_type_; | 590 return original_mime_type_; |
591 } | 591 } |
592 | 592 |
593 std::string DownloadItemImpl::GetRemoteAddress() const { | 593 std::string DownloadItemImpl::GetRemoteAddress() const { |
594 return remote_address_; | 594 return remote_address_; |
595 } | 595 } |
596 | 596 |
597 bool DownloadItemImpl::HasUserGesture() const { | 597 bool DownloadItemImpl::HasUserGesture() const { |
598 return has_user_gesture_; | 598 return has_user_gesture_; |
599 }; | 599 } |
600 | 600 |
601 ui::PageTransition DownloadItemImpl::GetTransitionType() const { | 601 ui::PageTransition DownloadItemImpl::GetTransitionType() const { |
602 return transition_type_; | 602 return transition_type_; |
603 }; | 603 } |
604 | 604 |
605 const std::string& DownloadItemImpl::GetLastModifiedTime() const { | 605 const std::string& DownloadItemImpl::GetLastModifiedTime() const { |
606 return last_modified_time_; | 606 return last_modified_time_; |
607 } | 607 } |
608 | 608 |
609 const std::string& DownloadItemImpl::GetETag() const { | 609 const std::string& DownloadItemImpl::GetETag() const { |
610 return etag_; | 610 return etag_; |
611 } | 611 } |
612 | 612 |
613 bool DownloadItemImpl::IsSavePackageDownload() const { | 613 bool DownloadItemImpl::IsSavePackageDownload() const { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 WebContents* DownloadItemImpl::GetWebContents() const { | 770 WebContents* DownloadItemImpl::GetWebContents() const { |
771 // TODO(rdsmith): Remove null check after removing GetWebContents() from | 771 // TODO(rdsmith): Remove null check after removing GetWebContents() from |
772 // paths that might be used by DownloadItems created from history import. | 772 // paths that might be used by DownloadItems created from history import. |
773 // Currently such items have null request_handle_s, where other items | 773 // Currently such items have null request_handle_s, where other items |
774 // (regular and SavePackage downloads) have actual objects off the pointer. | 774 // (regular and SavePackage downloads) have actual objects off the pointer. |
775 if (request_handle_) | 775 if (request_handle_) |
776 return request_handle_->GetWebContents(); | 776 return request_handle_->GetWebContents(); |
777 return NULL; | 777 return NULL; |
778 } | 778 } |
779 | 779 |
780 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { | 780 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type, |
| 781 bool block_file) { |
781 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 782 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
782 DCHECK(AllDataSaved()); | 783 DCHECK(AllDataSaved()); |
783 | 784 |
784 // Danger type is only allowed to be set on an active download after all data | 785 // Danger type is only allowed to be set on an active download after all data |
785 // has been saved. This excludes all other states. In particular, | 786 // has been saved. This excludes all other states. In particular, |
786 // OnContentCheckCompleted() isn't allowed on an INTERRUPTED download since | 787 // OnContentCheckCompleted() isn't allowed on an INTERRUPTED download since |
787 // such an interruption would need to happen between OnAllDataSaved() and | 788 // such an interruption would need to happen between OnAllDataSaved() and |
788 // OnContentCheckCompleted() during which no disk or network activity | 789 // OnContentCheckCompleted() during which no disk or network activity |
789 // should've taken place. | 790 // should've taken place. |
790 DCHECK_EQ(state_, IN_PROGRESS_INTERNAL); | 791 DCHECK_EQ(state_, IN_PROGRESS_INTERNAL); |
791 DVLOG(20) << __func__ << "() danger_type=" << danger_type | 792 DVLOG(20) << __func__ << "() danger_type=" << danger_type |
792 << " download=" << DebugString(true); | 793 << " download=" << DebugString(true); |
793 SetDangerType(danger_type); | 794 SetDangerType(danger_type); |
| 795 if (block_file) |
| 796 InterruptAndDiscardPartialState(DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); |
794 UpdateObservers(); | 797 UpdateObservers(); |
795 } | 798 } |
796 | 799 |
797 void DownloadItemImpl::SetOpenWhenComplete(bool open) { | 800 void DownloadItemImpl::SetOpenWhenComplete(bool open) { |
798 open_when_complete_ = open; | 801 open_when_complete_ = open; |
799 } | 802 } |
800 | 803 |
801 void DownloadItemImpl::SetOpened(bool opened) { | 804 void DownloadItemImpl::SetOpened(bool opened) { |
802 opened_ = opened; | 805 opened_ = opened; |
803 } | 806 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 // We also can't continue if we don't have some verifier to make sure | 877 // We also can't continue if we don't have some verifier to make sure |
875 // we're getting the same file. | 878 // we're getting the same file. |
876 bool restart_required = | 879 bool restart_required = |
877 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); | 880 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); |
878 | 881 |
879 // We won't auto-restart if we've used up our attempts or the | 882 // We won't auto-restart if we've used up our attempts or the |
880 // download has been paused by user action. | 883 // download has been paused by user action. |
881 bool user_action_required = | 884 bool user_action_required = |
882 (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_); | 885 (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_); |
883 | 886 |
884 switch(last_reason_) { | 887 switch (last_reason_) { |
885 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: | 888 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: |
886 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: | 889 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: |
887 break; | 890 break; |
888 | 891 |
889 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: | 892 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: |
890 // The server disagreed with the file offset that we sent. | 893 // The server disagreed with the file offset that we sent. |
891 | 894 |
892 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: | 895 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: |
893 // The file on disk was found to not match the expected hash. Discard and | 896 // The file on disk was found to not match the expected hash. Discard and |
894 // start from beginning. | 897 // start from beginning. |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2097 case COMPLETE_INTERNAL: | 2100 case COMPLETE_INTERNAL: |
2098 return "COMPLETE"; | 2101 return "COMPLETE"; |
2099 case CANCELLED_INTERNAL: | 2102 case CANCELLED_INTERNAL: |
2100 return "CANCELLED"; | 2103 return "CANCELLED"; |
2101 case INTERRUPTED_INTERNAL: | 2104 case INTERRUPTED_INTERNAL: |
2102 return "INTERRUPTED"; | 2105 return "INTERRUPTED"; |
2103 case RESUMING_INTERNAL: | 2106 case RESUMING_INTERNAL: |
2104 return "RESUMING"; | 2107 return "RESUMING"; |
2105 case MAX_DOWNLOAD_INTERNAL_STATE: | 2108 case MAX_DOWNLOAD_INTERNAL_STATE: |
2106 break; | 2109 break; |
2107 }; | 2110 } |
2108 NOTREACHED() << "Unknown download state " << state; | 2111 NOTREACHED() << "Unknown download state " << state; |
2109 return "unknown"; | 2112 return "unknown"; |
2110 } | 2113 } |
2111 | 2114 |
2112 const char* DownloadItemImpl::DebugResumeModeString(ResumeMode mode) { | 2115 const char* DownloadItemImpl::DebugResumeModeString(ResumeMode mode) { |
2113 switch (mode) { | 2116 switch (mode) { |
2114 case RESUME_MODE_INVALID: | 2117 case RESUME_MODE_INVALID: |
2115 return "INVALID"; | 2118 return "INVALID"; |
2116 case RESUME_MODE_IMMEDIATE_CONTINUE: | 2119 case RESUME_MODE_IMMEDIATE_CONTINUE: |
2117 return "IMMEDIATE_CONTINUE"; | 2120 return "IMMEDIATE_CONTINUE"; |
2118 case RESUME_MODE_IMMEDIATE_RESTART: | 2121 case RESUME_MODE_IMMEDIATE_RESTART: |
2119 return "IMMEDIATE_RESTART"; | 2122 return "IMMEDIATE_RESTART"; |
2120 case RESUME_MODE_USER_CONTINUE: | 2123 case RESUME_MODE_USER_CONTINUE: |
2121 return "USER_CONTINUE"; | 2124 return "USER_CONTINUE"; |
2122 case RESUME_MODE_USER_RESTART: | 2125 case RESUME_MODE_USER_RESTART: |
2123 return "USER_RESTART"; | 2126 return "USER_RESTART"; |
2124 } | 2127 } |
2125 NOTREACHED() << "Unknown resume mode " << mode; | 2128 NOTREACHED() << "Unknown resume mode " << mode; |
2126 return "unknown"; | 2129 return "unknown"; |
2127 } | 2130 } |
2128 | 2131 |
2129 } // namespace content | 2132 } // namespace content |
OLD | NEW |