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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 url_chain_(1, url), | 264 url_chain_(1, url), |
265 mime_type_(mime_type), | 265 mime_type_(mime_type), |
266 original_mime_type_(mime_type), | 266 original_mime_type_(mime_type), |
267 start_tick_(base::TimeTicks::Now()), | 267 start_tick_(base::TimeTicks::Now()), |
268 state_(IN_PROGRESS_INTERNAL), | 268 state_(IN_PROGRESS_INTERNAL), |
269 start_time_(base::Time::Now()), | 269 start_time_(base::Time::Now()), |
270 delegate_(delegate), | 270 delegate_(delegate), |
271 current_path_(path), | 271 current_path_(path), |
272 net_log_(net_log), | 272 net_log_(net_log), |
273 weak_ptr_factory_(this) { | 273 weak_ptr_factory_(this) { |
274 job_ = base::MakeUnique<DownloadJobImpl>(this, std::move(request_handle)); | 274 job_ = |
| 275 base::MakeUnique<DownloadJobImpl>(this, std::move(request_handle), false); |
275 delegate_->Attach(); | 276 delegate_->Attach(); |
276 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); | 277 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); |
277 } | 278 } |
278 | 279 |
279 DownloadItemImpl::~DownloadItemImpl() { | 280 DownloadItemImpl::~DownloadItemImpl() { |
280 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 281 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
281 | 282 |
282 // Should always have been nuked before now, at worst in | 283 // Should always have been nuked before now, at worst in |
283 // DownloadManager shutdown. | 284 // DownloadManager shutdown. |
284 DCHECK(!download_file_.get()); | 285 DCHECK(!download_file_.get()); |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | 1218 std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
1218 const DownloadCreateInfo& new_create_info) { | 1219 const DownloadCreateInfo& new_create_info) { |
1219 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1220 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1220 DCHECK(!download_file_.get()); | 1221 DCHECK(!download_file_.get()); |
1221 DVLOG(20) << __func__ << "() this=" << DebugString(true); | 1222 DVLOG(20) << __func__ << "() this=" << DebugString(true); |
1222 RecordDownloadCount(START_COUNT); | 1223 RecordDownloadCount(START_COUNT); |
1223 | 1224 |
1224 download_file_ = std::move(file); | 1225 download_file_ = std::move(file); |
1225 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle), | 1226 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle), |
1226 new_create_info); | 1227 new_create_info); |
1227 if (job_->UsesParallelRequests()) | 1228 if (job_->IsParallelizable()) { |
1228 RecordParallelDownloadCount(START_COUNT); | 1229 RecordParallelizableDownloadCount(START_COUNT, |
| 1230 job_->UsesParallelRequests()); |
| 1231 } |
1229 | 1232 |
1230 deferred_interrupt_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; | 1233 deferred_interrupt_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; |
1231 | 1234 |
1232 if (state_ == CANCELLED_INTERNAL) { | 1235 if (state_ == CANCELLED_INTERNAL) { |
1233 // The download was in the process of resuming when it was cancelled. Don't | 1236 // The download was in the process of resuming when it was cancelled. Don't |
1234 // proceed. | 1237 // proceed. |
1235 ReleaseDownloadFile(true); | 1238 ReleaseDownloadFile(true); |
1236 job_->Cancel(true); | 1239 job_->Cancel(true); |
1237 return; | 1240 return; |
1238 } | 1241 } |
(...skipping 30 matching lines...) Expand all Loading... |
1269 hash_.clear(); | 1272 hash_.clear(); |
1270 deferred_interrupt_reason_ = new_create_info.result; | 1273 deferred_interrupt_reason_ = new_create_info.result; |
1271 received_slices_.clear(); | 1274 received_slices_.clear(); |
1272 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); | 1275 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); |
1273 DetermineDownloadTarget(); | 1276 DetermineDownloadTarget(); |
1274 return; | 1277 return; |
1275 } | 1278 } |
1276 | 1279 |
1277 if (state_ == INITIAL_INTERNAL) { | 1280 if (state_ == INITIAL_INTERNAL) { |
1278 RecordDownloadCount(NEW_DOWNLOAD_COUNT); | 1281 RecordDownloadCount(NEW_DOWNLOAD_COUNT); |
1279 if (job_->UsesParallelRequests()) | 1282 if (job_->IsParallelizable()) |
1280 RecordParallelDownloadCount(NEW_DOWNLOAD_COUNT); | 1283 RecordParallelizableDownloadCount(NEW_DOWNLOAD_COUNT, |
| 1284 job_->UsesParallelRequests()); |
1281 RecordDownloadMimeType(mime_type_); | 1285 RecordDownloadMimeType(mime_type_); |
1282 if (!GetBrowserContext()->IsOffTheRecord()) { | 1286 if (!GetBrowserContext()->IsOffTheRecord()) { |
1283 RecordDownloadCount(NEW_DOWNLOAD_COUNT_NORMAL_PROFILE); | 1287 RecordDownloadCount(NEW_DOWNLOAD_COUNT_NORMAL_PROFILE); |
1284 RecordDownloadMimeTypeForNormalProfile(mime_type_); | 1288 RecordDownloadMimeTypeForNormalProfile(mime_type_); |
1285 } | 1289 } |
1286 } | 1290 } |
1287 | 1291 |
1288 // Successful download start. | 1292 // Successful download start. |
1289 DCHECK(download_file_); | 1293 DCHECK(download_file_); |
1290 DCHECK(job_); | 1294 DCHECK(job_); |
1291 | 1295 |
1292 if (state_ == RESUMING_INTERNAL) | 1296 if (state_ == RESUMING_INTERNAL) |
1293 UpdateValidatorsOnResumption(new_create_info); | 1297 UpdateValidatorsOnResumption(new_create_info); |
1294 | 1298 |
1295 TransitionTo(TARGET_PENDING_INTERNAL); | 1299 TransitionTo(TARGET_PENDING_INTERNAL); |
1296 | 1300 |
1297 job_->Start(); | 1301 job_->Start(); |
1298 } | 1302 } |
1299 | 1303 |
1300 void DownloadItemImpl::StartDownload() { | 1304 void DownloadItemImpl::StartDownload() { |
1301 BrowserThread::PostTask( | 1305 BrowserThread::PostTask( |
1302 BrowserThread::FILE, FROM_HERE, | 1306 BrowserThread::FILE, FROM_HERE, |
1303 base::Bind(&DownloadFile::Initialize, | 1307 base::Bind(&DownloadFile::Initialize, |
1304 // Safe because we control download file lifetime. | 1308 // Safe because we control download file lifetime. |
1305 base::Unretained(download_file_.get()), | 1309 base::Unretained(download_file_.get()), |
1306 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, | 1310 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, |
1307 weak_ptr_factory_.GetWeakPtr()), | 1311 weak_ptr_factory_.GetWeakPtr()), |
1308 received_slices_)); | 1312 received_slices_, job_ && job_->IsParallelizable())); |
1309 } | 1313 } |
1310 | 1314 |
1311 void DownloadItemImpl::OnDownloadFileInitialized( | 1315 void DownloadItemImpl::OnDownloadFileInitialized( |
1312 DownloadInterruptReason result) { | 1316 DownloadInterruptReason result) { |
1313 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1317 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1314 DCHECK(state_ == TARGET_PENDING_INTERNAL || | 1318 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
1315 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) | 1319 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) |
1316 << "Unexpected state: " << DebugDownloadStateString(state_); | 1320 << "Unexpected state: " << DebugDownloadStateString(state_); |
1317 | 1321 |
1318 DVLOG(20) << __func__ | 1322 DVLOG(20) << __func__ |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 | 1605 |
1602 DVLOG(20) << __func__ << "() " << DebugString(false); | 1606 DVLOG(20) << __func__ << "() " << DebugString(false); |
1603 | 1607 |
1604 DCHECK(all_data_saved_); | 1608 DCHECK(all_data_saved_); |
1605 end_time_ = base::Time::Now(); | 1609 end_time_ = base::Time::Now(); |
1606 TransitionTo(COMPLETE_INTERNAL); | 1610 TransitionTo(COMPLETE_INTERNAL); |
1607 RecordDownloadCompleted(start_tick_, received_bytes_); | 1611 RecordDownloadCompleted(start_tick_, received_bytes_); |
1608 if (!GetBrowserContext()->IsOffTheRecord()) { | 1612 if (!GetBrowserContext()->IsOffTheRecord()) { |
1609 RecordDownloadCount(COMPLETED_COUNT_NORMAL_PROFILE); | 1613 RecordDownloadCount(COMPLETED_COUNT_NORMAL_PROFILE); |
1610 } | 1614 } |
1611 if (job_ && job_->UsesParallelRequests()) | 1615 if (job_ && job_->IsParallelizable()) { |
1612 RecordParallelDownloadCount(COMPLETED_COUNT); | 1616 RecordParallelizableDownloadCount(COMPLETED_COUNT, |
| 1617 job_->UsesParallelRequests()); |
| 1618 } |
1613 | 1619 |
1614 if (auto_opened_) { | 1620 if (auto_opened_) { |
1615 // If it was already handled by the delegate, do nothing. | 1621 // If it was already handled by the delegate, do nothing. |
1616 } else if (GetOpenWhenComplete() || | 1622 } else if (GetOpenWhenComplete() || |
1617 ShouldOpenFileBasedOnExtension() || | 1623 ShouldOpenFileBasedOnExtension() || |
1618 IsTemporary()) { | 1624 IsTemporary()) { |
1619 // If the download is temporary, like in drag-and-drop, do not open it but | 1625 // If the download is temporary, like in drag-and-drop, do not open it but |
1620 // we still need to set it auto-opened so that it can be removed from the | 1626 // we still need to set it auto-opened so that it can be removed from the |
1621 // download shelf. | 1627 // download shelf. |
1622 if (!IsTemporary()) | 1628 if (!IsTemporary()) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 if (IsCancellation(reason)) { | 1756 if (IsCancellation(reason)) { |
1751 if (IsDangerous()) { | 1757 if (IsDangerous()) { |
1752 RecordDangerousDownloadDiscard( | 1758 RecordDangerousDownloadDiscard( |
1753 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED | 1759 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED |
1754 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION | 1760 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION |
1755 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, | 1761 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, |
1756 GetDangerType(), GetTargetFilePath()); | 1762 GetDangerType(), GetTargetFilePath()); |
1757 } | 1763 } |
1758 | 1764 |
1759 RecordDownloadCount(CANCELLED_COUNT); | 1765 RecordDownloadCount(CANCELLED_COUNT); |
1760 if (job_ && job_->UsesParallelRequests()) | 1766 if (job_ && job_->IsParallelizable()) { |
1761 RecordParallelDownloadCount(CANCELLED_COUNT); | 1767 RecordParallelizableDownloadCount(CANCELLED_COUNT, |
| 1768 job_->UsesParallelRequests()); |
| 1769 } |
1762 DCHECK_EQ(last_reason_, reason); | 1770 DCHECK_EQ(last_reason_, reason); |
1763 TransitionTo(CANCELLED_INTERNAL); | 1771 TransitionTo(CANCELLED_INTERNAL); |
1764 return; | 1772 return; |
1765 } | 1773 } |
1766 | 1774 |
1767 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, | 1775 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, |
| 1776 job_ && job_->IsParallelizable(), |
1768 job_ && job_->UsesParallelRequests()); | 1777 job_ && job_->UsesParallelRequests()); |
1769 if (!GetWebContents()) | 1778 if (!GetWebContents()) |
1770 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); | 1779 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); |
1771 | 1780 |
1772 // TODO(asanka): This is not good. We can transition to interrupted from | 1781 // TODO(asanka): This is not good. We can transition to interrupted from |
1773 // target-pending, which is something we don't want to do. Perhaps we should | 1782 // target-pending, which is something we don't want to do. Perhaps we should |
1774 // explicitly transition to target-resolved prior to switching to interrupted. | 1783 // explicitly transition to target-resolved prior to switching to interrupted. |
1775 DCHECK_EQ(last_reason_, reason); | 1784 DCHECK_EQ(last_reason_, reason); |
1776 TransitionTo(INTERRUPTED_INTERNAL); | 1785 TransitionTo(INTERRUPTED_INTERNAL); |
1777 AutoResumeIfValid(); | 1786 AutoResumeIfValid(); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2256 case RESUME_MODE_USER_CONTINUE: | 2265 case RESUME_MODE_USER_CONTINUE: |
2257 return "USER_CONTINUE"; | 2266 return "USER_CONTINUE"; |
2258 case RESUME_MODE_USER_RESTART: | 2267 case RESUME_MODE_USER_RESTART: |
2259 return "USER_RESTART"; | 2268 return "USER_RESTART"; |
2260 } | 2269 } |
2261 NOTREACHED() << "Unknown resume mode " << mode; | 2270 NOTREACHED() << "Unknown resume mode " << mode; |
2262 return "unknown"; | 2271 return "unknown"; |
2263 } | 2272 } |
2264 | 2273 |
2265 } // namespace content | 2274 } // namespace content |
OLD | NEW |