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

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

Issue 2722503006: Add slice information to DownloadDestinationObserver::DestinationUpdate(). (Closed)
Patch Set: Created 3 years, 9 months 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 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 total_bytes_ = total_bytes; 1036 total_bytes_ = total_bytes;
1037 } 1037 }
1038 1038
1039 void DownloadItemImpl::OnAllDataSaved( 1039 void DownloadItemImpl::OnAllDataSaved(
1040 int64_t total_bytes, 1040 int64_t total_bytes,
1041 std::unique_ptr<crypto::SecureHash> hash_state) { 1041 std::unique_ptr<crypto::SecureHash> hash_state) {
1042 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1042 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1043 DCHECK(!all_data_saved_); 1043 DCHECK(!all_data_saved_);
1044 all_data_saved_ = true; 1044 all_data_saved_ = true;
1045 SetTotalBytes(total_bytes); 1045 SetTotalBytes(total_bytes);
1046 UpdateProgress(total_bytes, 0); 1046 UpdateProgress(total_bytes, 0, std::vector<DownloadItem::ReceivedSlice>());
1047 SetHashState(std::move(hash_state)); 1047 SetHashState(std::move(hash_state));
1048 hash_state_.reset(); // No need to retain hash_state_ since we are done with 1048 hash_state_.reset(); // No need to retain hash_state_ since we are done with
1049 // the download and don't expect to receive any more 1049 // the download and don't expect to receive any more
1050 // data. 1050 // data.
1051 1051
1052 DVLOG(20) << __func__ << "() download=" << DebugString(true); 1052 DVLOG(20) << __func__ << "() download=" << DebugString(true);
1053 UpdateObservers(); 1053 UpdateObservers();
1054 } 1054 }
1055 1055
1056 void DownloadItemImpl::MarkAsComplete() { 1056 void DownloadItemImpl::MarkAsComplete() {
1057 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1057 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1058 1058
1059 DCHECK(all_data_saved_); 1059 DCHECK(all_data_saved_);
1060 end_time_ = base::Time::Now(); 1060 end_time_ = base::Time::Now();
1061 TransitionTo(COMPLETE_INTERNAL); 1061 TransitionTo(COMPLETE_INTERNAL);
1062 UpdateObservers(); 1062 UpdateObservers();
1063 } 1063 }
1064 1064
1065 void DownloadItemImpl::DestinationUpdate(int64_t bytes_so_far, 1065 void DownloadItemImpl::DestinationUpdate(
1066 int64_t bytes_per_sec) { 1066 int64_t bytes_so_far,
1067 int64_t bytes_per_sec,
1068 const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
1067 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1069 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1068 // If the download is in any other state we don't expect any 1070 // If the download is in any other state we don't expect any
1069 // DownloadDestinationObserver callbacks. An interruption or a cancellation 1071 // DownloadDestinationObserver callbacks. An interruption or a cancellation
1070 // results in a call to ReleaseDownloadFile which invalidates the weak 1072 // results in a call to ReleaseDownloadFile which invalidates the weak
1071 // reference held by the DownloadFile and hence cuts off any pending 1073 // reference held by the DownloadFile and hence cuts off any pending
1072 // callbacks. 1074 // callbacks.
1073 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL); 1075 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL);
1074 1076
1075 // There must be no pending destination_error_. 1077 // There must be no pending destination_error_.
1076 DCHECK_EQ(destination_error_, DOWNLOAD_INTERRUPT_REASON_NONE); 1078 DCHECK_EQ(destination_error_, DOWNLOAD_INTERRUPT_REASON_NONE);
1077 1079
1078 DVLOG(20) << __func__ << "() so_far=" << bytes_so_far 1080 DVLOG(20) << __func__ << "() so_far=" << bytes_so_far
1079 << " per_sec=" << bytes_per_sec 1081 << " per_sec=" << bytes_per_sec
1080 << " download=" << DebugString(true); 1082 << " download=" << DebugString(true);
1081 1083
1082 UpdateProgress(bytes_so_far, bytes_per_sec); 1084 UpdateProgress(bytes_so_far, bytes_per_sec, received_slices);
1083 if (net_log_.IsCapturing()) { 1085 if (net_log_.IsCapturing()) {
1084 net_log_.AddEvent( 1086 net_log_.AddEvent(
1085 net::NetLogEventType::DOWNLOAD_ITEM_UPDATED, 1087 net::NetLogEventType::DOWNLOAD_ITEM_UPDATED,
1086 net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); 1088 net::NetLog::Int64Callback("bytes_so_far", received_bytes_));
1087 } 1089 }
1088 1090
1089 UpdateObservers(); 1091 UpdateObservers();
1090 } 1092 }
1091 1093
1092 void DownloadItemImpl::DestinationError( 1094 void DownloadItemImpl::DestinationError(
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 new_create_info.save_info->hash_state 1219 new_create_info.save_info->hash_state
1218 ? new_create_info.save_info->hash_state->Clone() 1220 ? new_create_info.save_info->hash_state->Clone()
1219 : nullptr; 1221 : nullptr;
1220 1222
1221 // Interrupted downloads also need a target path. 1223 // Interrupted downloads also need a target path.
1222 if (target_path_.empty()) { 1224 if (target_path_.empty()) {
1223 received_bytes_ = offset; 1225 received_bytes_ = offset;
1224 hash_state_ = std::move(hash_state); 1226 hash_state_ = std::move(hash_state);
1225 hash_.clear(); 1227 hash_.clear();
1226 destination_error_ = new_create_info.result; 1228 destination_error_ = new_create_info.result;
1229 received_slices_.clear();
1227 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); 1230 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL);
1228 DetermineDownloadTarget(); 1231 DetermineDownloadTarget();
1229 return; 1232 return;
1230 } 1233 }
1231 1234
1232 // Otherwise, this was a resumption attempt which ended with an 1235 // Otherwise, this was a resumption attempt which ended with an
1233 // interruption. Continue with current target path. 1236 // interruption. Continue with current target path.
1234 TransitionTo(TARGET_RESOLVED_INTERNAL); 1237 TransitionTo(TARGET_RESOLVED_INTERNAL);
1235 InterruptWithPartialState( 1238 InterruptWithPartialState(
1236 offset, std::move(hash_state), new_create_info.result); 1239 offset, std::move(hash_state), new_create_info.result);
(...skipping 26 matching lines...) Expand all
1263 DVLOG(20) << __func__ 1266 DVLOG(20) << __func__
1264 << "() result:" << DownloadInterruptReasonToString(result); 1267 << "() result:" << DownloadInterruptReasonToString(result);
1265 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { 1268 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) {
1266 // Whoops. That didn't work. Proceed as an interrupted download, but reset 1269 // Whoops. That didn't work. Proceed as an interrupted download, but reset
1267 // the partial state. Currently, the partial stub cannot be recovered if the 1270 // the partial state. Currently, the partial stub cannot be recovered if the
1268 // download file initialization fails. 1271 // download file initialization fails.
1269 received_bytes_ = 0; 1272 received_bytes_ = 0;
1270 hash_state_.reset(); 1273 hash_state_.reset();
1271 hash_.clear(); 1274 hash_.clear();
1272 destination_error_ = result; 1275 destination_error_ = result;
1276 received_slices_.clear();
1273 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); 1277 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL);
1274 } 1278 }
1275 1279
1276 DetermineDownloadTarget(); 1280 DetermineDownloadTarget();
1277 } 1281 }
1278 1282
1279 void DownloadItemImpl::DetermineDownloadTarget() { 1283 void DownloadItemImpl::DetermineDownloadTarget() {
1280 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1284 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1281 DVLOG(20) << __func__ << "() " << DebugString(true); 1285 DVLOG(20) << __func__ << "() " << DebugString(true);
1282 1286
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 // after we download all the data, and b) if there were, that would probably 1635 // after we download all the data, and b) if there were, that would probably
1632 // simply result in a null range request, which would generate a 1636 // simply result in a null range request, which would generate a
1633 // DestinationCompleted() notification from the DownloadFile, which would 1637 // DestinationCompleted() notification from the DownloadFile, which would
1634 // behave properly with setting all_data_saved_ to false here. 1638 // behave properly with setting all_data_saved_ to false here.
1635 all_data_saved_ = false; 1639 all_data_saved_ = false;
1636 1640
1637 if (current_path_.empty()) { 1641 if (current_path_.empty()) {
1638 hash_state_.reset(); 1642 hash_state_.reset();
1639 hash_.clear(); 1643 hash_.clear();
1640 received_bytes_ = 0; 1644 received_bytes_ = 0;
1645 received_slices_.clear();
1641 } else { 1646 } else {
1642 UpdateProgress(bytes_so_far, 0); 1647 UpdateProgress(bytes_so_far, 0, std::vector<DownloadItem::ReceivedSlice>());
1643 SetHashState(std::move(hash_state)); 1648 SetHashState(std::move(hash_state));
1644 } 1649 }
1645 1650
1646 if (request_handle_) 1651 if (request_handle_)
1647 request_handle_->CancelRequest(); 1652 request_handle_->CancelRequest();
1648 1653
1649 if (reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED || 1654 if (reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED ||
1650 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) { 1655 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) {
1651 if (IsDangerous()) { 1656 if (IsDangerous()) {
1652 RecordDangerousDownloadDiscard( 1657 RecordDangerousDownloadDiscard(
1653 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED 1658 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED
1654 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION 1659 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION
1655 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, 1660 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN,
1656 GetDangerType(), GetTargetFilePath()); 1661 GetDangerType(), GetTargetFilePath());
1657 } 1662 }
1658 1663
1659 RecordDownloadCount(CANCELLED_COUNT); 1664 RecordDownloadCount(CANCELLED_COUNT);
1660 TransitionTo(CANCELLED_INTERNAL); 1665 TransitionTo(CANCELLED_INTERNAL);
1661 return; 1666 return;
1662 } 1667 }
1663 1668
1664 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); 1669 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_);
1665 if (!GetWebContents()) 1670 if (!GetWebContents())
1666 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); 1671 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS);
1667 1672
1668 TransitionTo(INTERRUPTED_INTERNAL); 1673 TransitionTo(INTERRUPTED_INTERNAL);
1669 AutoResumeIfValid(); 1674 AutoResumeIfValid();
1670 } 1675 }
1671 1676
1672 void DownloadItemImpl::UpdateProgress(int64_t bytes_so_far, 1677 void DownloadItemImpl::UpdateProgress(
1673 int64_t bytes_per_sec) { 1678 int64_t bytes_so_far,
1679 int64_t bytes_per_sec,
1680 const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
1674 received_bytes_ = bytes_so_far; 1681 received_bytes_ = bytes_so_far;
1675 bytes_per_sec_ = bytes_per_sec; 1682 bytes_per_sec_ = bytes_per_sec;
1676 1683
1677 // If we've received more data than we were expecting (bad server info?), 1684 // If we've received more data than we were expecting (bad server info?),
1678 // revert to 'unknown size mode'. 1685 // revert to 'unknown size mode'.
1679 if (received_bytes_ > total_bytes_) 1686 if (received_bytes_ > total_bytes_)
1680 total_bytes_ = 0; 1687 total_bytes_ = 0;
1688
1689 received_slices_ = received_slices;
1681 } 1690 }
1682 1691
1683 void DownloadItemImpl::SetHashState( 1692 void DownloadItemImpl::SetHashState(
1684 std::unique_ptr<crypto::SecureHash> hash_state) { 1693 std::unique_ptr<crypto::SecureHash> hash_state) {
1685 hash_state_ = std::move(hash_state); 1694 hash_state_ = std::move(hash_state);
1686 if (!hash_state_) { 1695 if (!hash_state_) {
1687 hash_.clear(); 1696 hash_.clear();
1688 return; 1697 return;
1689 } 1698 }
1690 1699
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 1925
1917 // Reset the appropriate state if restarting. 1926 // Reset the appropriate state if restarting.
1918 ResumeMode mode = GetResumeMode(); 1927 ResumeMode mode = GetResumeMode();
1919 if (mode == RESUME_MODE_IMMEDIATE_RESTART || 1928 if (mode == RESUME_MODE_IMMEDIATE_RESTART ||
1920 mode == RESUME_MODE_USER_RESTART) { 1929 mode == RESUME_MODE_USER_RESTART) {
1921 received_bytes_ = 0; 1930 received_bytes_ = 0;
1922 last_modified_time_.clear(); 1931 last_modified_time_.clear();
1923 etag_.clear(); 1932 etag_.clear();
1924 hash_.clear(); 1933 hash_.clear();
1925 hash_state_.reset(); 1934 hash_state_.reset();
1935 received_slices_.clear();
1926 } 1936 }
1927 1937
1928 StoragePartition* storage_partition = 1938 StoragePartition* storage_partition =
1929 BrowserContext::GetStoragePartitionForSite(GetBrowserContext(), 1939 BrowserContext::GetStoragePartitionForSite(GetBrowserContext(),
1930 site_url_); 1940 site_url_);
1931 1941
1932 // Avoid using the WebContents even if it's still around. Resumption requests 1942 // Avoid using the WebContents even if it's still around. Resumption requests
1933 // are consistently routed through the no-renderer code paths so that the 1943 // are consistently routed through the no-renderer code paths so that the
1934 // request will not be dropped if the WebContents (and by extension, the 1944 // request will not be dropped if the WebContents (and by extension, the
1935 // associated renderer) goes away before a response is received. 1945 // associated renderer) goes away before a response is received.
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 case RESUME_MODE_USER_CONTINUE: 2138 case RESUME_MODE_USER_CONTINUE:
2129 return "USER_CONTINUE"; 2139 return "USER_CONTINUE";
2130 case RESUME_MODE_USER_RESTART: 2140 case RESUME_MODE_USER_RESTART:
2131 return "USER_RESTART"; 2141 return "USER_RESTART";
2132 } 2142 }
2133 NOTREACHED() << "Unknown resume mode " << mode; 2143 NOTREACHED() << "Unknown resume mode " << mode;
2134 return "unknown"; 2144 return "unknown";
2135 } 2145 }
2136 2146
2137 } // namespace content 2147 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698