diff --git a/components/download/internal/common/download_item_impl.cc b/components/download/internal/common/download_item_impl.cc index da9688ac3c5a69fcd00d4e2bb6be06c81ff8fc36..20ed2d385908c9f52e079740434c7854968a4be3 100644 --- a/components/download/internal/common/download_item_impl.cc +++ b/components/download/internal/common/download_item_impl.cc @@ -599,6 +599,9 @@ void DownloadItemImpl::StealDangerousDownload(bool delete_file_afterward, void DownloadItemImpl::Pause() { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + LOG(INFO) << "DownloadItemImpl::Pause guid: " << GetGuid() + << ", isPaused: " << IsPaused() + << ", state_: " << DebugDownloadStateString(state_); // Ignore irrelevant states. if (IsPaused()) @@ -634,6 +637,8 @@ void DownloadItemImpl::Pause() { void DownloadItemImpl::Resume(bool user_resume) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DVLOG(20) << __func__ << "() download = " << DebugString(true); + LOG(INFO) << "DownloadItemImpl::Resume guid: " << GetGuid() + << ", user_resume: " << user_resume; switch (state_) { case CANCELLED_INTERNAL: // Nothing to resume. @@ -690,6 +695,8 @@ void DownloadItemImpl::UpdateResumptionInfo(bool user_resume) { void DownloadItemImpl::Cancel(bool user_cancel) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DVLOG(20) << __func__ << "() download = " << DebugString(true); + LOG(INFO) << "DownloadItemImpl::Cancel guid: " << GetGuid() + << ", user_cancel: " << user_cancel; InterruptAndDiscardPartialState( user_cancel ? DOWNLOAD_INTERRUPT_REASON_USER_CANCELED : DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN); @@ -699,6 +706,7 @@ void DownloadItemImpl::Cancel(bool user_cancel) { void DownloadItemImpl::Remove() { DVLOG(20) << __func__ << "() download = " << DebugString(true); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + LOG(INFO) << "DownloadItemImpl::Remove guid: " << GetGuid(); InterruptAndDiscardPartialState(DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); UpdateObservers(); @@ -779,6 +787,7 @@ void DownloadItemImpl::RenameDownloadedFileDone( void DownloadItemImpl::Rename(const base::FilePath& display_name, DownloadItem::RenameDownloadCallback callback) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + LOG(INFO) << "DownloadItemImpl::Rename guid: " << GetGuid(); if (display_name.IsAbsolute()) { base::SequencedTaskRunner::GetCurrentDefault()->PostTask( @@ -834,6 +843,8 @@ const std::string& DownloadItemImpl::GetRequestMethod() const { bool DownloadItemImpl::CanResume() const { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + LOG(INFO) << "DownloadItemImpl::CanResume guid: " << GetGuid() + << ", state_: " << DebugDownloadStateString(state_); switch (state_) { case INITIAL_INTERNAL: case COMPLETING_INTERNAL: @@ -1561,6 +1572,7 @@ void DownloadItemImpl::Start( URLLoaderFactoryProvider::URLLoaderFactoryProviderPtr url_loader_factory_provider) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + LOG(INFO) << "DownloadItemImpl::Start guid: " << GetGuid(); #if BUILDFLAG(IS_OHOS) // Simultaneously restoring a failed download multiple times will result in a crash. if (download_file_) { @@ -1670,6 +1682,7 @@ void DownloadItemImpl::Start( } TransitionTo(TARGET_PENDING_INTERNAL); + LOG(INFO) << "DownloadItemImpl::Start download_file_: " << download_file_.get(); job_->Start(download_file_.get(), base::BindRepeating(&DownloadItemImpl::OnDownloadFileInitialized, @@ -2140,14 +2153,16 @@ void DownloadItemImpl::InterruptWithPartialState( if (CheckIsNeedAutoResume(reason)) { LOG(INFO) << "DownloadItemImpl::CheckIsNeedAutoResume last_reason_: " << last_reason_ << ", auto_resume_count_: " << auto_resume_count_ - << ", state_: " << state_ << ", guid: " << GetGuid() + << ", state_: " << DebugDownloadStateString(state_) << ", guid: " << GetGuid() << ", isPause: " << IsPaused() << ", is cancel: "<< IsCancellation(reason); resume_mode = ResumeMode::IMMEDIATE_CONTINUE; need_auto_resume = true; } LOG(INFO) << "DownloadItemImpl::InterruptWithPartialState " - << "need_auto_resume: " << need_auto_resume; + << ", guid: " << GetGuid() + << ", need_auto_resume: " << need_auto_resume + << ", path: " << GetFullPath(); #endif // OHOS_EX_DOWNLOAD ReleaseDownloadFile(resume_mode != ResumeMode::IMMEDIATE_CONTINUE && resume_mode != ResumeMode::USER_CONTINUE); @@ -2343,7 +2358,9 @@ bool DownloadItemImpl::IsDownloadReadyForCompletion( void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - LOG(INFO) << "DownloadItemImpl::TransitionTo " << state_ << " to " << new_state; + LOG(INFO) << "DownloadItemImpl::TransitionTo " + << DebugDownloadStateString(state_) << " to " + << DebugDownloadStateString(new_state); if (state_ == new_state) return; @@ -2486,11 +2503,30 @@ void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { } #ifdef OHOS_EX_DOWNLOAD +bool DownloadItemImpl::IsAllowedAutoResume() { + switch (last_reason_) { + case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: + case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: + case DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT: + case DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN: + case DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE: + case DOWNLOAD_INTERRUPT_REASON_CRASH: + case DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED: + case DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE: + case DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED: + case DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG: + case DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE: + return false; + default: + return true; + } +} + bool DownloadItemImpl::CheckIsNeedAutoResume(DownloadInterruptReason reason) { if (base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableNwebExDownload) && (state_ == TARGET_RESOLVED_INTERNAL || state_ == IN_PROGRESS_INTERNAL) && - !IsPaused() && !IsCancellation(reason) && + !IsPaused() && !IsCancellation(reason) && IsAllowedAutoResume() && auto_resume_count_ <= kMaxAutoResumeAttempts) { return true; } diff --git a/components/download/public/common/download_item_impl.h b/components/download/public/common/download_item_impl.h index dbbd4a6414167e3006100275622696276b76329d..dded2baf0bb6a5430ad8989982b9d3092f60bef8 100644 --- a/components/download/public/common/download_item_impl.h +++ b/components/download/public/common/download_item_impl.h @@ -695,6 +695,7 @@ struct COMPONENTS_DOWNLOAD_EXPORT NWebIdData : public base::SupportsUserData::Da #ifdef OHOS_EX_DOWNLOAD void AutoResume(); bool CheckIsNeedAutoResume(DownloadInterruptReason reason); + bool IsAllowedAutoResume(); #endif // OHOS_EX_DOWNLOAD enum class ResumptionRequestSource { AUTOMATIC, USER }; diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index b0bc56e4deb399b150cd3f9cc86da40ac33b54bc..142fe378114458e4fd45708dc1b120cf424a998b 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -644,6 +644,7 @@ void NWebDelegate::RegisterWebDownloadDelegateListener( } void NWebDelegate::StartDownload(const char* url) { + LOG(INFO) << "NWebDelegate::StartDownload"; if (handler_delegate_ == nullptr) { LOG(ERROR) << "fail to start download, NWEB handler is nullptr"; return; @@ -656,7 +657,7 @@ void NWebDelegate::StartDownload(const char* url) { void NWebDelegate::ResumeDownload( std::shared_ptr web_download) { - LOG(DEBUG) << "NWebDelegate::ResumeDownload"; + LOG(INFO) << "NWebDelegate::ResumeDownload"; auto browser = GetBrowser(); if (web_download == nullptr) { diff --git a/ohos_nweb/src/cef_delegate/nweb_download_handler_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_download_handler_delegate.cc index 3f4cdc5899e2400132a61b215514f9b62dcfe3a5..a457b2814d7bba23c34b7cb0b9b3fb6c592692d5 100644 --- a/ohos_nweb/src/cef_delegate/nweb_download_handler_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_download_handler_delegate.cc @@ -137,7 +137,7 @@ std::string NWebDownloadHandlerDelegate::GenerateSuggestedFilename( preference_delegate_ ? preference_delegate_->DefaultTextEncodingFormat() : (nweb ? nweb->GetPreference()->DefaultTextEncodingFormat() : "utf-8"); LOG(INFO) << "GenerateSuggestedFilename mime_type: " << sniffed_mime_type - << "default_charset: " << default_charset; + << ", default_charset: " << default_charset; GURL gurl(download_item->GetURL().ToString()); base::FilePath generated_filename = net::GenerateFileName( gurl, download_item->GetContentDisposition()->GetStdString(), default_charset,