Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: content/browser/download/download_item_impl.cc

Issue 2439533002: Download Feedback Service should upload all eligible downloads (Closed)
Patch Set: fix comments and nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f5a2ec8e5a6c6c8b916c87066693a47ab47155c0 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -93,6 +93,17 @@ 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;
+ else
+ return base::FilePath();
asanka 2016/11/01 21:09:23 Can this branch delete the file at |temp_file_path
Jialiu Lin 2016/11/03 20:16:50 Done.
+}
+
static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
download_file->Cancel();
@@ -299,23 +310,32 @@ 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());
asanka 2016/11/01 20:58:58 Can you also DCHECK AllDataSaved() ? It appears t
Jialiu Lin 2016/11/03 20:16:50 Done.
- 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();
+ // We have now been deleted.
+ } else if (download_file_) {
asanka 2016/11/01 20:58:58 If there's no download_file_, then you can callbac
Jialiu Lin 2016/11/03 20:16:50 Done.
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 +1395,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_);

Powered by Google App Engine
This is Rietveld 408576698