Chromium Code Reviews| Index: chrome/browser/android/download/download_manager_service.cc |
| diff --git a/chrome/browser/android/download/download_manager_service.cc b/chrome/browser/android/download/download_manager_service.cc |
| index f00173594033be98ce8d3a58358bbd1f0e705993..08dd6e3e45f56a32933fd10f2fd3f18458172753 100644 |
| --- a/chrome/browser/android/download/download_manager_service.cc |
| +++ b/chrome/browser/android/download/download_manager_service.cc |
| @@ -44,6 +44,23 @@ void updateNotifier(DownloadManagerService* service, |
| } |
| } |
| +void RemoveDownloadsFromDownloadManager( |
| + content::DownloadManager* manager, |
| + const base::FilePath& path) { |
| + if (!manager) |
| + return; |
| + content::DownloadManager::DownloadVector all_items; |
| + manager->GetAllDownloads(&all_items); |
| + |
| + for (size_t i = 0; i < all_items.size(); i++) { |
| + content::DownloadItem* item = all_items[i]; |
| + if (item->GetState() == content::DownloadItem::COMPLETE && |
|
Theresa
2016/09/21 17:40:43
Is it possible to interleave downloading items wit
qinmin
2016/09/21 21:20:29
If a download starts (or resumes) with the same ta
|
| + item->GetTargetFilePath() == path) { |
| + item->Remove(); |
| + } |
| + } |
| +} |
| + |
| } // namespace |
| // static |
| @@ -65,11 +82,15 @@ void DownloadManagerService::OnDownloadCanceled( |
| DownloadController::RecordDownloadCancelReason(reason); |
| } |
| +// static |
| +DownloadManagerService* DownloadManagerService::GetInstance() { |
| + return base::Singleton<DownloadManagerService>::get(); |
| +} |
| static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
| Profile* profile = ProfileManager::GetActiveUserProfile(); |
| - DownloadManagerService* service = |
| - new DownloadManagerService(env, jobj); |
| + DownloadManagerService* service = DownloadManagerService::GetInstance(); |
| + service->Init(env, jobj); |
| DownloadService* download_service = |
| DownloadServiceFactory::GetForBrowserContext(profile); |
| DownloadHistory* history = download_service->GetDownloadHistory(); |
| @@ -78,17 +99,20 @@ static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
| return reinterpret_cast<intptr_t>(service); |
| } |
| -DownloadManagerService::DownloadManagerService( |
| +DownloadManagerService::DownloadManagerService() |
| + : is_history_query_complete_(false) { |
| +} |
| + |
| +DownloadManagerService::~DownloadManagerService() {} |
| + |
| +void DownloadManagerService::Init( |
| JNIEnv* env, |
| - jobject obj) |
| - : java_ref_(env, obj), |
| - is_history_query_complete_(false) { |
| + jobject obj) { |
| + java_ref_.Reset(env, obj); |
| DownloadControllerBase::Get()->SetDefaultDownloadFileName( |
| l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
| } |
| -DownloadManagerService::~DownloadManagerService() {} |
| - |
| void DownloadManagerService::ResumeDownload( |
| JNIEnv* env, |
| jobject obj, |
| @@ -185,6 +209,14 @@ void DownloadManagerService::CheckForExternallyRemovedDownloads( |
| manager->CheckForHistoryFilesRemoval(); |
| } |
| +void DownloadManagerService::RemoveExternallyRemovedDownloads( |
| + const base::FilePath& path) { |
| + content::DownloadManager* manager = GetDownloadManager(false); |
| + RemoveDownloadsFromDownloadManager(manager, path); |
| + manager = GetDownloadManager(true); |
| + RemoveDownloadsFromDownloadManager(manager, path); |
| +} |
| + |
| void DownloadManagerService::CancelDownload( |
| JNIEnv* env, |
| jobject obj, |