summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-19 23:21:01 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-19 23:21:01 +0000
commit30307700ac157552793f3370b9dd53373015ac55 (patch)
tree593c62a5995d31e9ca8bfea0760835848604d2c9 /chrome/browser/download
parentabe92999c62ebc866b8a0451b3a1eb1d71e37391 (diff)
downloadchromium_src-30307700ac157552793f3370b9dd53373015ac55.zip
chromium_src-30307700ac157552793f3370b9dd53373015ac55.tar.gz
chromium_src-30307700ac157552793f3370b9dd53373015ac55.tar.bz2
Add enum histogram for dangerous download save or discard.
BUG=79490 TEST=save or discard a dangerous download, check about:histograms Review URL: http://codereview.chromium.org/6849004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82186 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r--chrome/browser/download/download_browsertest.cc2
-rw-r--r--chrome/browser/download/download_item.cc34
-rw-r--r--chrome/browser/download/download_item.h25
-rw-r--r--chrome/browser/download/download_manager.cc2
4 files changed, 51 insertions, 12 deletions
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index 99440ba..55a9e6e 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -1172,7 +1172,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) {
EXPECT_TRUE(IsDownloadUIVisible(browser()));
// Cancel the download and wait for download system quiesce.
- downloads[0]->Remove(/* delete_on_disk = */ true);
+ downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
scoped_refptr<DownloadsFlushObserver> flush_observer(
new DownloadsFlushObserver(browser()->profile()->GetDownloadManager()));
flush_observer->WaitForFlush();
diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc
index 99b6b9d..56baada 100644
--- a/chrome/browser/download/download_item.cc
+++ b/chrome/browser/download/download_item.cc
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/format_macros.h"
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "base/stringprintf.h"
#include "base/timer.h"
#include "base/utf_string_conversions.h"
@@ -299,6 +300,9 @@ void DownloadItem::ShowDownloadInShell() {
}
void DownloadItem::DangerousDownloadValidated() {
+ UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated",
+ danger_type_,
+ DANGEROUS_TYPE_MAX);
download_manager_->DangerousDownloadValidated(this);
}
@@ -408,14 +412,32 @@ void DownloadItem::Interrupted(int64 size, int os_error) {
UpdateObservers();
}
-void DownloadItem::Remove(bool delete_on_disk) {
+void DownloadItem::Delete(DeleteReason reason) {
+ switch (reason) {
+ case DELETE_DUE_TO_USER_DISCARD:
+ UMA_HISTOGRAM_ENUMERATION("Download.UserDiscard",
+ danger_type_,
+ DANGEROUS_TYPE_MAX);
+ break;
+ case DELETE_DUE_TO_BROWSER_SHUTDOWN:
+ UMA_HISTOGRAM_ENUMERATION("Download.Discard",
+ danger_type_,
+ DANGEROUS_TYPE_MAX);
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableFunction(&DeleteDownloadedFile, full_path_));
+ Remove();
+ // We have now been deleted.
+}
+
+void DownloadItem::Remove() {
Cancel(true);
state_ = REMOVING;
- if (delete_on_disk) {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableFunction(&DeleteDownloadedFile, full_path_));
- }
download_manager_->RemoveDownload(db_handle_);
// We have now been deleted.
}
diff --git a/chrome/browser/download/download_item.h b/chrome/browser/download/download_item.h
index e90dbf51..5340027 100644
--- a/chrome/browser/download/download_item.h
+++ b/chrome/browser/download/download_item.h
@@ -62,6 +62,8 @@ class DownloadItem {
DANGEROUS_BUT_VALIDATED // Dangerous but the user confirmed the download.
};
+ // This enum is used by histograms. Do not change the ordering or remove
+ // items.
enum DangerType {
NOT_DANGEROUS = 0,
@@ -70,7 +72,17 @@ class DownloadItem {
DANGEROUS_FILE,
// Safebrowsing service shows this URL leads to malicious file download.
- DANGEROUS_URL
+ DANGEROUS_URL,
+
+ // Memory space for histograms is determined by the max.
+ // ALWAYS ADD NEW VALUES BEFORE THIS ONE.
+ DANGEROUS_TYPE_MAX
+ };
+
+ // Reason for deleting the download. Passed to Delete().
+ enum DeleteReason {
+ DELETE_DUE_TO_BROWSER_SHUTDOWN = 0,
+ DELETE_DUE_TO_USER_DISCARD
};
// Interface that observers of a particular download must implement in order
@@ -156,9 +168,14 @@ class DownloadItem {
// code that the operation received.
void Interrupted(int64 size, int os_error);
- // The user wants to remove the download from the views and history. If
- // |delete_file| is true, the file is deleted on the disk.
- void Remove(bool delete_file);
+ // Deletes the file from disk and removes the download from the views and
+ // history. |user| should be true if this is the result of the user clicking
+ // the discard button, and false if it is being deleted for other reasons like
+ // browser shutdown.
+ void Delete(DeleteReason reason);
+
+ // Removes the download from the views and history.
+ void Remove();
// Simple calculation of the amount of time remaining to completion. Fills
// |*remaining| with the amount of time remaining if successful. Fails and
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 3d49a46..45db448 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -100,7 +100,7 @@ void DownloadManager::Shutdown() {
// so the only thing we know after calling this function is that
// the download was deleted if-and-only-if it was removed
// from all queues.
- download->Remove(true);
+ download->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN);
} else if (download->IsPartialDownload()) {
download->Cancel(false);
download_history_->UpdateEntry(download);