Commit 88cb7aae authored by cbentzel@chromium.org's avatar cbentzel@chromium.org

Get more information about types of images being downloaded.

This adds a new enum Download.ContentImageType rather than adding additional entries to Download.ContentType.

The downside is that there is a bit more code. The upside is that we don't have to worry about the image entries getting fragmented across the Download.ContentType enum, and there is a top-level entry for images in the Download.ContentType histogram to compare against other general media types.

TEST=Download a few images, make sure Download.ContentType and Download.ContentImageType look sane.


Review URL: http://codereview.chromium.org/8734006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112711 0039d316-1c4b-4281-b951-d872f2087c98
parent 10a99b30
...@@ -171,6 +171,48 @@ static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = { ...@@ -171,6 +171,48 @@ static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = {
{"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX}, {"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX},
}; };
enum DownloadImage {
DOWNLOAD_IMAGE_UNRECOGNIZED = 0,
DOWNLOAD_IMAGE_GIF = 1,
DOWNLOAD_IMAGE_JPEG = 2,
DOWNLOAD_IMAGE_PNG = 3,
DOWNLOAD_IMAGE_TIFF = 4,
DOWNLOAD_IMAGE_ICON = 5,
DOWNLOAD_IMAGE_WEBP = 6,
DOWNLOAD_IMAGE_MAX = 7,
};
struct MimeTypeToDownloadImage {
const char* mime_type;
DownloadImage download_image;
};
static MimeTypeToDownloadImage kMapMimeTypeToDownloadImage[] = {
{"image/gif", DOWNLOAD_IMAGE_GIF},
{"image/jpeg", DOWNLOAD_IMAGE_JPEG},
{"image/png", DOWNLOAD_IMAGE_PNG},
{"image/tiff", DOWNLOAD_IMAGE_TIFF},
{"image/vnd.microsoft.icon", DOWNLOAD_IMAGE_ICON},
{"image/webp", DOWNLOAD_IMAGE_WEBP},
};
void RecordDownloadImageType(const std::string& mime_type_string) {
DownloadImage download_image = DOWNLOAD_IMAGE_UNRECOGNIZED;
// Look up exact matches.
for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadImage); ++i) {
const MimeTypeToDownloadImage& entry = kMapMimeTypeToDownloadImage[i];
if (mime_type_string == entry.mime_type) {
download_image = entry.download_image;
break;
}
}
UMA_HISTOGRAM_ENUMERATION("Download.ContentImageType",
download_image,
DOWNLOAD_IMAGE_MAX);
}
} // namespace } // namespace
void RecordDownloadMimeType(const std::string& mime_type_string) { void RecordDownloadMimeType(const std::string& mime_type_string) {
...@@ -178,8 +220,7 @@ void RecordDownloadMimeType(const std::string& mime_type_string) { ...@@ -178,8 +220,7 @@ void RecordDownloadMimeType(const std::string& mime_type_string) {
// Look up exact matches. // Look up exact matches.
for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) { for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) {
const MimeTypeToDownloadContent& entry = const MimeTypeToDownloadContent& entry = kMapMimeTypeToDownloadContent[i];
kMapMimeTypeToDownloadContent[i];
if (mime_type_string == entry.mime_type) { if (mime_type_string == entry.mime_type) {
download_content = entry.download_content; download_content = entry.download_content;
break; break;
...@@ -192,6 +233,7 @@ void RecordDownloadMimeType(const std::string& mime_type_string) { ...@@ -192,6 +233,7 @@ void RecordDownloadMimeType(const std::string& mime_type_string) {
download_content = DOWNLOAD_CONTENT_TEXT; download_content = DOWNLOAD_CONTENT_TEXT;
} else if (StartsWithASCII(mime_type_string, "image/", true)) { } else if (StartsWithASCII(mime_type_string, "image/", true)) {
download_content = DOWNLOAD_CONTENT_IMAGE; download_content = DOWNLOAD_CONTENT_IMAGE;
RecordDownloadImageType(mime_type_string);
} else if (StartsWithASCII(mime_type_string, "audio/", true)) { } else if (StartsWithASCII(mime_type_string, "audio/", true)) {
download_content = DOWNLOAD_CONTENT_AUDIO; download_content = DOWNLOAD_CONTENT_AUDIO;
} else if (StartsWithASCII(mime_type_string, "video/", true)) { } else if (StartsWithASCII(mime_type_string, "video/", true)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment