Commit 3fa5b8a0 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Better error handling in MakeCopyOfDownloadFile().

If base::CreateTemporaryFile() fails, the caller should not try to use
its out parameter.

Change-Id: Ibd301e5dbeb173246c5b540c37417ea9ddc1513a
Reviewed-on: https://chromium-review.googlesource.com/688226Reviewed-by: default avatarJialiu Lin <jialiul@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505063}
parent a545953e
......@@ -93,30 +93,28 @@ void DeleteDownloadedFileDone(
// Wrapper around DownloadFile::Detach and DownloadFile::Cancel that
// takes ownership of the DownloadFile and hence implicitly destroys it
// at the end of the function.
static base::FilePath DownloadFileDetach(
std::unique_ptr<DownloadFile> download_file) {
base::FilePath DownloadFileDetach(std::unique_ptr<DownloadFile> download_file) {
DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
base::FilePath full_path = download_file->FullPath();
download_file->Detach();
return full_path;
}
static base::FilePath MakeCopyOfDownloadFile(DownloadFile* download_file) {
base::FilePath MakeCopyOfDownloadFile(DownloadFile* download_file) {
DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
base::FilePath temp_file_path;
if (base::CreateTemporaryFile(&temp_file_path) &&
base::CopyFile(download_file->FullPath(), temp_file_path)) {
return temp_file_path;
} else {
// Deletes the file at |temp_file_path|.
if (!base::DirectoryExists(temp_file_path))
base::DeleteFile(temp_file_path, false);
temp_file_path.clear();
if (!base::CreateTemporaryFile(&temp_file_path))
return base::FilePath();
if (!base::CopyFile(download_file->FullPath(), temp_file_path)) {
DeleteDownloadedFile(temp_file_path);
return base::FilePath();
}
return temp_file_path;
}
static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) {
void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) {
DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
download_file->Cancel();
}
......
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