Chromium Code Reviews| Index: content/browser/download/download_item_impl.cc |
| diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc |
| index f2494eb3fc479ad88b90c3c71d59901c646be2cd..33b4983e939d3ec762f369a8da4b39265e7224be 100644 |
| --- a/content/browser/download/download_item_impl.cc |
| +++ b/content/browser/download/download_item_impl.cc |
| @@ -93,6 +93,24 @@ static base::FilePath DownloadFileDetach( |
| return full_path; |
| } |
| +static base::FilePath MakeCopyOfDownloadFile( |
| + DownloadFile* download_file) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + base::FilePath temp_file_path; |
| + if(base::CreateTemporaryFile(&temp_file_path) && |
| + base::CopyFile(download_file->FullPath(), temp_file_path)) { |
| + return temp_file_path; |
| + } |
|
asanka
2016/11/07 16:01:55
} else {
clang-format should've fixed this for yo
Jialiu Lin
2016/11/14 20:57:39
Done.
|
| + else { |
| + // Deletes the file at |temp_file_path| if it exists. |
| + if (base::PathExists(temp_file_path)) { |
|
asanka
2016/11/07 16:01:55
DeleteFile is a no-op if the file doesn't exist an
Jialiu Lin
2016/11/14 20:57:39
Done.
|
| + DeleteFile(temp_file_path, false); |
| + } |
| + temp_file_path.clear(); |
| + return base::FilePath(); |
| + } |
| +} |
| + |
| static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { |
| DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| download_file->Cancel(); |
| @@ -299,23 +317,35 @@ void DownloadItemImpl::ValidateDangerousDownload() { |
| } |
| void DownloadItemImpl::StealDangerousDownload( |
| + bool delete_file_afterward, |
| const AcquireFileCallback& callback) { |
| DVLOG(20) << __func__ << "() download = " << DebugString(true); |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| DCHECK(IsDangerous()); |
| + DCHECK(AllDataSaved()); |
| - if (download_file_) { |
| + if (delete_file_afterward) { |
| + if (download_file_){ |
| + BrowserThread::PostTaskAndReplyWithResult( |
| + BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), |
| + callback); |
| + } else { |
| + callback.Run(current_path_); |
| + } |
| + current_path_.clear(); |
| + Remove(); |
| + // Download item has now been deleted. |
| + } else if (download_file_) { |
| BrowserThread::PostTaskAndReplyWithResult( |
| BrowserThread::FILE, |
| FROM_HERE, |
| - base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), |
| + base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), |
| callback); |
| } else { |
| callback.Run(current_path_); |
| } |
| - current_path_.clear(); |
| - Remove(); |
| - // We have now been deleted. |
| } |
| void DownloadItemImpl::Pause() { |
| @@ -1375,7 +1405,6 @@ void DownloadItemImpl::MaybeCompleteDownload() { |
| base::Bind(&DownloadItemImpl::MaybeCompleteDownload, |
| weak_ptr_factory_.GetWeakPtr()))) |
| return; |
| - |
| // Confirm we're in the proper set of states to be here; have all data, have a |
| // history handle, (validated or safe). |
| DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); |