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 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | 1224 std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
1224 const DownloadCreateInfo& new_create_info) { | 1225 const DownloadCreateInfo& new_create_info) { |
1225 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1226 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1226 DCHECK(!download_file_.get()); | 1227 DCHECK(!download_file_.get()); |
1227 DVLOG(20) << __func__ << "() this=" << DebugString(true); | 1228 DVLOG(20) << __func__ << "() this=" << DebugString(true); |
1228 RecordDownloadCount(START_COUNT); | 1229 RecordDownloadCount(START_COUNT); |
1229 | 1230 |
1230 download_file_ = std::move(file); | 1231 download_file_ = std::move(file); |
1231 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle), | 1232 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle), |
1232 new_create_info); | 1233 new_create_info); |
1233 if (job_->UsesParallelRequests()) | 1234 if (job_->IsParallelizable()) { |
1234 RecordParallelDownloadCount(START_COUNT); | 1235 RecordParallelizableDownloadCount(START_COUNT, IsParallelDownloadEnabled()); |
| 1236 } |
1235 | 1237 |
1236 deferred_interrupt_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; | 1238 deferred_interrupt_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; |
1237 | 1239 |
1238 if (state_ == CANCELLED_INTERNAL) { | 1240 if (state_ == CANCELLED_INTERNAL) { |
1239 // The download was in the process of resuming when it was cancelled. Don't | 1241 // The download was in the process of resuming when it was cancelled. Don't |
1240 // proceed. | 1242 // proceed. |
1241 ReleaseDownloadFile(true); | 1243 ReleaseDownloadFile(true); |
1242 job_->Cancel(true); | 1244 job_->Cancel(true); |
1243 return; | 1245 return; |
1244 } | 1246 } |
(...skipping 30 matching lines...) Expand all Loading... |
1275 hash_.clear(); | 1277 hash_.clear(); |
1276 deferred_interrupt_reason_ = new_create_info.result; | 1278 deferred_interrupt_reason_ = new_create_info.result; |
1277 received_slices_.clear(); | 1279 received_slices_.clear(); |
1278 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); | 1280 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL); |
1279 DetermineDownloadTarget(); | 1281 DetermineDownloadTarget(); |
1280 return; | 1282 return; |
1281 } | 1283 } |
1282 | 1284 |
1283 if (state_ == INITIAL_INTERNAL) { | 1285 if (state_ == INITIAL_INTERNAL) { |
1284 RecordDownloadCount(NEW_DOWNLOAD_COUNT); | 1286 RecordDownloadCount(NEW_DOWNLOAD_COUNT); |
1285 if (job_->UsesParallelRequests()) | 1287 if (job_->IsParallelizable()) { |
1286 RecordParallelDownloadCount(NEW_DOWNLOAD_COUNT); | 1288 RecordParallelizableDownloadCount(NEW_DOWNLOAD_COUNT, |
| 1289 IsParallelDownloadEnabled()); |
| 1290 } |
1287 RecordDownloadMimeType(mime_type_); | 1291 RecordDownloadMimeType(mime_type_); |
1288 if (!GetBrowserContext()->IsOffTheRecord()) { | 1292 if (!GetBrowserContext()->IsOffTheRecord()) { |
1289 RecordDownloadCount(NEW_DOWNLOAD_COUNT_NORMAL_PROFILE); | 1293 RecordDownloadCount(NEW_DOWNLOAD_COUNT_NORMAL_PROFILE); |
1290 RecordDownloadMimeTypeForNormalProfile(mime_type_); | 1294 RecordDownloadMimeTypeForNormalProfile(mime_type_); |
1291 } | 1295 } |
1292 } | 1296 } |
1293 | 1297 |
1294 // Successful download start. | 1298 // Successful download start. |
1295 DCHECK(download_file_); | 1299 DCHECK(download_file_); |
1296 DCHECK(job_); | 1300 DCHECK(job_); |
1297 | 1301 |
1298 if (state_ == RESUMING_INTERNAL) | 1302 if (state_ == RESUMING_INTERNAL) |
1299 UpdateValidatorsOnResumption(new_create_info); | 1303 UpdateValidatorsOnResumption(new_create_info); |
1300 | 1304 |
1301 // If the download uses parallel requests, and choose not to create parallel | 1305 // If the download uses parallel requests, and choose not to create parallel |
1302 // request during resumption, clear the received_slices_ vector. | 1306 // request during resumption, clear the received_slices_ vector. |
1303 if (!job_->UsesParallelRequests() && !received_slices_.empty()) { | 1307 if (!IsParallelDownloadEnabled() && !received_slices_.empty()) { |
1304 received_bytes_ = | 1308 received_bytes_ = |
1305 GetMaxContiguousDataBlockSizeFromBeginning(received_slices_); | 1309 GetMaxContiguousDataBlockSizeFromBeginning(received_slices_); |
1306 received_slices_.clear(); | 1310 received_slices_.clear(); |
1307 } | 1311 } |
1308 | 1312 |
1309 TransitionTo(TARGET_PENDING_INTERNAL); | 1313 TransitionTo(TARGET_PENDING_INTERNAL); |
1310 | 1314 |
1311 job_->Start(); | 1315 job_->Start(); |
1312 } | 1316 } |
1313 | 1317 |
1314 void DownloadItemImpl::StartDownload() { | 1318 void DownloadItemImpl::StartDownload() { |
1315 BrowserThread::PostTask( | 1319 BrowserThread::PostTask( |
1316 BrowserThread::FILE, FROM_HERE, | 1320 BrowserThread::FILE, FROM_HERE, |
1317 base::Bind(&DownloadFile::Initialize, | 1321 base::Bind(&DownloadFile::Initialize, |
1318 // Safe because we control download file lifetime. | 1322 // Safe because we control download file lifetime. |
1319 base::Unretained(download_file_.get()), | 1323 base::Unretained(download_file_.get()), |
1320 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, | 1324 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, |
1321 weak_ptr_factory_.GetWeakPtr()), | 1325 weak_ptr_factory_.GetWeakPtr()), |
1322 base::Bind(&DownloadItemImpl::CancelRequestWithOffset, | 1326 base::Bind(&DownloadItemImpl::CancelRequestWithOffset, |
1323 weak_ptr_factory_.GetWeakPtr()), | 1327 weak_ptr_factory_.GetWeakPtr()), |
1324 received_slices_)); | 1328 received_slices_, job_ && job_->IsParallelizable())); |
1325 } | 1329 } |
1326 | 1330 |
1327 void DownloadItemImpl::OnDownloadFileInitialized( | 1331 void DownloadItemImpl::OnDownloadFileInitialized( |
1328 DownloadInterruptReason result) { | 1332 DownloadInterruptReason result) { |
1329 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1333 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1330 DCHECK(state_ == TARGET_PENDING_INTERNAL || | 1334 DCHECK(state_ == TARGET_PENDING_INTERNAL || |
1331 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) | 1335 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) |
1332 << "Unexpected state: " << DebugDownloadStateString(state_); | 1336 << "Unexpected state: " << DebugDownloadStateString(state_); |
1333 | 1337 |
1334 DVLOG(20) << __func__ | 1338 DVLOG(20) << __func__ |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 | 1626 |
1623 DVLOG(20) << __func__ << "() " << DebugString(false); | 1627 DVLOG(20) << __func__ << "() " << DebugString(false); |
1624 | 1628 |
1625 DCHECK(all_data_saved_); | 1629 DCHECK(all_data_saved_); |
1626 end_time_ = base::Time::Now(); | 1630 end_time_ = base::Time::Now(); |
1627 TransitionTo(COMPLETE_INTERNAL); | 1631 TransitionTo(COMPLETE_INTERNAL); |
1628 RecordDownloadCompleted(start_tick_, received_bytes_); | 1632 RecordDownloadCompleted(start_tick_, received_bytes_); |
1629 if (!GetBrowserContext()->IsOffTheRecord()) { | 1633 if (!GetBrowserContext()->IsOffTheRecord()) { |
1630 RecordDownloadCount(COMPLETED_COUNT_NORMAL_PROFILE); | 1634 RecordDownloadCount(COMPLETED_COUNT_NORMAL_PROFILE); |
1631 } | 1635 } |
1632 if (job_ && job_->UsesParallelRequests()) | 1636 if (job_ && job_->IsParallelizable()) { |
1633 RecordParallelDownloadCount(COMPLETED_COUNT); | 1637 RecordParallelizableDownloadCount(COMPLETED_COUNT, |
| 1638 IsParallelDownloadEnabled()); |
| 1639 } |
1634 | 1640 |
1635 if (auto_opened_) { | 1641 if (auto_opened_) { |
1636 // If it was already handled by the delegate, do nothing. | 1642 // If it was already handled by the delegate, do nothing. |
1637 } else if (GetOpenWhenComplete() || | 1643 } else if (GetOpenWhenComplete() || |
1638 ShouldOpenFileBasedOnExtension() || | 1644 ShouldOpenFileBasedOnExtension() || |
1639 IsTemporary()) { | 1645 IsTemporary()) { |
1640 // If the download is temporary, like in drag-and-drop, do not open it but | 1646 // If the download is temporary, like in drag-and-drop, do not open it but |
1641 // we still need to set it auto-opened so that it can be removed from the | 1647 // we still need to set it auto-opened so that it can be removed from the |
1642 // download shelf. | 1648 // download shelf. |
1643 if (!IsTemporary()) | 1649 if (!IsTemporary()) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1771 if (IsCancellation(reason)) { | 1777 if (IsCancellation(reason)) { |
1772 if (IsDangerous()) { | 1778 if (IsDangerous()) { |
1773 RecordDangerousDownloadDiscard( | 1779 RecordDangerousDownloadDiscard( |
1774 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED | 1780 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED |
1775 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION | 1781 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION |
1776 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, | 1782 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, |
1777 GetDangerType(), GetTargetFilePath()); | 1783 GetDangerType(), GetTargetFilePath()); |
1778 } | 1784 } |
1779 | 1785 |
1780 RecordDownloadCount(CANCELLED_COUNT); | 1786 RecordDownloadCount(CANCELLED_COUNT); |
1781 if (job_ && job_->UsesParallelRequests()) | 1787 if (job_ && job_->IsParallelizable()) { |
1782 RecordParallelDownloadCount(CANCELLED_COUNT); | 1788 RecordParallelizableDownloadCount(CANCELLED_COUNT, |
| 1789 IsParallelDownloadEnabled()); |
| 1790 } |
1783 DCHECK_EQ(last_reason_, reason); | 1791 DCHECK_EQ(last_reason_, reason); |
1784 TransitionTo(CANCELLED_INTERNAL); | 1792 TransitionTo(CANCELLED_INTERNAL); |
1785 return; | 1793 return; |
1786 } | 1794 } |
1787 | 1795 |
1788 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, | 1796 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, |
1789 job_ && job_->UsesParallelRequests()); | 1797 job_ && job_->IsParallelizable(), |
| 1798 IsParallelDownloadEnabled()); |
1790 if (!GetWebContents()) | 1799 if (!GetWebContents()) |
1791 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); | 1800 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); |
1792 | 1801 |
1793 // TODO(asanka): This is not good. We can transition to interrupted from | 1802 // TODO(asanka): This is not good. We can transition to interrupted from |
1794 // target-pending, which is something we don't want to do. Perhaps we should | 1803 // target-pending, which is something we don't want to do. Perhaps we should |
1795 // explicitly transition to target-resolved prior to switching to interrupted. | 1804 // explicitly transition to target-resolved prior to switching to interrupted. |
1796 DCHECK_EQ(last_reason_, reason); | 1805 DCHECK_EQ(last_reason_, reason); |
1797 TransitionTo(INTERRUPTED_INTERNAL); | 1806 TransitionTo(INTERRUPTED_INTERNAL); |
1798 AutoResumeIfValid(); | 1807 AutoResumeIfValid(); |
1799 } | 1808 } |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2277 case RESUME_MODE_USER_CONTINUE: | 2286 case RESUME_MODE_USER_CONTINUE: |
2278 return "USER_CONTINUE"; | 2287 return "USER_CONTINUE"; |
2279 case RESUME_MODE_USER_RESTART: | 2288 case RESUME_MODE_USER_RESTART: |
2280 return "USER_RESTART"; | 2289 return "USER_RESTART"; |
2281 } | 2290 } |
2282 NOTREACHED() << "Unknown resume mode " << mode; | 2291 NOTREACHED() << "Unknown resume mode " << mode; |
2283 return "unknown"; | 2292 return "unknown"; |
2284 } | 2293 } |
2285 | 2294 |
2286 } // namespace content | 2295 } // namespace content |
OLD | NEW |