summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 20:52:35 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 20:52:35 +0000
commit0d118595241314f3e4ad30af454a93e6bfdf46d3 (patch)
tree36e34b47e058717d615446002bc8434f76311906 /chrome/browser
parenta3a62191e80559303e48f648d9b8f260b0aad3a3 (diff)
downloadchromium_src-0d118595241314f3e4ad30af454a93e6bfdf46d3.zip
chromium_src-0d118595241314f3e4ad30af454a93e6bfdf46d3.tar.gz
chromium_src-0d118595241314f3e4ad30af454a93e6bfdf46d3.tar.bz2
Record type of content being downloaded.
BUG=None TEST=None Review URL: http://codereview.chromium.org/7538007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/download/download_util.cc76
-rw-r--r--chrome/browser/download/download_util.h3
-rw-r--r--chrome/browser/renderer_host/download_resource_handler.cc1
3 files changed, 80 insertions, 0 deletions
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index e1db3ff..821624d 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -392,6 +392,82 @@ void RecordDownloadInterrupted(int error, int64 received, int64 total) {
UMA_HISTOGRAM_BOOLEAN("Download.InterruptedUnknownSize", unknown_size);
}
+namespace {
+
+enum DownloadContent {
+ DOWNLOAD_CONTENT_UNRECOGNIZED = 0,
+ DOWNLOAD_CONTENT_TEXT = 1,
+ DOWNLOAD_CONTENT_IMAGE = 2,
+ DOWNLOAD_CONTENT_AUDIO = 3,
+ DOWNLOAD_CONTENT_VIDEO = 4,
+ DOWNLOAD_CONTENT_OCTET_STREAM = 5,
+ DOWNLOAD_CONTENT_PDF = 6,
+ DOWNLOAD_CONTENT_DOC = 7,
+ DOWNLOAD_CONTENT_XLS = 8,
+ DOWNLOAD_CONTENT_PPT = 9,
+ DOWNLOAD_CONTENT_ARCHIVE = 10,
+ DOWNLOAD_CONTENT_EXE = 11,
+ DOWNLOAD_CONTENT_DMG = 12,
+ DOWNLOAD_CONTENT_CRX = 13,
+ DOWNLOAD_CONTENT_MAX = 14,
+};
+
+struct MimeTypeToDownloadContent {
+ const char* mime_type;
+ DownloadContent download_content;
+};
+
+static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = {
+ {"application/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
+ {"binary/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
+ {"application/pdf", DOWNLOAD_CONTENT_PDF},
+ {"application/msword", DOWNLOAD_CONTENT_DOC},
+ {"application/vnd.ms-excel", DOWNLOAD_CONTENT_XLS},
+ {"application/vns.ms-powerpoint", DOWNLOAD_CONTENT_PPT},
+ {"application/zip", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-bzip", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-exe", DOWNLOAD_CONTENT_EXE},
+ {"application/x-apple-diskimage", DOWNLOAD_CONTENT_DMG},
+ {"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX},
+};
+
+} // namespace
+
+void RecordDownloadMimeType(const std::string& mime_type_string) {
+ DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED;
+
+ // Look up exact matches.
+ for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) {
+ const MimeTypeToDownloadContent& entry =
+ kMapMimeTypeToDownloadContent[i];
+ if (mime_type_string == entry.mime_type) {
+ download_content = entry.download_content;
+ break;
+ }
+ }
+
+ // Do partial matches.
+ if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) {
+ if (StartsWithASCII(mime_type_string, "text/", true)) {
+ download_content = DOWNLOAD_CONTENT_TEXT;
+ } else if (StartsWithASCII(mime_type_string, "image/", true)) {
+ download_content = DOWNLOAD_CONTENT_IMAGE;
+ } else if (StartsWithASCII(mime_type_string, "audio/", true)) {
+ download_content = DOWNLOAD_CONTENT_AUDIO;
+ } else if (StartsWithASCII(mime_type_string, "video/", true)) {
+ download_content = DOWNLOAD_CONTENT_VIDEO;
+ }
+ }
+
+ // Record the value.
+ UMA_HISTOGRAM_ENUMERATION("Download.ContentType",
+ download_content,
+ DOWNLOAD_CONTENT_MAX);
+}
+
// Download progress painting --------------------------------------------------
// Common bitmaps used for download progress animations. We load them once the
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 644853f..d36762d4b0 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -174,6 +174,9 @@ void RecordDownloadCompleted(const base::TimeTicks& start);
// Record INTERRUPTED_COUNT, |error|, |received| and |total| bytes.
void RecordDownloadInterrupted(int error, int64 received, int64 total);
+// Records the mime type of the download.
+void RecordDownloadMimeType(const std::string& mime_type);
+
// Paint the common download animation progress foreground and background,
// clipping the foreground to 'percent' full. If percent is -1, then we don't
// know the total size, so we just draw a rotating segment until we're done.
diff --git a/chrome/browser/renderer_host/download_resource_handler.cc b/chrome/browser/renderer_host/download_resource_handler.cc
index f35d5e4..289d150 100644
--- a/chrome/browser/renderer_host/download_resource_handler.cc
+++ b/chrome/browser/renderer_host/download_resource_handler.cc
@@ -95,6 +95,7 @@ bool DownloadResourceHandler::OnResponseStarted(int request_id,
global_id_.request_id);
info->content_disposition = content_disposition_;
info->mime_type = response->response_head.mime_type;
+ download_util::RecordDownloadMimeType(info->mime_type);
// TODO(ahendrickson) -- Get the last modified time and etag, so we can
// resume downloading.