| 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 | 1621 |
| 1618 DVLOG(20) << __func__ << "() " << DebugString(false); | 1622 DVLOG(20) << __func__ << "() " << DebugString(false); |
| 1619 | 1623 |
| 1620 DCHECK(all_data_saved_); | 1624 DCHECK(all_data_saved_); |
| 1621 end_time_ = base::Time::Now(); | 1625 end_time_ = base::Time::Now(); |
| 1622 TransitionTo(COMPLETE_INTERNAL); | 1626 TransitionTo(COMPLETE_INTERNAL); |
| 1623 RecordDownloadCompleted(start_tick_, received_bytes_); | 1627 RecordDownloadCompleted(start_tick_, received_bytes_); |
| 1624 if (!GetBrowserContext()->IsOffTheRecord()) { | 1628 if (!GetBrowserContext()->IsOffTheRecord()) { |
| 1625 RecordDownloadCount(COMPLETED_COUNT_NORMAL_PROFILE); | 1629 RecordDownloadCount(COMPLETED_COUNT_NORMAL_PROFILE); |
| 1626 } | 1630 } |
| 1627 if (job_ && job_->UsesParallelRequests()) | 1631 if (job_ && job_->IsParallelizable()) { |
| 1628 RecordParallelDownloadCount(COMPLETED_COUNT); | 1632 RecordParallelizableDownloadCount(COMPLETED_COUNT, |
| 1633 IsParallelDownloadEnabled()); |
| 1634 } |
| 1629 | 1635 |
| 1630 if (auto_opened_) { | 1636 if (auto_opened_) { |
| 1631 // If it was already handled by the delegate, do nothing. | 1637 // If it was already handled by the delegate, do nothing. |
| 1632 } else if (GetOpenWhenComplete() || | 1638 } else if (GetOpenWhenComplete() || |
| 1633 ShouldOpenFileBasedOnExtension() || | 1639 ShouldOpenFileBasedOnExtension() || |
| 1634 IsTemporary()) { | 1640 IsTemporary()) { |
| 1635 // If the download is temporary, like in drag-and-drop, do not open it but | 1641 // If the download is temporary, like in drag-and-drop, do not open it but |
| 1636 // we still need to set it auto-opened so that it can be removed from the | 1642 // we still need to set it auto-opened so that it can be removed from the |
| 1637 // download shelf. | 1643 // download shelf. |
| 1638 if (!IsTemporary()) | 1644 if (!IsTemporary()) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 if (IsCancellation(reason)) { | 1772 if (IsCancellation(reason)) { |
| 1767 if (IsDangerous()) { | 1773 if (IsDangerous()) { |
| 1768 RecordDangerousDownloadDiscard( | 1774 RecordDangerousDownloadDiscard( |
| 1769 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED | 1775 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED |
| 1770 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION | 1776 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION |
| 1771 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, | 1777 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, |
| 1772 GetDangerType(), GetTargetFilePath()); | 1778 GetDangerType(), GetTargetFilePath()); |
| 1773 } | 1779 } |
| 1774 | 1780 |
| 1775 RecordDownloadCount(CANCELLED_COUNT); | 1781 RecordDownloadCount(CANCELLED_COUNT); |
| 1776 if (job_ && job_->UsesParallelRequests()) | 1782 if (job_ && job_->IsParallelizable()) { |
| 1777 RecordParallelDownloadCount(CANCELLED_COUNT); | 1783 RecordParallelizableDownloadCount(CANCELLED_COUNT, |
| 1784 IsParallelDownloadEnabled()); |
| 1785 } |
| 1778 DCHECK_EQ(last_reason_, reason); | 1786 DCHECK_EQ(last_reason_, reason); |
| 1779 TransitionTo(CANCELLED_INTERNAL); | 1787 TransitionTo(CANCELLED_INTERNAL); |
| 1780 return; | 1788 return; |
| 1781 } | 1789 } |
| 1782 | 1790 |
| 1783 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, | 1791 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_, |
| 1784 job_ && job_->UsesParallelRequests()); | 1792 job_ && job_->IsParallelizable(), |
| 1793 IsParallelDownloadEnabled()); |
| 1785 if (!GetWebContents()) | 1794 if (!GetWebContents()) |
| 1786 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); | 1795 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); |
| 1787 | 1796 |
| 1788 // TODO(asanka): This is not good. We can transition to interrupted from | 1797 // TODO(asanka): This is not good. We can transition to interrupted from |
| 1789 // target-pending, which is something we don't want to do. Perhaps we should | 1798 // target-pending, which is something we don't want to do. Perhaps we should |
| 1790 // explicitly transition to target-resolved prior to switching to interrupted. | 1799 // explicitly transition to target-resolved prior to switching to interrupted. |
| 1791 DCHECK_EQ(last_reason_, reason); | 1800 DCHECK_EQ(last_reason_, reason); |
| 1792 TransitionTo(INTERRUPTED_INTERNAL); | 1801 TransitionTo(INTERRUPTED_INTERNAL); |
| 1793 AutoResumeIfValid(); | 1802 AutoResumeIfValid(); |
| 1794 } | 1803 } |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2272 case RESUME_MODE_USER_CONTINUE: | 2281 case RESUME_MODE_USER_CONTINUE: |
| 2273 return "USER_CONTINUE"; | 2282 return "USER_CONTINUE"; |
| 2274 case RESUME_MODE_USER_RESTART: | 2283 case RESUME_MODE_USER_RESTART: |
| 2275 return "USER_RESTART"; | 2284 return "USER_RESTART"; |
| 2276 } | 2285 } |
| 2277 NOTREACHED() << "Unknown resume mode " << mode; | 2286 NOTREACHED() << "Unknown resume mode " << mode; |
| 2278 return "unknown"; | 2287 return "unknown"; |
| 2279 } | 2288 } |
| 2280 | 2289 |
| 2281 } // namespace content | 2290 } // namespace content |
| OLD | NEW |