| 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 22 matching lines...) Expand all Loading... |
| 33 #include "base/logging.h" | 33 #include "base/logging.h" |
| 34 #include "base/metrics/histogram_macros.h" | 34 #include "base/metrics/histogram_macros.h" |
| 35 #include "base/stl_util.h" | 35 #include "base/stl_util.h" |
| 36 #include "base/strings/string_util.h" | 36 #include "base/strings/string_util.h" |
| 37 #include "base/strings/stringprintf.h" | 37 #include "base/strings/stringprintf.h" |
| 38 #include "base/strings/utf_string_conversions.h" | 38 #include "base/strings/utf_string_conversions.h" |
| 39 #include "content/browser/download/download_create_info.h" | 39 #include "content/browser/download/download_create_info.h" |
| 40 #include "content/browser/download/download_file.h" | 40 #include "content/browser/download/download_file.h" |
| 41 #include "content/browser/download/download_interrupt_reasons_impl.h" | 41 #include "content/browser/download/download_interrupt_reasons_impl.h" |
| 42 #include "content/browser/download/download_item_impl_delegate.h" | 42 #include "content/browser/download/download_item_impl_delegate.h" |
| 43 #include "content/browser/download/download_job_factory.h" |
| 44 #include "content/browser/download/download_job_impl.h" |
| 43 #include "content/browser/download/download_net_log_parameters.h" | 45 #include "content/browser/download/download_net_log_parameters.h" |
| 44 #include "content/browser/download/download_request_handle.h" | 46 #include "content/browser/download/download_request_handle.h" |
| 45 #include "content/browser/download/download_stats.h" | 47 #include "content/browser/download/download_stats.h" |
| 46 #include "content/browser/renderer_host/render_view_host_impl.h" | 48 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 47 #include "content/browser/web_contents/web_contents_impl.h" | 49 #include "content/browser/web_contents/web_contents_impl.h" |
| 48 #include "content/public/browser/browser_context.h" | 50 #include "content/public/browser/browser_context.h" |
| 49 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
| 50 #include "content/public/browser/content_browser_client.h" | 52 #include "content/public/browser/content_browser_client.h" |
| 51 #include "content/public/browser/download_danger_type.h" | 53 #include "content/public/browser/download_danger_type.h" |
| 52 #include "content/public/browser/download_interrupt_reasons.h" | 54 #include "content/public/browser/download_interrupt_reasons.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Constructing for the "Save Page As..." feature: | 235 // Constructing for the "Save Page As..." feature: |
| 234 DownloadItemImpl::DownloadItemImpl( | 236 DownloadItemImpl::DownloadItemImpl( |
| 235 DownloadItemImplDelegate* delegate, | 237 DownloadItemImplDelegate* delegate, |
| 236 uint32_t download_id, | 238 uint32_t download_id, |
| 237 const base::FilePath& path, | 239 const base::FilePath& path, |
| 238 const GURL& url, | 240 const GURL& url, |
| 239 const std::string& mime_type, | 241 const std::string& mime_type, |
| 240 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 242 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
| 241 const net::NetLogWithSource& net_log) | 243 const net::NetLogWithSource& net_log) |
| 242 : is_save_package_download_(true), | 244 : is_save_package_download_(true), |
| 243 request_handle_(std::move(request_handle)), | |
| 244 guid_(base::ToUpperASCII(base::GenerateGUID())), | 245 guid_(base::ToUpperASCII(base::GenerateGUID())), |
| 245 download_id_(download_id), | 246 download_id_(download_id), |
| 246 target_path_(path), | 247 target_path_(path), |
| 247 url_chain_(1, url), | 248 url_chain_(1, url), |
| 248 mime_type_(mime_type), | 249 mime_type_(mime_type), |
| 249 original_mime_type_(mime_type), | 250 original_mime_type_(mime_type), |
| 250 start_tick_(base::TimeTicks::Now()), | 251 start_tick_(base::TimeTicks::Now()), |
| 251 state_(IN_PROGRESS_INTERNAL), | 252 state_(IN_PROGRESS_INTERNAL), |
| 252 start_time_(base::Time::Now()), | 253 start_time_(base::Time::Now()), |
| 253 delegate_(delegate), | 254 delegate_(delegate), |
| 254 current_path_(path), | 255 current_path_(path), |
| 255 net_log_(net_log), | 256 net_log_(net_log), |
| 256 weak_ptr_factory_(this) { | 257 weak_ptr_factory_(this) { |
| 258 job_ = base::MakeUnique<DownloadJobImpl>(this, std::move(request_handle)); |
| 257 delegate_->Attach(); | 259 delegate_->Attach(); |
| 258 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); | 260 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); |
| 259 } | 261 } |
| 260 | 262 |
| 261 DownloadItemImpl::~DownloadItemImpl() { | 263 DownloadItemImpl::~DownloadItemImpl() { |
| 262 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 264 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 263 | 265 |
| 264 // Should always have been nuked before now, at worst in | 266 // Should always have been nuked before now, at worst in |
| 265 // DownloadManager shutdown. | 267 // DownloadManager shutdown. |
| 266 DCHECK(!download_file_.get()); | 268 DCHECK(!download_file_.get()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), callback); | 345 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), callback); |
| 344 } else { | 346 } else { |
| 345 callback.Run(current_path_); | 347 callback.Run(current_path_); |
| 346 } | 348 } |
| 347 } | 349 } |
| 348 | 350 |
| 349 void DownloadItemImpl::Pause() { | 351 void DownloadItemImpl::Pause() { |
| 350 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 352 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 351 | 353 |
| 352 // Ignore irrelevant states. | 354 // Ignore irrelevant states. |
| 353 if (is_paused_) | 355 if (IsPaused()) |
| 354 return; | 356 return; |
| 355 | 357 |
| 356 switch (state_) { | 358 switch (state_) { |
| 357 case CANCELLED_INTERNAL: | 359 case CANCELLED_INTERNAL: |
| 358 case COMPLETE_INTERNAL: | 360 case COMPLETE_INTERNAL: |
| 359 case COMPLETING_INTERNAL: | 361 case COMPLETING_INTERNAL: |
| 360 case INITIAL_INTERNAL: | 362 case INITIAL_INTERNAL: |
| 361 case INTERRUPTED_INTERNAL: | 363 case INTERRUPTED_INTERNAL: |
| 362 case INTERRUPTED_TARGET_PENDING_INTERNAL: | 364 case INTERRUPTED_TARGET_PENDING_INTERNAL: |
| 363 case RESUMING_INTERNAL: | 365 case RESUMING_INTERNAL: |
| 364 // No active request. | 366 // No active request. |
| 365 // TODO(asanka): In the case of RESUMING_INTERNAL, consider setting | 367 // TODO(asanka): In the case of RESUMING_INTERNAL, consider setting |
| 366 // is_paused_ even if there's no request currently associated with this | 368 // |DownloadJob::is_paused_| even if there's no request currently |
| 367 // DII. When a request is assigned (due to a resumption, for example) we | 369 // associated with this DII. When a request is assigned (due to a |
| 368 // can honor the is_paused_ setting. | 370 // resumption, for example) we can honor the |DownloadJob::is_paused_| |
| 371 // setting. |
| 369 return; | 372 return; |
| 370 | 373 |
| 371 case IN_PROGRESS_INTERNAL: | 374 case IN_PROGRESS_INTERNAL: |
| 372 case TARGET_PENDING_INTERNAL: | 375 case TARGET_PENDING_INTERNAL: |
| 373 request_handle_->PauseRequest(); | 376 job_->Pause(); |
| 374 is_paused_ = true; | |
| 375 UpdateObservers(); | 377 UpdateObservers(); |
| 376 return; | 378 return; |
| 377 | 379 |
| 378 case MAX_DOWNLOAD_INTERNAL_STATE: | 380 case MAX_DOWNLOAD_INTERNAL_STATE: |
| 379 case TARGET_RESOLVED_INTERNAL: | 381 case TARGET_RESOLVED_INTERNAL: |
| 380 NOTREACHED(); | 382 NOTREACHED(); |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 | 385 |
| 384 void DownloadItemImpl::Resume() { | 386 void DownloadItemImpl::Resume() { |
| 385 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 387 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 386 DVLOG(20) << __func__ << "() download = " << DebugString(true); | 388 DVLOG(20) << __func__ << "() download = " << DebugString(true); |
| 387 switch (state_) { | 389 switch (state_) { |
| 388 case CANCELLED_INTERNAL: // Nothing to resume. | 390 case CANCELLED_INTERNAL: // Nothing to resume. |
| 389 case COMPLETE_INTERNAL: | 391 case COMPLETE_INTERNAL: |
| 390 case COMPLETING_INTERNAL: | 392 case COMPLETING_INTERNAL: |
| 391 case INITIAL_INTERNAL: | 393 case INITIAL_INTERNAL: |
| 392 case INTERRUPTED_TARGET_PENDING_INTERNAL: | 394 case INTERRUPTED_TARGET_PENDING_INTERNAL: |
| 393 case RESUMING_INTERNAL: // Resumption in progress. | 395 case RESUMING_INTERNAL: // Resumption in progress. |
| 394 return; | 396 return; |
| 395 | 397 |
| 396 case TARGET_PENDING_INTERNAL: | 398 case TARGET_PENDING_INTERNAL: |
| 397 case IN_PROGRESS_INTERNAL: | 399 case IN_PROGRESS_INTERNAL: |
| 398 if (!is_paused_) | 400 if (!IsPaused()) |
| 399 return; | 401 return; |
| 400 request_handle_->ResumeRequest(); | 402 if (job_) |
| 401 is_paused_ = false; | 403 job_->Resume(true); |
| 402 UpdateObservers(); | 404 UpdateObservers(); |
| 403 return; | 405 return; |
| 404 | 406 |
| 405 case INTERRUPTED_INTERNAL: | 407 case INTERRUPTED_INTERNAL: |
| 406 auto_resume_count_ = 0; // User input resets the counter. | 408 auto_resume_count_ = 0; // User input resets the counter. |
| 407 ResumeInterruptedDownload(ResumptionRequestSource::USER); | 409 ResumeInterruptedDownload(ResumptionRequestSource::USER); |
| 408 UpdateObservers(); | 410 UpdateObservers(); |
| 409 return; | 411 return; |
| 410 | 412 |
| 411 case MAX_DOWNLOAD_INTERNAL_STATE: | 413 case MAX_DOWNLOAD_INTERNAL_STATE: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 481 |
| 480 DownloadItem::DownloadState DownloadItemImpl::GetState() const { | 482 DownloadItem::DownloadState DownloadItemImpl::GetState() const { |
| 481 return InternalToExternalState(state_); | 483 return InternalToExternalState(state_); |
| 482 } | 484 } |
| 483 | 485 |
| 484 DownloadInterruptReason DownloadItemImpl::GetLastReason() const { | 486 DownloadInterruptReason DownloadItemImpl::GetLastReason() const { |
| 485 return last_reason_; | 487 return last_reason_; |
| 486 } | 488 } |
| 487 | 489 |
| 488 bool DownloadItemImpl::IsPaused() const { | 490 bool DownloadItemImpl::IsPaused() const { |
| 489 return is_paused_; | 491 return job_ ? job_->is_paused() : false; |
| 490 } | 492 } |
| 491 | 493 |
| 492 bool DownloadItemImpl::IsTemporary() const { | 494 bool DownloadItemImpl::IsTemporary() const { |
| 493 return is_temporary_; | 495 return is_temporary_; |
| 494 } | 496 } |
| 495 | 497 |
| 496 bool DownloadItemImpl::CanResume() const { | 498 bool DownloadItemImpl::CanResume() const { |
| 497 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 499 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 498 switch (state_) { | 500 switch (state_) { |
| 499 case INITIAL_INTERNAL: | 501 case INITIAL_INTERNAL: |
| 500 case COMPLETING_INTERNAL: | 502 case COMPLETING_INTERNAL: |
| 501 case COMPLETE_INTERNAL: | 503 case COMPLETE_INTERNAL: |
| 502 case CANCELLED_INTERNAL: | 504 case CANCELLED_INTERNAL: |
| 503 case RESUMING_INTERNAL: | 505 case RESUMING_INTERNAL: |
| 504 case INTERRUPTED_TARGET_PENDING_INTERNAL: | 506 case INTERRUPTED_TARGET_PENDING_INTERNAL: |
| 505 return false; | 507 return false; |
| 506 | 508 |
| 507 case TARGET_PENDING_INTERNAL: | 509 case TARGET_PENDING_INTERNAL: |
| 508 case TARGET_RESOLVED_INTERNAL: | 510 case TARGET_RESOLVED_INTERNAL: |
| 509 case IN_PROGRESS_INTERNAL: | 511 case IN_PROGRESS_INTERNAL: |
| 510 return is_paused_; | 512 return IsPaused(); |
| 511 | 513 |
| 512 case INTERRUPTED_INTERNAL: { | 514 case INTERRUPTED_INTERNAL: { |
| 513 ResumeMode resume_mode = GetResumeMode(); | 515 ResumeMode resume_mode = GetResumeMode(); |
| 514 // Only allow Resume() calls if the resumption mode requires a user | 516 // Only allow Resume() calls if the resumption mode requires a user |
| 515 // action. | 517 // action. |
| 516 return resume_mode == RESUME_MODE_USER_RESTART || | 518 return resume_mode == RESUME_MODE_USER_RESTART || |
| 517 resume_mode == RESUME_MODE_USER_CONTINUE; | 519 resume_mode == RESUME_MODE_USER_CONTINUE; |
| 518 } | 520 } |
| 519 | 521 |
| 520 case MAX_DOWNLOAD_INTERNAL_STATE: | 522 case MAX_DOWNLOAD_INTERNAL_STATE: |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 int64_t speed = CurrentSpeed(); | 696 int64_t speed = CurrentSpeed(); |
| 695 if (speed == 0) | 697 if (speed == 0) |
| 696 return false; | 698 return false; |
| 697 | 699 |
| 698 *remaining = base::TimeDelta::FromSeconds( | 700 *remaining = base::TimeDelta::FromSeconds( |
| 699 (total_bytes_ - received_bytes_) / speed); | 701 (total_bytes_ - received_bytes_) / speed); |
| 700 return true; | 702 return true; |
| 701 } | 703 } |
| 702 | 704 |
| 703 int64_t DownloadItemImpl::CurrentSpeed() const { | 705 int64_t DownloadItemImpl::CurrentSpeed() const { |
| 704 if (is_paused_) | 706 if (IsPaused()) |
| 705 return 0; | 707 return 0; |
| 706 return bytes_per_sec_; | 708 return bytes_per_sec_; |
| 707 } | 709 } |
| 708 | 710 |
| 709 int DownloadItemImpl::PercentComplete() const { | 711 int DownloadItemImpl::PercentComplete() const { |
| 710 // If the delegate is delaying completion of the download, then we have no | 712 // If the delegate is delaying completion of the download, then we have no |
| 711 // idea how long it will take. | 713 // idea how long it will take. |
| 712 if (delegate_delayed_complete_ || total_bytes_ <= 0) | 714 if (delegate_delayed_complete_ || total_bytes_ <= 0) |
| 713 return -1; | 715 return -1; |
| 714 | 716 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 | 775 |
| 774 BrowserContext* DownloadItemImpl::GetBrowserContext() const { | 776 BrowserContext* DownloadItemImpl::GetBrowserContext() const { |
| 775 return delegate_->GetBrowserContext(); | 777 return delegate_->GetBrowserContext(); |
| 776 } | 778 } |
| 777 | 779 |
| 778 WebContents* DownloadItemImpl::GetWebContents() const { | 780 WebContents* DownloadItemImpl::GetWebContents() const { |
| 779 // TODO(rdsmith): Remove null check after removing GetWebContents() from | 781 // TODO(rdsmith): Remove null check after removing GetWebContents() from |
| 780 // paths that might be used by DownloadItems created from history import. | 782 // paths that might be used by DownloadItems created from history import. |
| 781 // Currently such items have null request_handle_s, where other items | 783 // Currently such items have null request_handle_s, where other items |
| 782 // (regular and SavePackage downloads) have actual objects off the pointer. | 784 // (regular and SavePackage downloads) have actual objects off the pointer. |
| 783 if (request_handle_) | 785 if (job_) |
| 784 return request_handle_->GetWebContents(); | 786 return job_->GetWebContents(); |
| 785 return NULL; | 787 return nullptr; |
| 786 } | 788 } |
| 787 | 789 |
| 788 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { | 790 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { |
| 789 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 791 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 790 DCHECK(AllDataSaved()); | 792 DCHECK(AllDataSaved()); |
| 791 | 793 |
| 792 // Danger type is only allowed to be set on an active download after all data | 794 // Danger type is only allowed to be set on an active download after all data |
| 793 // has been saved. This excludes all other states. In particular, | 795 // has been saved. This excludes all other states. In particular, |
| 794 // OnContentCheckCompleted() isn't allowed on an INTERRUPTED download since | 796 // OnContentCheckCompleted() isn't allowed on an INTERRUPTED download since |
| 795 // such an interruption would need to happen between OnAllDataSaved() and | 797 // such an interruption would need to happen between OnAllDataSaved() and |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 | 882 |
| 881 // We can't continue without a handle on the intermediate file. | 883 // We can't continue without a handle on the intermediate file. |
| 882 // We also can't continue if we don't have some verifier to make sure | 884 // We also can't continue if we don't have some verifier to make sure |
| 883 // we're getting the same file. | 885 // we're getting the same file. |
| 884 bool restart_required = | 886 bool restart_required = |
| 885 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); | 887 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); |
| 886 | 888 |
| 887 // We won't auto-restart if we've used up our attempts or the | 889 // We won't auto-restart if we've used up our attempts or the |
| 888 // download has been paused by user action. | 890 // download has been paused by user action. |
| 889 bool user_action_required = | 891 bool user_action_required = |
| 890 (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_); | 892 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused()); |
| 891 | 893 |
| 892 switch(last_reason_) { | 894 switch(last_reason_) { |
| 893 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: | 895 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: |
| 894 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: | 896 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: |
| 895 break; | 897 break; |
| 896 | 898 |
| 897 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: | 899 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: |
| 898 // The server disagreed with the file offset that we sent. | 900 // The server disagreed with the file offset that we sent. |
| 899 | 901 |
| 900 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: | 902 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 // We're starting the download. | 1175 // We're starting the download. |
| 1174 void DownloadItemImpl::Start( | 1176 void DownloadItemImpl::Start( |
| 1175 std::unique_ptr<DownloadFile> file, | 1177 std::unique_ptr<DownloadFile> file, |
| 1176 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | 1178 std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
| 1177 const DownloadCreateInfo& new_create_info) { | 1179 const DownloadCreateInfo& new_create_info) { |
| 1178 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1180 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1179 DCHECK(!download_file_.get()); | 1181 DCHECK(!download_file_.get()); |
| 1180 DVLOG(20) << __func__ << "() this=" << DebugString(true); | 1182 DVLOG(20) << __func__ << "() this=" << DebugString(true); |
| 1181 | 1183 |
| 1182 download_file_ = std::move(file); | 1184 download_file_ = std::move(file); |
| 1183 request_handle_ = std::move(req_handle); | 1185 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle), |
| 1186 new_create_info); |
| 1184 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; | 1187 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 1185 | 1188 |
| 1186 if (state_ == CANCELLED_INTERNAL) { | 1189 if (state_ == CANCELLED_INTERNAL) { |
| 1187 // The download was in the process of resuming when it was cancelled. Don't | 1190 // The download was in the process of resuming when it was cancelled. Don't |
| 1188 // proceed. | 1191 // proceed. |
| 1189 ReleaseDownloadFile(true); | 1192 ReleaseDownloadFile(true); |
| 1190 if (request_handle_) | 1193 job_->Cancel(true); |
| 1191 request_handle_->CancelRequest(); | |
| 1192 return; | 1194 return; |
| 1193 } | 1195 } |
| 1194 | 1196 |
| 1195 // The state could be one of the following: | 1197 // The state could be one of the following: |
| 1196 // | 1198 // |
| 1197 // INITIAL_INTERNAL: A normal download attempt. | 1199 // INITIAL_INTERNAL: A normal download attempt. |
| 1198 // | 1200 // |
| 1199 // RESUMING_INTERNAL: A resumption attempt. May or may not have been | 1201 // RESUMING_INTERNAL: A resumption attempt. May or may not have been |
| 1200 // successful. | 1202 // successful. |
| 1201 DCHECK(state_ == INITIAL_INTERNAL || state_ == RESUMING_INTERNAL); | 1203 DCHECK(state_ == INITIAL_INTERNAL || state_ == RESUMING_INTERNAL); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1232 // Otherwise, this was a resumption attempt which ended with an | 1234 // Otherwise, this was a resumption attempt which ended with an |
| 1233 // interruption. Continue with current target path. | 1235 // interruption. Continue with current target path. |
| 1234 TransitionTo(TARGET_RESOLVED_INTERNAL); | 1236 TransitionTo(TARGET_RESOLVED_INTERNAL); |
| 1235 InterruptWithPartialState( | 1237 InterruptWithPartialState( |
| 1236 offset, std::move(hash_state), new_create_info.result); | 1238 offset, std::move(hash_state), new_create_info.result); |
| 1237 UpdateObservers(); | 1239 UpdateObservers(); |
| 1238 return; | 1240 return; |
| 1239 } | 1241 } |
| 1240 | 1242 |
| 1241 // Successful download start. | 1243 // Successful download start. |
| 1242 DCHECK(download_file_.get()); | 1244 DCHECK(download_file_); |
| 1243 DCHECK(request_handle_.get()); | 1245 DCHECK(job_); |
| 1244 | 1246 |
| 1245 if (state_ == RESUMING_INTERNAL) | 1247 if (state_ == RESUMING_INTERNAL) |
| 1246 UpdateValidatorsOnResumption(new_create_info); | 1248 UpdateValidatorsOnResumption(new_create_info); |
| 1247 | 1249 |
| 1248 TransitionTo(TARGET_PENDING_INTERNAL); | 1250 TransitionTo(TARGET_PENDING_INTERNAL); |
| 1249 | 1251 |
| 1252 job_->Start(); |
| 1253 } |
| 1254 |
| 1255 void DownloadItemImpl::StartDownload() { |
| 1250 BrowserThread::PostTask( | 1256 BrowserThread::PostTask( |
| 1251 BrowserThread::FILE, FROM_HERE, | 1257 BrowserThread::FILE, FROM_HERE, |
| 1252 base::Bind(&DownloadFile::Initialize, | 1258 base::Bind(&DownloadFile::Initialize, |
| 1253 // Safe because we control download file lifetime. | 1259 // Safe because we control download file lifetime. |
| 1254 base::Unretained(download_file_.get()), | 1260 base::Unretained(download_file_.get()), |
| 1255 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, | 1261 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, |
| 1256 weak_ptr_factory_.GetWeakPtr()))); | 1262 weak_ptr_factory_.GetWeakPtr()))); |
| 1257 } | 1263 } |
| 1258 | 1264 |
| 1259 void DownloadItemImpl::OnDownloadFileInitialized( | 1265 void DownloadItemImpl::OnDownloadFileInitialized( |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 | 1642 |
| 1637 if (current_path_.empty()) { | 1643 if (current_path_.empty()) { |
| 1638 hash_state_.reset(); | 1644 hash_state_.reset(); |
| 1639 hash_.clear(); | 1645 hash_.clear(); |
| 1640 received_bytes_ = 0; | 1646 received_bytes_ = 0; |
| 1641 } else { | 1647 } else { |
| 1642 UpdateProgress(bytes_so_far, 0); | 1648 UpdateProgress(bytes_so_far, 0); |
| 1643 SetHashState(std::move(hash_state)); | 1649 SetHashState(std::move(hash_state)); |
| 1644 } | 1650 } |
| 1645 | 1651 |
| 1646 if (request_handle_) | 1652 if (job_) |
| 1647 request_handle_->CancelRequest(); | 1653 job_->Cancel(false); |
| 1648 | 1654 |
| 1649 if (reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED || | 1655 if (reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED || |
| 1650 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) { | 1656 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) { |
| 1651 if (IsDangerous()) { | 1657 if (IsDangerous()) { |
| 1652 RecordDangerousDownloadDiscard( | 1658 RecordDangerousDownloadDiscard( |
| 1653 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED | 1659 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED |
| 1654 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION | 1660 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION |
| 1655 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, | 1661 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, |
| 1656 GetDangerType(), GetTargetFilePath()); | 1662 GetDangerType(), GetTargetFilePath()); |
| 1657 } | 1663 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1777 case TARGET_RESOLVED_INTERNAL: | 1783 case TARGET_RESOLVED_INTERNAL: |
| 1778 case INTERRUPTED_TARGET_PENDING_INTERNAL: | 1784 case INTERRUPTED_TARGET_PENDING_INTERNAL: |
| 1779 break; | 1785 break; |
| 1780 | 1786 |
| 1781 case IN_PROGRESS_INTERNAL: | 1787 case IN_PROGRESS_INTERNAL: |
| 1782 DCHECK(!current_path_.empty()) << "Current output path must be known."; | 1788 DCHECK(!current_path_.empty()) << "Current output path must be known."; |
| 1783 DCHECK(!target_path_.empty()) << "Target path must be known."; | 1789 DCHECK(!target_path_.empty()) << "Target path must be known."; |
| 1784 DCHECK(current_path_.DirName() == target_path_.DirName()) | 1790 DCHECK(current_path_.DirName() == target_path_.DirName()) |
| 1785 << "Current output directory must match target directory."; | 1791 << "Current output directory must match target directory."; |
| 1786 DCHECK(download_file_) << "Output file must be owned by download item."; | 1792 DCHECK(download_file_) << "Output file must be owned by download item."; |
| 1787 DCHECK(request_handle_) << "Download source must be active."; | 1793 DCHECK(job_) << "Must have active download job."; |
| 1788 DCHECK(!is_paused_) << "At the time a download enters IN_PROGRESS state, " | 1794 DCHECK(!job_->is_paused()) |
| 1789 "it must not be paused."; | 1795 << "At the time a download enters IN_PROGRESS state, " |
| 1796 "it must not be paused."; |
| 1790 break; | 1797 break; |
| 1791 | 1798 |
| 1792 case COMPLETING_INTERNAL: | 1799 case COMPLETING_INTERNAL: |
| 1793 DCHECK(all_data_saved_) << "All data must be saved prior to completion."; | 1800 DCHECK(all_data_saved_) << "All data must be saved prior to completion."; |
| 1794 DCHECK(!download_file_) | 1801 DCHECK(!download_file_) |
| 1795 << "Download file must be released prior to completion."; | 1802 << "Download file must be released prior to completion."; |
| 1796 DCHECK(!target_path_.empty()) << "Target path must be known."; | 1803 DCHECK(!target_path_.empty()) << "Target path must be known."; |
| 1797 DCHECK(current_path_ == target_path_) | 1804 DCHECK(current_path_ == target_path_) |
| 1798 << "Current output path must match target path."; | 1805 << "Current output path must match target path."; |
| 1799 | 1806 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1947 // (which is the contents of the Referer header for the last download request) | 1954 // (which is the contents of the Referer header for the last download request) |
| 1948 // will only be sent to the URL returned by GetURL(). | 1955 // will only be sent to the URL returned by GetURL(). |
| 1949 download_params->set_referrer( | 1956 download_params->set_referrer( |
| 1950 Referrer(GetReferrerUrl(), blink::WebReferrerPolicyAlways)); | 1957 Referrer(GetReferrerUrl(), blink::WebReferrerPolicyAlways)); |
| 1951 | 1958 |
| 1952 TransitionTo(RESUMING_INTERNAL); | 1959 TransitionTo(RESUMING_INTERNAL); |
| 1953 RecordDownloadSource(source == ResumptionRequestSource::USER | 1960 RecordDownloadSource(source == ResumptionRequestSource::USER |
| 1954 ? INITIATED_BY_MANUAL_RESUMPTION | 1961 ? INITIATED_BY_MANUAL_RESUMPTION |
| 1955 : INITIATED_BY_AUTOMATIC_RESUMPTION); | 1962 : INITIATED_BY_AUTOMATIC_RESUMPTION); |
| 1956 delegate_->ResumeInterruptedDownload(std::move(download_params), GetId()); | 1963 delegate_->ResumeInterruptedDownload(std::move(download_params), GetId()); |
| 1957 // Just in case we were interrupted while paused. | 1964 |
| 1958 is_paused_ = false; | 1965 if (job_) |
| 1966 job_->Resume(false); |
| 1959 } | 1967 } |
| 1960 | 1968 |
| 1961 // static | 1969 // static |
| 1962 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( | 1970 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( |
| 1963 DownloadInternalState internal_state) { | 1971 DownloadInternalState internal_state) { |
| 1964 switch (internal_state) { | 1972 switch (internal_state) { |
| 1965 case INITIAL_INTERNAL: | 1973 case INITIAL_INTERNAL: |
| 1966 case TARGET_PENDING_INTERNAL: | 1974 case TARGET_PENDING_INTERNAL: |
| 1967 case TARGET_RESOLVED_INTERNAL: | 1975 case TARGET_RESOLVED_INTERNAL: |
| 1968 case INTERRUPTED_TARGET_PENDING_INTERNAL: | 1976 case INTERRUPTED_TARGET_PENDING_INTERNAL: |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2128 case RESUME_MODE_USER_CONTINUE: | 2136 case RESUME_MODE_USER_CONTINUE: |
| 2129 return "USER_CONTINUE"; | 2137 return "USER_CONTINUE"; |
| 2130 case RESUME_MODE_USER_RESTART: | 2138 case RESUME_MODE_USER_RESTART: |
| 2131 return "USER_RESTART"; | 2139 return "USER_RESTART"; |
| 2132 } | 2140 } |
| 2133 NOTREACHED() << "Unknown resume mode " << mode; | 2141 NOTREACHED() << "Unknown resume mode " << mode; |
| 2134 return "unknown"; | 2142 return "unknown"; |
| 2135 } | 2143 } |
| 2136 | 2144 |
| 2137 } // namespace content | 2145 } // namespace content |
| OLD | NEW |