From 7d76680f436a5577a55086b9e02c555f837ecb59 Mon Sep 17 00:00:00 2001 From: yueyang Date: Wed, 25 Dec 2024 22:22:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=B5=81=E7=A8=8B=E6=A0=B9=E6=8D=AE=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=81=A2=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yueyang --- .../internal/common/download_item_impl.cc | 44 +++++++++++++++++-- .../public/common/download_item_impl.h | 1 + ohos_nweb/src/cef_delegate/nweb_delegate.cc | 3 +- .../nweb_download_handler_delegate.cc | 2 +- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/components/download/internal/common/download_item_impl.cc b/components/download/internal/common/download_item_impl.cc index da9688ac3c..20ed2d3859 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 dbbd4a6414..dded2baf0b 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 b0bc56e4de..142fe37811 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 3f4cdc5899..a457b2814d 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, -- Gitee