Skip to content

Commit

Permalink
Fix an issue that download file is not deleted when clicking Replace …
Browse files Browse the repository at this point in the history
…button

When enqueueing a file to Android DownloadManager, we delete the file if
user choose to overwrite.
But when using Chrome's network stack, we didn't remove the file.
This will reduce user's sdcard space during download.
And it also causes issues when user try to resume the download.
This CL deletes the file when user clicks the "Replace File" button.

BUG=602721

Review URL: https://codereview.chromium.org/1884783002

Cr-Commit-Position: refs/heads/master@{#387368}
  • Loading branch information
qinmin authored and Commit bot committed Apr 14, 2016
1 parent 9e4c1a8 commit c0258fd
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"

namespace {

void DeleteExistingDownloadFile(
const base::FilePath& download_path,
const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
base::File::Info info;
if (GetFileInfo(download_path, &info) && !info.is_directory)
base::DeleteFile(download_path, false);

content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(callback, download_path));
}

} // namespace

namespace chrome {
namespace android {

Expand Down Expand Up @@ -49,7 +65,10 @@ ChromeDownloadManagerOverwriteInfoBarDelegate::GetIdentifier() const {
}

bool ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() {
file_selected_callback_.Run(suggested_download_path_);
content::BrowserThread::PostTask(
content::BrowserThread::FILE, FROM_HERE,
base::Bind(&DeleteExistingDownloadFile, suggested_download_path_,
file_selected_callback_));
return true;
}

Expand Down

0 comments on commit c0258fd

Please sign in to comment.