Commit 1cd8209a authored by Min Qin's avatar Min Qin Committed by Commit Bot

Remove non-resumable interrupted file from disk

On Android, we clean up non-resumable interrupted file from the history and
download db. However, the actual files may still be on disk.
This CL removes those files while cleaning up the database.

BUG=899775

Change-Id: I59bdf32c11789448295126b2819d326fedcf54ff
Reviewed-on: https://chromium-review.googlesource.com/c/1310499
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605047}
parent c169b4e4
......@@ -62,15 +62,6 @@ namespace download {
namespace {
bool DeleteDownloadedFile(const base::FilePath& path) {
DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
// Make sure we only delete files.
if (base::DirectoryExists(path))
return true;
return base::DeleteFile(path, false);
}
void DeleteDownloadedFileDone(base::WeakPtr<DownloadItemImpl> item,
const base::Callback<void(bool)>& callback,
bool success) {
......
......@@ -4,6 +4,7 @@
#include "components/download/public/common/download_utils.h"
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
......@@ -12,6 +13,7 @@
#include "components/download/public/common/download_item.h"
#include "components/download/public/common/download_save_info.h"
#include "components/download/public/common/download_stats.h"
#include "components/download/public/common/download_task_runner.h"
#include "components/download/public/common/download_url_parameters.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
......@@ -509,4 +511,13 @@ ResumeMode GetDownloadResumeMode(DownloadInterruptReason reason,
return ResumeMode::IMMEDIATE_CONTINUE;
}
bool DeleteDownloadedFile(const base::FilePath& path) {
DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
// Make sure we only delete files.
if (base::DirectoryExists(path))
return true;
return base::DeleteFile(path, false);
}
} // namespace download
......@@ -91,6 +91,8 @@ GetDownloadResumeMode(DownloadInterruptReason reason,
bool restart_required,
bool user_action_required);
COMPONENTS_DOWNLOAD_EXPORT bool DeleteDownloadedFile(
const base::FilePath& path);
} // namespace download
#endif // COMPONENTS_DOWNLOAD_PUBLIC_COMMON_DOWNLOAD_UTILS_H_
......@@ -88,6 +88,17 @@
namespace content {
namespace {
#if defined(OS_ANDROID)
void DeleteDownloadedFileOnUIThread(const base::FilePath& file_path) {
if (!file_path.empty()) {
download::GetDownloadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(base::IgnoreResult(&download::DeleteDownloadedFile),
file_path));
}
}
#endif
StoragePartitionImpl* GetStoragePartition(BrowserContext* context,
int render_process_id,
int render_frame_id) {
......@@ -566,6 +577,7 @@ void DownloadManagerImpl::OnInProgressDownloadManagerInitialized() {
if (ShouldClearDownloadFromDB(download->GetState(),
download->GetLastReason())) {
cleared_download_guids_on_startup_.insert(download->GetGuid());
DeleteDownloadedFileOnUIThread(download->GetFullPath());
continue;
}
#endif // defined(OS_ANDROID)
......@@ -970,8 +982,11 @@ download::DownloadItem* DownloadManagerImpl::CreateDownloadItem(
// download. Simply returning null and don't store them in this class to
// reduce memory usage.
if (cleared_download_guids_on_startup_.find(guid) !=
cleared_download_guids_on_startup_.end() ||
ShouldClearDownloadFromDB(state, interrupt_reason)) {
cleared_download_guids_on_startup_.end()) {
return nullptr;
}
if (ShouldClearDownloadFromDB(state, interrupt_reason)) {
DeleteDownloadedFileOnUIThread(current_path);
return nullptr;
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment