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

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

Issue 14947007: [Downloads] Allow acquiring dangerous download file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename methods for consistency Created 7 years, 7 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 27c170796605127ddb40b24c0507a9dbc4d82c06..5c3620fa3e401210b4b1b134ca2fa6d98669c1bb 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -68,9 +68,12 @@ void DeleteDownloadedFile(const base::FilePath& path) {
// 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 void DownloadFileDetach(scoped_ptr<DownloadFile> download_file) {
+static base::FilePath DownloadFileDetach(
+ scoped_ptr<DownloadFile> download_file) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ base::FilePath full_path = download_file->FullPath();
download_file->Detach();
+ return full_path;
}
static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) {
@@ -275,7 +278,7 @@ void DownloadItemImpl::UpdateObservers() {
FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this));
}
-void DownloadItemImpl::DangerousDownloadValidated() {
+void DownloadItemImpl::ValidateDangerousDownload() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK_EQ(IN_PROGRESS, GetState());
DCHECK(IsDangerous());
@@ -372,9 +375,12 @@ void DownloadItemImpl::Cancel(bool user_cancel) {
TransitionTo(CANCELLED_INTERNAL);
}
-void DownloadItemImpl::Delete(DeleteReason reason) {
+void DownloadItemImpl::DiscardDangerousDownload(
+ DeleteReason reason,
+ const AcquireFileCallback& callback) {
VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(IsDangerous());
switch (reason) {
case DELETE_DUE_TO_USER_DISCARD:
@@ -391,6 +397,19 @@ void DownloadItemImpl::Delete(DeleteReason reason) {
NOTREACHED();
}
+ if (!callback.is_null()) {
+ 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();
+ }
+
// Delete the file if it exists and is not owned by a DownloadFile object.
// (In the latter case the DownloadFile object will delete it on cancel.)
if (!current_path_.empty() && download_file_.get() == NULL) {
@@ -1405,10 +1424,11 @@ void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) {
// current_path_.
current_path_.clear();
} else {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- // Will be deleted at end of task execution.
- base::Bind(&DownloadFileDetach, base::Passed(&download_file_)));
+ BrowserThread::PostTask(BrowserThread::FILE,
+ FROM_HERE,
+ // Will be deleted at end of task execution.
+ base::Bind(base::IgnoreResult(&DownloadFileDetach),
+ base::Passed(&download_file_)));
}
// Don't accept any more messages from the DownloadFile, and null
// out any previous "all data received". This also breaks links to

Powered by Google App Engine
This is Rietveld 408576698