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

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 and get rid of Delete() 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 6f06e3252d6d50b2bc89f8cd68d821edf547cb3b..dabce4bbd7268682ac1ecf9245d1c953e5903ba0 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());
@@ -285,9 +288,7 @@ void DownloadItemImpl::DangerousDownloadValidated() {
if (GetState() != IN_PROGRESS)
return;
- UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated",
- GetDangerType(),
- DOWNLOAD_DANGER_TYPE_MAX);
+ RecordDangerousDownloadAccept(GetDangerType());
danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED;
@@ -300,6 +301,23 @@ void DownloadItemImpl::DangerousDownloadValidated() {
MaybeCompleteDownload();
}
+void DownloadItemImpl::StealDangerousDownload(
+ const AcquireFileCallback& callback) {
+ VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(IsDangerous());
+ DCHECK(download_file_);
+
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&DownloadFileDetach, base::Passed(&download_file_)),
+ callback);
+ current_path_.clear();
+ Remove();
+ // We have now been deleted.
+}
+
void DownloadItemImpl::Pause() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -350,9 +368,15 @@ void DownloadItemImpl::Cancel(bool user_cancel) {
return;
}
- last_reason_ = user_cancel ?
- DOWNLOAD_INTERRUPT_REASON_USER_CANCELED :
- DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN;
+ if (IsDangerous()) {
+ RecordDangerousDownloadDiscard(
+ user_cancel ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION
Randy Smith (Not in Mondays) 2013/05/24 02:06:16 Hmmm. Is this changing the semantics of the UMA?
asanka 2013/05/24 20:32:47 It's incorrect to do UMA in both Remove() and Canc
+ : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN,
+ GetDangerType());
+ }
+
+ last_reason_ = user_cancel ? DOWNLOAD_INTERRUPT_REASON_USER_CANCELED
+ : DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN;
RecordDownloadCount(CANCELLED_COUNT);
@@ -372,39 +396,14 @@ void DownloadItemImpl::Cancel(bool user_cancel) {
TransitionTo(CANCELLED_INTERNAL);
}
-void DownloadItemImpl::Delete(DeleteReason reason) {
+void DownloadItemImpl::Remove() {
VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- switch (reason) {
- case DELETE_DUE_TO_USER_DISCARD:
- UMA_HISTOGRAM_ENUMERATION(
- "Download.UserDiscard", GetDangerType(),
- DOWNLOAD_DANGER_TYPE_MAX);
- break;
- case DELETE_DUE_TO_BROWSER_SHUTDOWN:
- UMA_HISTOGRAM_ENUMERATION(
- "Download.Discard", GetDangerType(),
- DOWNLOAD_DANGER_TYPE_MAX);
- break;
- default:
- NOTREACHED();
- }
-
- // 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) {
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- base::Bind(&DeleteDownloadedFile, current_path_));
- current_path_.clear();
+ if (IsDangerous()) {
+ RecordDangerousDownloadDiscard(DOWNLOAD_DISCARD_DUE_TO_USER_ACTION,
+ GetDangerType());
}
- Remove();
- // We have now been deleted.
-}
-
-void DownloadItemImpl::Remove() {
- VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Remove the intermediate file if we are removing an interrupted download.
// Continuable interruptions leave the intermediate file around. However, the
@@ -1399,9 +1398,11 @@ void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) {
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::FILE,
+ FROM_HERE,
+ base::Bind(base::IgnoreResult(&DownloadFileDetach),
+ // Will be deleted at end of task execution.
+ 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
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698