Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: content/browser/download/download_item_impl.cc

Issue 2453633006: [downloads] Move platform specific code out of DownloadTargetDeterminer. (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 std::string DownloadItemImpl::GetOriginalMimeType() const { 564 std::string DownloadItemImpl::GetOriginalMimeType() const {
565 return original_mime_type_; 565 return original_mime_type_;
566 } 566 }
567 567
568 std::string DownloadItemImpl::GetRemoteAddress() const { 568 std::string DownloadItemImpl::GetRemoteAddress() const {
569 return remote_address_; 569 return remote_address_;
570 } 570 }
571 571
572 bool DownloadItemImpl::HasUserGesture() const { 572 bool DownloadItemImpl::HasUserGesture() const {
573 return has_user_gesture_; 573 return has_user_gesture_;
574 }; 574 }
575 575
576 ui::PageTransition DownloadItemImpl::GetTransitionType() const { 576 ui::PageTransition DownloadItemImpl::GetTransitionType() const {
577 return transition_type_; 577 return transition_type_;
578 }; 578 }
579 579
580 const std::string& DownloadItemImpl::GetLastModifiedTime() const { 580 const std::string& DownloadItemImpl::GetLastModifiedTime() const {
581 return last_modified_time_; 581 return last_modified_time_;
582 } 582 }
583 583
584 const std::string& DownloadItemImpl::GetETag() const { 584 const std::string& DownloadItemImpl::GetETag() const {
585 return etag_; 585 return etag_;
586 } 586 }
587 587
588 bool DownloadItemImpl::IsSavePackageDownload() const { 588 bool DownloadItemImpl::IsSavePackageDownload() const {
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 // We also can't continue if we don't have some verifier to make sure 849 // We also can't continue if we don't have some verifier to make sure
850 // we're getting the same file. 850 // we're getting the same file.
851 bool restart_required = 851 bool restart_required =
852 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); 852 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty()));
853 853
854 // We won't auto-restart if we've used up our attempts or the 854 // We won't auto-restart if we've used up our attempts or the
855 // download has been paused by user action. 855 // download has been paused by user action.
856 bool user_action_required = 856 bool user_action_required =
857 (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_); 857 (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_);
858 858
859 switch(last_reason_) { 859 switch (last_reason_) {
860 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: 860 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR:
861 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: 861 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT:
862 break; 862 break;
863 863
864 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: 864 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE:
865 // The server disagreed with the file offset that we sent. 865 // The server disagreed with the file offset that we sent.
866 866
867 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: 867 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH:
868 // The file on disk was found to not match the expected hash. Discard and 868 // The file on disk was found to not match the expected hash. Discard and
869 // start from beginning. 869 // start from beginning.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 case DOWNLOAD_INTERRUPT_REASON_NONE: 910 case DOWNLOAD_INTERRUPT_REASON_NONE:
911 case DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST: 911 case DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST:
912 case DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED: 912 case DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED:
913 case DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT: 913 case DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT:
914 case DOWNLOAD_INTERRUPT_REASON_USER_CANCELED: 914 case DOWNLOAD_INTERRUPT_REASON_USER_CANCELED:
915 case DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED: 915 case DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED:
916 case DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED: 916 case DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED:
917 case DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED: 917 case DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED:
918 case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM: 918 case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM:
919 case DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN: 919 case DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN:
920 // Unhandled.
921 return RESUME_MODE_INVALID; 920 return RESUME_MODE_INVALID;
922 } 921 }
923 922
924 if (user_action_required && restart_required) 923 if (user_action_required && restart_required)
925 return RESUME_MODE_USER_RESTART; 924 return RESUME_MODE_USER_RESTART;
926 925
927 if (restart_required) 926 if (restart_required)
928 return RESUME_MODE_IMMEDIATE_RESTART; 927 return RESUME_MODE_IMMEDIATE_RESTART;
929 928
930 if (user_action_required) 929 if (user_action_required)
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 delegate_->DetermineDownloadTarget( 1246 delegate_->DetermineDownloadTarget(
1248 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, 1247 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined,
1249 weak_ptr_factory_.GetWeakPtr())); 1248 weak_ptr_factory_.GetWeakPtr()));
1250 } 1249 }
1251 1250
1252 // Called by delegate_ when the download target path has been determined. 1251 // Called by delegate_ when the download target path has been determined.
1253 void DownloadItemImpl::OnDownloadTargetDetermined( 1252 void DownloadItemImpl::OnDownloadTargetDetermined(
1254 const base::FilePath& target_path, 1253 const base::FilePath& target_path,
1255 TargetDisposition disposition, 1254 TargetDisposition disposition,
1256 DownloadDangerType danger_type, 1255 DownloadDangerType danger_type,
1257 const base::FilePath& intermediate_path) { 1256 const base::FilePath& intermediate_path,
1257 DownloadInterruptReason interrupt_reason) {
1258 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1258 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1259 DCHECK(state_ == TARGET_PENDING_INTERNAL || 1259 DCHECK(state_ == TARGET_PENDING_INTERNAL ||
1260 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL); 1260 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL);
1261 1261
1262 // If the |target_path| is empty, then we consider this download to be 1262 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED ||
1263 // canceled. 1263 target_path.empty()) {
1264 if (target_path.empty()) {
1265 Cancel(true); 1264 Cancel(true);
1266 return; 1265 return;
1267 } 1266 }
1268 1267
1268 if (interrupt_reason != DOWNLOAD_INTERRUPT_REASON_NONE) {
1269 InterruptAndDiscardPartialState(interrupt_reason);
1270 UpdateObservers();
1271 return;
1272 }
1273
1269 DVLOG(20) << __func__ << "() target_path:" << target_path.value() 1274 DVLOG(20) << __func__ << "() target_path:" << target_path.value()
svaldez 2016/10/28 17:29:36 Should be moved up since otherwise this will never
asanka 2016/11/07 19:50:15 Done.
1270 << " disposition:" << disposition << " danger_type:" << danger_type 1275 << " disposition:" << disposition << " danger_type:" << danger_type
1276 << " interrupt_reason:"
1277 << DownloadInterruptReasonToString(interrupt_reason)
1271 << " this:" << DebugString(true); 1278 << " this:" << DebugString(true);
1272
1273 target_path_ = target_path; 1279 target_path_ = target_path;
1274 target_disposition_ = disposition; 1280 target_disposition_ = disposition;
1275 SetDangerType(danger_type); 1281 SetDangerType(danger_type);
1276 1282
1277 // This was an interrupted download that was looking for a filename. Now that 1283 // This was an interrupted download that was looking for a filename. Now that
1278 // it has one, transition to interrupted. 1284 // it has one, transition to interrupted.
1279 if (state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) { 1285 if (state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) {
1280 InterruptWithPartialState( 1286 InterruptWithPartialState(
1281 received_bytes_, std::move(hash_state_), destination_error_); 1287 received_bytes_, std::move(hash_state_), destination_error_);
1282 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; 1288 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 1559
1554 case INTERRUPTED_TARGET_PENDING_INTERNAL: 1560 case INTERRUPTED_TARGET_PENDING_INTERNAL:
1555 case IN_PROGRESS_INTERNAL: 1561 case IN_PROGRESS_INTERNAL:
1556 case TARGET_PENDING_INTERNAL: 1562 case TARGET_PENDING_INTERNAL:
1557 case TARGET_RESOLVED_INTERNAL: 1563 case TARGET_RESOLVED_INTERNAL:
1558 // last_reason_ needs to be set for GetResumeMode() to work. 1564 // last_reason_ needs to be set for GetResumeMode() to work.
1559 last_reason_ = reason; 1565 last_reason_ = reason;
1560 1566
1561 if (download_file_) { 1567 if (download_file_) {
1562 ResumeMode resume_mode = GetResumeMode(); 1568 ResumeMode resume_mode = GetResumeMode();
1563 ReleaseDownloadFile(resume_mode != RESUME_MODE_IMMEDIATE_CONTINUE && 1569 bool destroy_file = bytes_so_far == 0 ||
1564 resume_mode != RESUME_MODE_USER_CONTINUE); 1570 (resume_mode != RESUME_MODE_IMMEDIATE_CONTINUE &&
1571 resume_mode != RESUME_MODE_USER_CONTINUE);
1572 ReleaseDownloadFile(destroy_file);
1565 } 1573 }
1566 break; 1574 break;
1567 1575
1568 case RESUMING_INTERNAL: 1576 case RESUMING_INTERNAL:
1569 case INTERRUPTED_INTERNAL: 1577 case INTERRUPTED_INTERNAL:
1570 DCHECK(!download_file_); 1578 DCHECK(!download_file_);
1571 // The first non-cancel interrupt reason wins in cases where multiple 1579 // The first non-cancel interrupt reason wins in cases where multiple
1572 // things go wrong. 1580 // things go wrong.
1573 if (reason != DOWNLOAD_INTERRUPT_REASON_USER_CANCELED && 1581 if (reason != DOWNLOAD_INTERRUPT_REASON_USER_CANCELED &&
1574 reason != DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) 1582 reason != DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) { 1623 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) {
1616 if (IsDangerous()) { 1624 if (IsDangerous()) {
1617 RecordDangerousDownloadDiscard( 1625 RecordDangerousDownloadDiscard(
1618 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED 1626 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED
1619 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION 1627 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION
1620 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, 1628 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN,
1621 GetDangerType(), GetTargetFilePath()); 1629 GetDangerType(), GetTargetFilePath());
1622 } 1630 }
1623 1631
1624 RecordDownloadCount(CANCELLED_COUNT); 1632 RecordDownloadCount(CANCELLED_COUNT);
1633 DCHECK_EQ(last_reason_, reason);
1625 TransitionTo(CANCELLED_INTERNAL); 1634 TransitionTo(CANCELLED_INTERNAL);
1626 return; 1635 return;
1627 } 1636 }
1628 1637
1629 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); 1638 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_);
1630 if (!GetWebContents()) 1639 if (!GetWebContents())
1631 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); 1640 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS);
1632 1641
1642 // TODO(asanka): This is not good. We can transition to interrupted from
1643 // target-pending, which is something we don't want to do. Perhaps we should
1644 // explicitly transition to target-resolved prior to switching to interrupted.
1645 DCHECK_EQ(last_reason_, reason);
1633 TransitionTo(INTERRUPTED_INTERNAL); 1646 TransitionTo(INTERRUPTED_INTERNAL);
1634 AutoResumeIfValid(); 1647 AutoResumeIfValid();
1635 } 1648 }
1636 1649
1637 void DownloadItemImpl::UpdateProgress(int64_t bytes_so_far, 1650 void DownloadItemImpl::UpdateProgress(int64_t bytes_so_far,
1638 int64_t bytes_per_sec) { 1651 int64_t bytes_per_sec) {
1639 received_bytes_ = bytes_so_far; 1652 received_bytes_ = bytes_so_far;
1640 bytes_per_sec_ = bytes_per_sec; 1653 bytes_per_sec_ = bytes_per_sec;
1641 1654
1642 // If we've received more data than we were expecting (bad server info?), 1655 // If we've received more data than we were expecting (bad server info?),
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 case COMPLETE_INTERNAL: 2083 case COMPLETE_INTERNAL:
2071 return "COMPLETE"; 2084 return "COMPLETE";
2072 case CANCELLED_INTERNAL: 2085 case CANCELLED_INTERNAL:
2073 return "CANCELLED"; 2086 return "CANCELLED";
2074 case INTERRUPTED_INTERNAL: 2087 case INTERRUPTED_INTERNAL:
2075 return "INTERRUPTED"; 2088 return "INTERRUPTED";
2076 case RESUMING_INTERNAL: 2089 case RESUMING_INTERNAL:
2077 return "RESUMING"; 2090 return "RESUMING";
2078 case MAX_DOWNLOAD_INTERNAL_STATE: 2091 case MAX_DOWNLOAD_INTERNAL_STATE:
2079 break; 2092 break;
2080 }; 2093 }
2081 NOTREACHED() << "Unknown download state " << state; 2094 NOTREACHED() << "Unknown download state " << state;
2082 return "unknown"; 2095 return "unknown";
2083 } 2096 }
2084 2097
2085 const char* DownloadItemImpl::DebugResumeModeString(ResumeMode mode) { 2098 const char* DownloadItemImpl::DebugResumeModeString(ResumeMode mode) {
2086 switch (mode) { 2099 switch (mode) {
2087 case RESUME_MODE_INVALID: 2100 case RESUME_MODE_INVALID:
2088 return "INVALID"; 2101 return "INVALID";
2089 case RESUME_MODE_IMMEDIATE_CONTINUE: 2102 case RESUME_MODE_IMMEDIATE_CONTINUE:
2090 return "IMMEDIATE_CONTINUE"; 2103 return "IMMEDIATE_CONTINUE";
2091 case RESUME_MODE_IMMEDIATE_RESTART: 2104 case RESUME_MODE_IMMEDIATE_RESTART:
2092 return "IMMEDIATE_RESTART"; 2105 return "IMMEDIATE_RESTART";
2093 case RESUME_MODE_USER_CONTINUE: 2106 case RESUME_MODE_USER_CONTINUE:
2094 return "USER_CONTINUE"; 2107 return "USER_CONTINUE";
2095 case RESUME_MODE_USER_RESTART: 2108 case RESUME_MODE_USER_RESTART:
2096 return "USER_RESTART"; 2109 return "USER_RESTART";
2097 } 2110 }
2098 NOTREACHED() << "Unknown resume mode " << mode; 2111 NOTREACHED() << "Unknown resume mode " << mode;
2099 return "unknown"; 2112 return "unknown";
2100 } 2113 }
2101 2114
2102 } // namespace content 2115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698