Chromium Code Reviews| 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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 std::string DownloadItemImpl::GetOriginalMimeType() const { | 625 std::string DownloadItemImpl::GetOriginalMimeType() const { |
| 626 return original_mime_type_; | 626 return original_mime_type_; |
| 627 } | 627 } |
| 628 | 628 |
| 629 std::string DownloadItemImpl::GetRemoteAddress() const { | 629 std::string DownloadItemImpl::GetRemoteAddress() const { |
| 630 return remote_address_; | 630 return remote_address_; |
| 631 } | 631 } |
| 632 | 632 |
| 633 bool DownloadItemImpl::HasUserGesture() const { | 633 bool DownloadItemImpl::HasUserGesture() const { |
| 634 return has_user_gesture_; | 634 return has_user_gesture_; |
| 635 }; | 635 } |
| 636 | 636 |
| 637 ui::PageTransition DownloadItemImpl::GetTransitionType() const { | 637 ui::PageTransition DownloadItemImpl::GetTransitionType() const { |
| 638 return transition_type_; | 638 return transition_type_; |
| 639 }; | 639 } |
| 640 | 640 |
| 641 const std::string& DownloadItemImpl::GetLastModifiedTime() const { | 641 const std::string& DownloadItemImpl::GetLastModifiedTime() const { |
| 642 return last_modified_time_; | 642 return last_modified_time_; |
| 643 } | 643 } |
| 644 | 644 |
| 645 const std::string& DownloadItemImpl::GetETag() const { | 645 const std::string& DownloadItemImpl::GetETag() const { |
| 646 return etag_; | 646 return etag_; |
| 647 } | 647 } |
| 648 | 648 |
| 649 bool DownloadItemImpl::IsSavePackageDownload() const { | 649 bool DownloadItemImpl::IsSavePackageDownload() const { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 WebContents* DownloadItemImpl::GetWebContents() const { | 819 WebContents* DownloadItemImpl::GetWebContents() const { |
| 820 // TODO(rdsmith): Remove null check after removing GetWebContents() from | 820 // TODO(rdsmith): Remove null check after removing GetWebContents() from |
| 821 // paths that might be used by DownloadItems created from history import. | 821 // paths that might be used by DownloadItems created from history import. |
| 822 // Currently such items have null request_handle_s, where other items | 822 // Currently such items have null request_handle_s, where other items |
| 823 // (regular and SavePackage downloads) have actual objects off the pointer. | 823 // (regular and SavePackage downloads) have actual objects off the pointer. |
| 824 if (job_) | 824 if (job_) |
| 825 return job_->GetWebContents(); | 825 return job_->GetWebContents(); |
| 826 return nullptr; | 826 return nullptr; |
| 827 } | 827 } |
| 828 | 828 |
| 829 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { | 829 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type, |
| 830 DownloadInterruptReason reason) { | |
| 830 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 831 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 831 DCHECK(AllDataSaved()); | 832 DCHECK(AllDataSaved()); |
| 832 | 833 |
| 833 // Danger type is only allowed to be set on an active download after all data | 834 // Danger type is only allowed to be set on an active download after all data |
| 834 // has been saved. This excludes all other states. In particular, | 835 // has been saved. This excludes all other states. In particular, |
| 835 // OnContentCheckCompleted() isn't allowed on an INTERRUPTED download since | 836 // OnContentCheckCompleted() isn't allowed on an INTERRUPTED download since |
| 836 // such an interruption would need to happen between OnAllDataSaved() and | 837 // such an interruption would need to happen between OnAllDataSaved() and |
| 837 // OnContentCheckCompleted() during which no disk or network activity | 838 // OnContentCheckCompleted() during which no disk or network activity |
| 838 // should've taken place. | 839 // should've taken place. |
| 839 DCHECK_EQ(state_, IN_PROGRESS_INTERNAL); | 840 DCHECK_EQ(state_, IN_PROGRESS_INTERNAL); |
| 840 DVLOG(20) << __func__ << "() danger_type=" << danger_type | 841 DVLOG(20) << __func__ << "() danger_type=" << danger_type |
| 841 << " download=" << DebugString(true); | 842 << " download=" << DebugString(true); |
| 842 SetDangerType(danger_type); | 843 SetDangerType(danger_type); |
| 844 if (reason != DOWNLOAD_INTERRUPT_REASON_NONE) | |
| 845 InterruptAndDiscardPartialState(reason); | |
|
asanka
2017/06/06 03:00:36
The only interrupt reasons that make sense here ar
MAD
2017/06/06 18:00:28
Héhé... Interestingly, I initially had a bool and
asanka
2017/06/06 18:34:18
LOL. Apologies for the runaround :). I'll defer to
MAD
2017/06/12 17:38:15
OK, thanks, I'll wait to see if the OWNERs prefer
David Trainor- moved to gerrit
2017/06/12 19:09:04
I'm ok leaving the interrupt reason here. Could w
MAD
2017/06/12 19:45:13
Done.
| |
| 843 UpdateObservers(); | 846 UpdateObservers(); |
| 844 } | 847 } |
| 845 | 848 |
| 846 void DownloadItemImpl::SetOpenWhenComplete(bool open) { | 849 void DownloadItemImpl::SetOpenWhenComplete(bool open) { |
| 847 open_when_complete_ = open; | 850 open_when_complete_ = open; |
| 848 } | 851 } |
| 849 | 852 |
| 850 void DownloadItemImpl::SetOpened(bool opened) { | 853 void DownloadItemImpl::SetOpened(bool opened) { |
| 851 opened_ = opened; | 854 opened_ = opened; |
| 852 } | 855 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 // We also can't continue if we don't have some verifier to make sure | 931 // We also can't continue if we don't have some verifier to make sure |
| 929 // we're getting the same file. | 932 // we're getting the same file. |
| 930 bool restart_required = | 933 bool restart_required = |
| 931 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); | 934 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); |
| 932 | 935 |
| 933 // We won't auto-restart if we've used up our attempts or the | 936 // We won't auto-restart if we've used up our attempts or the |
| 934 // download has been paused by user action. | 937 // download has been paused by user action. |
| 935 bool user_action_required = | 938 bool user_action_required = |
| 936 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); | 939 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); |
| 937 | 940 |
| 938 switch(last_reason_) { | 941 switch (last_reason_) { |
| 939 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: | 942 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: |
| 940 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: | 943 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: |
| 941 case DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH: | 944 case DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH: |
| 942 break; | 945 break; |
| 943 | 946 |
| 944 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: | 947 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: |
| 945 // The server disagreed with the file offset that we sent. | 948 // The server disagreed with the file offset that we sent. |
| 946 | 949 |
| 947 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: | 950 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: |
| 948 // The file on disk was found to not match the expected hash. Discard and | 951 // The file on disk was found to not match the expected hash. Discard and |
| (...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2286 case RESUME_MODE_USER_CONTINUE: | 2289 case RESUME_MODE_USER_CONTINUE: |
| 2287 return "USER_CONTINUE"; | 2290 return "USER_CONTINUE"; |
| 2288 case RESUME_MODE_USER_RESTART: | 2291 case RESUME_MODE_USER_RESTART: |
| 2289 return "USER_RESTART"; | 2292 return "USER_RESTART"; |
| 2290 } | 2293 } |
| 2291 NOTREACHED() << "Unknown resume mode " << mode; | 2294 NOTREACHED() << "Unknown resume mode " << mode; |
| 2292 return "unknown"; | 2295 return "unknown"; |
| 2293 } | 2296 } |
| 2294 | 2297 |
| 2295 } // namespace content | 2298 } // namespace content |
| OLD | NEW |