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

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

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

Powered by Google App Engine
This is Rietveld 408576698