Chromium Code Reviews| Index: chrome/browser/download/download_util.cc |
| diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc |
| index e1db3ffd38fe7e253f00c1b64ea722df4033df25..dec64a7c9e7e3dd1f3514187dc6760073a81a7c9 100644 |
| --- a/chrome/browser/download/download_util.cc |
| +++ b/chrome/browser/download/download_util.cc |
| @@ -392,6 +392,75 @@ void RecordDownloadInterrupted(int error, int64 received, int64 total) { |
| UMA_HISTOGRAM_BOOLEAN("Download.InterruptedUnknownSize", unknown_size); |
| } |
| +namespace { |
| + |
| +enum DownloadContent { |
|
benjhayden
2011/08/01 18:53:03
Do all compilers number enums from 0 counting upwa
cbentzel
2011/08/01 19:00:33
Not guaranteed - thanks for the catch.
|
| + DOWNLOAD_CONTENT_TEXT, |
| + DOWNLOAD_CONTENT_IMAGE, |
| + DOWNLOAD_CONTENT_AUDIO, |
| + DOWNLOAD_CONTENT_VIDEO, |
| + DOWNLOAD_CONTENT_OCTET_STREAM, |
| + DOWNLOAD_CONTENT_PDF, |
| + DOWNLOAD_CONTENT_DOC, |
| + DOWNLOAD_CONTENT_XLS, |
| + DOWNLOAD_CONTENT_PPT, |
| + DOWNLOAD_CONTENT_ARCHIVE, |
| + DOWNLOAD_CONTENT_UNRECOGNIZED, |
| + DOWNLOAD_CONTENT_MAX, |
| +}; |
| + |
| +struct MimeTypeToDownloadContent { |
| + const char* mime_type; |
| + DownloadContent download_content; |
| +}; |
| + |
| +static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = { |
|
benjhayden
2011/08/01 18:53:03
Could you add exe, dmg, crx, and bzip?
exe: appli
cbentzel
2011/08/01 19:00:33
Will do. Hoping I don't need to move to binary sea
cbentzel
2011/08/01 21:06:18
Do you know how frequently these happen? I mostly
benjhayden
2011/08/01 21:48:12
No idea. I just copied it from some website. Don't
|
| + {"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}, |
| +}; |
| + |
| +} // 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 |