diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index 40df9b3a81627707199eb804d31ca6acbe152fab..487a831e4d188fa0f3ee5670dccaccb5ba834cdd 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -293,6 +293,26 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content m_weakPtrFactory.GetWeakPtr())); } +bool DownloadManagerDelegateQt::IsMostRecentDownloadItemAtFilePath(content::DownloadItem *download) +{ + content::BrowserContext *context = download->GetBrowserContext(); + std::vector<content::DownloadItem*> all_downloads; + + content::DownloadManager* manager = + content::BrowserContext::GetDownloadManager(context); + if (manager) + manager->GetAllDownloads(&all_downloads); + + for (const auto* item : all_downloads) { + if (item->GetGuid() == download->GetGuid() || + item->GetTargetFilePath() != download->GetTargetFilePath()) + continue; + if (item->GetState() == content::DownloadItem::IN_PROGRESS) + return false; + } + return true; +} + void DownloadManagerDelegateQt::savePackageDownloadCreated(content::DownloadItem *item) { OnDownloadUpdated(item); diff --git a/src/core/download_manager_delegate_qt.h b/src/core/download_manager_delegate_qt.h index df43211ed3d11a24590a93a69d4c6da257879849..7563d5d3b5ddf87b87a6d4fbd99860f90d182e27 100644 --- a/src/core/download_manager_delegate_qt.h +++ b/src/core/download_manager_delegate_qt.h @@ -81,6 +81,8 @@ public: const base::FilePath::StringType &default_extension, bool can_save_as_complete, const content::SavePackagePathPickedCallback &callback) override; + bool IsMostRecentDownloadItemAtFilePath(content::DownloadItem* download) override; + void cancelDownload(quint32 downloadId); void pauseDownload(quint32 downloadId);