OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/download/download_stats.h" | 5 #include "content/browser/download/download_stats.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "content/browser/download/download_resource_handler.h" | 9 #include "content/browser/download/download_resource_handler.h" |
10 #include "content/browser/download/interrupt_reasons.h" | 10 #include "content/browser/download/interrupt_reasons.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 {"application/zip", DOWNLOAD_CONTENT_ARCHIVE}, | 137 {"application/zip", DOWNLOAD_CONTENT_ARCHIVE}, |
138 {"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE}, | 138 {"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE}, |
139 {"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE}, | 139 {"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE}, |
140 {"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE}, | 140 {"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE}, |
141 {"application/x-bzip", DOWNLOAD_CONTENT_ARCHIVE}, | 141 {"application/x-bzip", DOWNLOAD_CONTENT_ARCHIVE}, |
142 {"application/x-exe", DOWNLOAD_CONTENT_EXE}, | 142 {"application/x-exe", DOWNLOAD_CONTENT_EXE}, |
143 {"application/x-apple-diskimage", DOWNLOAD_CONTENT_DMG}, | 143 {"application/x-apple-diskimage", DOWNLOAD_CONTENT_DMG}, |
144 {"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX}, | 144 {"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX}, |
145 }; | 145 }; |
146 | 146 |
| 147 enum DownloadImage { |
| 148 DOWNLOAD_IMAGE_UNRECOGNIZED = 0, |
| 149 DOWNLOAD_IMAGE_GIF = 1, |
| 150 DOWNLOAD_IMAGE_JPEG = 2, |
| 151 DOWNLOAD_IMAGE_PNG = 3, |
| 152 DOWNLOAD_IMAGE_TIFF = 4, |
| 153 DOWNLOAD_IMAGE_ICON = 5, |
| 154 DOWNLOAD_IMAGE_WEBP = 6, |
| 155 DOWNLOAD_IMAGE_MAX = 7, |
| 156 }; |
| 157 |
| 158 struct MimeTypeToDownloadImage { |
| 159 const char* mime_type; |
| 160 DownloadImage download_image; |
| 161 }; |
| 162 |
| 163 static MimeTypeToDownloadImage kMapMimeTypeToDownloadImage[] = { |
| 164 {"image/gif", DOWNLOAD_IMAGE_GIF}, |
| 165 {"image/jpeg", DOWNLOAD_IMAGE_JPEG}, |
| 166 {"image/png", DOWNLOAD_IMAGE_PNG}, |
| 167 {"image/tiff", DOWNLOAD_IMAGE_TIFF}, |
| 168 {"image/vnd.microsoft.icon", DOWNLOAD_IMAGE_ICON}, |
| 169 {"image/webp", DOWNLOAD_IMAGE_WEBP}, |
| 170 }; |
| 171 |
| 172 void RecordDownloadImageType(const std::string& mime_type_string) { |
| 173 DownloadImage download_image = DOWNLOAD_IMAGE_UNRECOGNIZED; |
| 174 |
| 175 // Look up exact matches. |
| 176 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadImage); ++i) { |
| 177 const MimeTypeToDownloadImage& entry = kMapMimeTypeToDownloadImage[i]; |
| 178 if (mime_type_string == entry.mime_type) { |
| 179 download_image = entry.download_image; |
| 180 break; |
| 181 } |
| 182 } |
| 183 |
| 184 UMA_HISTOGRAM_ENUMERATION("Download.ContentImageType", |
| 185 download_image, |
| 186 DOWNLOAD_IMAGE_MAX); |
| 187 } |
| 188 |
147 } // namespace | 189 } // namespace |
148 | 190 |
149 void RecordDownloadMimeType(const std::string& mime_type_string) { | 191 void RecordDownloadMimeType(const std::string& mime_type_string) { |
150 DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED; | 192 DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED; |
151 | 193 |
152 // Look up exact matches. | 194 // Look up exact matches. |
153 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) { | 195 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) { |
154 const MimeTypeToDownloadContent& entry = | 196 const MimeTypeToDownloadContent& entry = kMapMimeTypeToDownloadContent[i]; |
155 kMapMimeTypeToDownloadContent[i]; | |
156 if (mime_type_string == entry.mime_type) { | 197 if (mime_type_string == entry.mime_type) { |
157 download_content = entry.download_content; | 198 download_content = entry.download_content; |
158 break; | 199 break; |
159 } | 200 } |
160 } | 201 } |
161 | 202 |
162 // Do partial matches. | 203 // Do partial matches. |
163 if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) { | 204 if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) { |
164 if (StartsWithASCII(mime_type_string, "text/", true)) { | 205 if (StartsWithASCII(mime_type_string, "text/", true)) { |
165 download_content = DOWNLOAD_CONTENT_TEXT; | 206 download_content = DOWNLOAD_CONTENT_TEXT; |
166 } else if (StartsWithASCII(mime_type_string, "image/", true)) { | 207 } else if (StartsWithASCII(mime_type_string, "image/", true)) { |
167 download_content = DOWNLOAD_CONTENT_IMAGE; | 208 download_content = DOWNLOAD_CONTENT_IMAGE; |
| 209 RecordDownloadImageType(mime_type_string); |
168 } else if (StartsWithASCII(mime_type_string, "audio/", true)) { | 210 } else if (StartsWithASCII(mime_type_string, "audio/", true)) { |
169 download_content = DOWNLOAD_CONTENT_AUDIO; | 211 download_content = DOWNLOAD_CONTENT_AUDIO; |
170 } else if (StartsWithASCII(mime_type_string, "video/", true)) { | 212 } else if (StartsWithASCII(mime_type_string, "video/", true)) { |
171 download_content = DOWNLOAD_CONTENT_VIDEO; | 213 download_content = DOWNLOAD_CONTENT_VIDEO; |
172 } | 214 } |
173 } | 215 } |
174 | 216 |
175 // Record the value. | 217 // Record the value. |
176 UMA_HISTOGRAM_ENUMERATION("Download.ContentType", | 218 UMA_HISTOGRAM_ENUMERATION("Download.ContentType", |
177 download_content, | 219 download_content, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 284 |
243 void RecordOpensOutstanding(int size) { | 285 void RecordOpensOutstanding(int size) { |
244 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.OpensOutstanding", | 286 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.OpensOutstanding", |
245 size, | 287 size, |
246 0/*min*/, | 288 0/*min*/, |
247 (1 << 10)/*max*/, | 289 (1 << 10)/*max*/, |
248 64/*num_buckets*/); | 290 64/*num_buckets*/); |
249 } | 291 } |
250 | 292 |
251 } // namespace download_stats | 293 } // namespace download_stats |
OLD | NEW |