Process Alt-Svc headers.
[chromium-blink-merge.git] / content / browser / download / download_stats.cc
blob248ece0954c7d2de8564234033f59875894c262d
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/download/download_stats.h"
7 #include "base/metrics/histogram.h"
8 #include "base/metrics/sparse_histogram.h"
9 #include "base/strings/string_util.h"
10 #include "content/browser/download/download_resource_handler.h"
11 #include "content/public/browser/download_interrupt_reasons.h"
12 #include "net/http/http_content_disposition.h"
14 namespace content {
16 namespace {
18 // All possible error codes from the network module. Note that the error codes
19 // are all positive (since histograms expect positive sample values).
20 const int kAllInterruptReasonCodes[] = {
21 #define INTERRUPT_REASON(label, value) (value),
22 #include "content/public/browser/download_interrupt_reason_values.h"
23 #undef INTERRUPT_REASON
26 // These values are based on net::HttpContentDisposition::ParseResult values.
27 // Values other than HEADER_PRESENT and IS_VALID are only measured if |IS_VALID|
28 // is true.
29 enum ContentDispositionCountTypes {
30 // Count of downloads which had a Content-Disposition headers. The total
31 // number of downloads is measured by UNTHROTTLED_COUNT.
32 CONTENT_DISPOSITION_HEADER_PRESENT = 0,
34 // Either 'filename' or 'filename*' attributes were valid and
35 // yielded a non-empty filename.
36 CONTENT_DISPOSITION_IS_VALID,
38 // The following enum values correspond to
39 // net::HttpContentDisposition::ParseResult.
40 CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE,
41 CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE,
43 CONTENT_DISPOSITION_HAS_NAME, // Obsolete; kept for UMA compatiblity.
45 CONTENT_DISPOSITION_HAS_FILENAME,
46 CONTENT_DISPOSITION_HAS_EXT_FILENAME,
47 CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS,
48 CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS,
49 CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS,
51 CONTENT_DISPOSITION_HAS_NAME_ONLY, // Obsolete; kept for UMA compatiblity.
53 CONTENT_DISPOSITION_LAST_ENTRY
56 void RecordContentDispositionCount(ContentDispositionCountTypes type,
57 bool record) {
58 if (!record)
59 return;
60 UMA_HISTOGRAM_ENUMERATION(
61 "Download.ContentDisposition", type, CONTENT_DISPOSITION_LAST_ENTRY);
64 void RecordContentDispositionCountFlag(
65 ContentDispositionCountTypes type,
66 int flags_to_test,
67 net::HttpContentDisposition::ParseResultFlags flag) {
68 RecordContentDispositionCount(type, (flags_to_test & flag) == flag);
71 // Do not insert, delete, or reorder; this is being histogrammed. Append only.
72 // All of the download_extensions.cc file types should be in this list.
73 // TODO(asanka): This enum and the UMA metrics for dangerous/malicious downloads
74 // should be moved to //chrome/browser/download.
75 const base::FilePath::CharType* kDangerousFileTypes[] = {
76 FILE_PATH_LITERAL(".ad"),
77 FILE_PATH_LITERAL(".ade"),
78 FILE_PATH_LITERAL(".adp"),
79 FILE_PATH_LITERAL(".ah"),
80 FILE_PATH_LITERAL(".apk"),
81 FILE_PATH_LITERAL(".app"),
82 FILE_PATH_LITERAL(".application"),
83 FILE_PATH_LITERAL(".asp"),
84 FILE_PATH_LITERAL(".asx"),
85 FILE_PATH_LITERAL(".bas"),
86 FILE_PATH_LITERAL(".bash"),
87 FILE_PATH_LITERAL(".bat"),
88 FILE_PATH_LITERAL(".cfg"),
89 FILE_PATH_LITERAL(".chi"),
90 FILE_PATH_LITERAL(".chm"),
91 FILE_PATH_LITERAL(".class"),
92 FILE_PATH_LITERAL(".cmd"),
93 FILE_PATH_LITERAL(".com"),
94 FILE_PATH_LITERAL(".command"),
95 FILE_PATH_LITERAL(".crt"),
96 FILE_PATH_LITERAL(".crx"),
97 FILE_PATH_LITERAL(".csh"),
98 FILE_PATH_LITERAL(".deb"),
99 FILE_PATH_LITERAL(".dex"),
100 FILE_PATH_LITERAL(".dll"),
101 FILE_PATH_LITERAL(".drv"),
102 FILE_PATH_LITERAL(".exe"),
103 FILE_PATH_LITERAL(".fxp"),
104 FILE_PATH_LITERAL(".grp"),
105 FILE_PATH_LITERAL(".hlp"),
106 FILE_PATH_LITERAL(".hta"),
107 FILE_PATH_LITERAL(".htm"),
108 FILE_PATH_LITERAL(".html"),
109 FILE_PATH_LITERAL(".htt"),
110 FILE_PATH_LITERAL(".inf"),
111 FILE_PATH_LITERAL(".ini"),
112 FILE_PATH_LITERAL(".ins"),
113 FILE_PATH_LITERAL(".isp"),
114 FILE_PATH_LITERAL(".jar"),
115 FILE_PATH_LITERAL(".jnlp"),
116 FILE_PATH_LITERAL(".user.js"),
117 FILE_PATH_LITERAL(".js"),
118 FILE_PATH_LITERAL(".jse"),
119 FILE_PATH_LITERAL(".ksh"),
120 FILE_PATH_LITERAL(".lnk"),
121 FILE_PATH_LITERAL(".local"),
122 FILE_PATH_LITERAL(".mad"),
123 FILE_PATH_LITERAL(".maf"),
124 FILE_PATH_LITERAL(".mag"),
125 FILE_PATH_LITERAL(".mam"),
126 FILE_PATH_LITERAL(".manifest"),
127 FILE_PATH_LITERAL(".maq"),
128 FILE_PATH_LITERAL(".mar"),
129 FILE_PATH_LITERAL(".mas"),
130 FILE_PATH_LITERAL(".mat"),
131 FILE_PATH_LITERAL(".mau"),
132 FILE_PATH_LITERAL(".mav"),
133 FILE_PATH_LITERAL(".maw"),
134 FILE_PATH_LITERAL(".mda"),
135 FILE_PATH_LITERAL(".mdb"),
136 FILE_PATH_LITERAL(".mde"),
137 FILE_PATH_LITERAL(".mdt"),
138 FILE_PATH_LITERAL(".mdw"),
139 FILE_PATH_LITERAL(".mdz"),
140 FILE_PATH_LITERAL(".mht"),
141 FILE_PATH_LITERAL(".mhtml"),
142 FILE_PATH_LITERAL(".mmc"),
143 FILE_PATH_LITERAL(".mof"),
144 FILE_PATH_LITERAL(".msc"),
145 FILE_PATH_LITERAL(".msh"),
146 FILE_PATH_LITERAL(".mshxml"),
147 FILE_PATH_LITERAL(".msi"),
148 FILE_PATH_LITERAL(".msp"),
149 FILE_PATH_LITERAL(".mst"),
150 FILE_PATH_LITERAL(".ocx"),
151 FILE_PATH_LITERAL(".ops"),
152 FILE_PATH_LITERAL(".pcd"),
153 FILE_PATH_LITERAL(".pif"),
154 FILE_PATH_LITERAL(".pkg"),
155 FILE_PATH_LITERAL(".pl"),
156 FILE_PATH_LITERAL(".plg"),
157 FILE_PATH_LITERAL(".prf"),
158 FILE_PATH_LITERAL(".prg"),
159 FILE_PATH_LITERAL(".pst"),
160 FILE_PATH_LITERAL(".py"),
161 FILE_PATH_LITERAL(".pyc"),
162 FILE_PATH_LITERAL(".pyw"),
163 FILE_PATH_LITERAL(".rb"),
164 FILE_PATH_LITERAL(".reg"),
165 FILE_PATH_LITERAL(".rpm"),
166 FILE_PATH_LITERAL(".scf"),
167 FILE_PATH_LITERAL(".scr"),
168 FILE_PATH_LITERAL(".sct"),
169 FILE_PATH_LITERAL(".sh"),
170 FILE_PATH_LITERAL(".shar"),
171 FILE_PATH_LITERAL(".shb"),
172 FILE_PATH_LITERAL(".shs"),
173 FILE_PATH_LITERAL(".shtm"),
174 FILE_PATH_LITERAL(".shtml"),
175 FILE_PATH_LITERAL(".spl"),
176 FILE_PATH_LITERAL(".svg"),
177 FILE_PATH_LITERAL(".swf"),
178 FILE_PATH_LITERAL(".sys"),
179 FILE_PATH_LITERAL(".tcsh"),
180 FILE_PATH_LITERAL(".url"),
181 FILE_PATH_LITERAL(".vb"),
182 FILE_PATH_LITERAL(".vbe"),
183 FILE_PATH_LITERAL(".vbs"),
184 FILE_PATH_LITERAL(".vsd"),
185 FILE_PATH_LITERAL(".vsmacros"),
186 FILE_PATH_LITERAL(".vss"),
187 FILE_PATH_LITERAL(".vst"),
188 FILE_PATH_LITERAL(".vsw"),
189 FILE_PATH_LITERAL(".ws"),
190 FILE_PATH_LITERAL(".wsc"),
191 FILE_PATH_LITERAL(".wsf"),
192 FILE_PATH_LITERAL(".wsh"),
193 FILE_PATH_LITERAL(".xbap"),
194 FILE_PATH_LITERAL(".xht"),
195 FILE_PATH_LITERAL(".xhtm"),
196 FILE_PATH_LITERAL(".xhtml"),
197 FILE_PATH_LITERAL(".xml"),
198 FILE_PATH_LITERAL(".xsl"),
199 FILE_PATH_LITERAL(".xslt"),
200 FILE_PATH_LITERAL(".website"),
201 FILE_PATH_LITERAL(".msh1"),
202 FILE_PATH_LITERAL(".msh2"),
203 FILE_PATH_LITERAL(".msh1xml"),
204 FILE_PATH_LITERAL(".msh2xml"),
205 FILE_PATH_LITERAL(".ps1"),
206 FILE_PATH_LITERAL(".ps1xml"),
207 FILE_PATH_LITERAL(".ps2"),
208 FILE_PATH_LITERAL(".ps2xml"),
209 FILE_PATH_LITERAL(".psc1"),
210 FILE_PATH_LITERAL(".psc2"),
211 FILE_PATH_LITERAL(".xnk"),
214 // Maps extensions to their matching UMA histogram int value.
215 int GetDangerousFileType(const base::FilePath& file_path) {
216 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) {
217 if (file_path.MatchesExtension(kDangerousFileTypes[i]))
218 return i + 1;
220 return 0; // Unknown extension.
223 } // namespace
225 void RecordDownloadCount(DownloadCountTypes type) {
226 UMA_HISTOGRAM_ENUMERATION(
227 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
230 void RecordDownloadSource(DownloadSource source) {
231 UMA_HISTOGRAM_ENUMERATION(
232 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY);
235 void RecordDownloadCompleted(const base::TimeTicks& start, int64 download_len) {
236 RecordDownloadCount(COMPLETED_COUNT);
237 UMA_HISTOGRAM_LONG_TIMES("Download.Time", (base::TimeTicks::Now() - start));
238 int64 max = 1024 * 1024 * 1024; // One Terabyte.
239 download_len /= 1024; // In Kilobytes
240 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.DownloadSize",
241 download_len,
243 max,
244 256);
247 void RecordDownloadInterrupted(DownloadInterruptReason reason,
248 int64 received,
249 int64 total) {
250 RecordDownloadCount(INTERRUPTED_COUNT);
251 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
252 "Download.InterruptedReason",
253 reason,
254 base::CustomHistogram::ArrayToCustomRanges(
255 kAllInterruptReasonCodes, arraysize(kAllInterruptReasonCodes)));
257 // The maximum should be 2^kBuckets, to have the logarithmic bucket
258 // boundaries fall on powers of 2.
259 static const int kBuckets = 30;
260 static const int64 kMaxKb = 1 << kBuckets; // One Terabyte, in Kilobytes.
261 int64 delta_bytes = total - received;
262 bool unknown_size = total <= 0;
263 int64 received_kb = received / 1024;
264 int64 total_kb = total / 1024;
265 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedReceivedSizeK",
266 received_kb,
268 kMaxKb,
269 kBuckets);
270 if (!unknown_size) {
271 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedTotalSizeK",
272 total_kb,
274 kMaxKb,
275 kBuckets);
276 if (delta_bytes == 0) {
277 RecordDownloadCount(INTERRUPTED_AT_END_COUNT);
278 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
279 "Download.InterruptedAtEndReason",
280 reason,
281 base::CustomHistogram::ArrayToCustomRanges(
282 kAllInterruptReasonCodes,
283 arraysize(kAllInterruptReasonCodes)));
284 } else if (delta_bytes > 0) {
285 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedOverrunBytes",
286 delta_bytes,
288 kMaxKb,
289 kBuckets);
290 } else {
291 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedUnderrunBytes",
292 -delta_bytes,
294 kMaxKb,
295 kBuckets);
299 UMA_HISTOGRAM_BOOLEAN("Download.InterruptedUnknownSize", unknown_size);
302 void RecordMaliciousDownloadClassified(DownloadDangerType danger_type) {
303 UMA_HISTOGRAM_ENUMERATION("Download.MaliciousDownloadClassified",
304 danger_type,
305 DOWNLOAD_DANGER_TYPE_MAX);
308 void RecordDangerousDownloadAccept(DownloadDangerType danger_type,
309 const base::FilePath& file_path) {
310 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated",
311 danger_type,
312 DOWNLOAD_DANGER_TYPE_MAX);
313 if (danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE) {
314 UMA_HISTOGRAM_SPARSE_SLOWLY(
315 "Download.DangerousFile.DangerousDownloadValidated",
316 GetDangerousFileType(file_path));
320 void RecordDangerousDownloadDiscard(DownloadDiscardReason reason,
321 DownloadDangerType danger_type,
322 const base::FilePath& file_path) {
323 switch (reason) {
324 case DOWNLOAD_DISCARD_DUE_TO_USER_ACTION:
325 UMA_HISTOGRAM_ENUMERATION(
326 "Download.UserDiscard", danger_type, DOWNLOAD_DANGER_TYPE_MAX);
327 if (danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE) {
328 UMA_HISTOGRAM_SPARSE_SLOWLY("Download.DangerousFile.UserDiscard",
329 GetDangerousFileType(file_path));
331 break;
332 case DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN:
333 UMA_HISTOGRAM_ENUMERATION(
334 "Download.Discard", danger_type, DOWNLOAD_DANGER_TYPE_MAX);
335 if (danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE) {
336 UMA_HISTOGRAM_SPARSE_SLOWLY("Download.DangerousFile.Discard",
337 GetDangerousFileType(file_path));
339 break;
340 default:
341 NOTREACHED();
345 void RecordDownloadWriteSize(size_t data_len) {
346 int max = 1024 * 1024; // One Megabyte.
347 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.WriteSize", data_len, 1, max, 256);
350 void RecordDownloadWriteLoopCount(int count) {
351 UMA_HISTOGRAM_ENUMERATION("Download.WriteLoopCount", count, 20);
354 void RecordAcceptsRanges(const std::string& accepts_ranges,
355 int64 download_len,
356 bool has_strong_validator) {
357 int64 max = 1024 * 1024 * 1024; // One Terabyte.
358 download_len /= 1024; // In Kilobytes
359 static const int kBuckets = 50;
361 if (base::LowerCaseEqualsASCII(accepts_ranges, "none")) {
362 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.AcceptRangesNone.KBytes",
363 download_len,
365 max,
366 kBuckets);
367 } else if (base::LowerCaseEqualsASCII(accepts_ranges, "bytes")) {
368 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.AcceptRangesBytes.KBytes",
369 download_len,
371 max,
372 kBuckets);
373 if (has_strong_validator)
374 RecordDownloadCount(STRONG_VALIDATOR_AND_ACCEPTS_RANGES);
375 } else {
376 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.AcceptRangesMissingOrInvalid.KBytes",
377 download_len,
379 max,
380 kBuckets);
384 namespace {
386 enum DownloadContent {
387 DOWNLOAD_CONTENT_UNRECOGNIZED = 0,
388 DOWNLOAD_CONTENT_TEXT = 1,
389 DOWNLOAD_CONTENT_IMAGE = 2,
390 DOWNLOAD_CONTENT_AUDIO = 3,
391 DOWNLOAD_CONTENT_VIDEO = 4,
392 DOWNLOAD_CONTENT_OCTET_STREAM = 5,
393 DOWNLOAD_CONTENT_PDF = 6,
394 DOWNLOAD_CONTENT_DOC = 7,
395 DOWNLOAD_CONTENT_XLS = 8,
396 DOWNLOAD_CONTENT_PPT = 9,
397 DOWNLOAD_CONTENT_ARCHIVE = 10,
398 DOWNLOAD_CONTENT_EXE = 11,
399 DOWNLOAD_CONTENT_DMG = 12,
400 DOWNLOAD_CONTENT_CRX = 13,
401 DOWNLOAD_CONTENT_MAX = 14,
404 struct MimeTypeToDownloadContent {
405 const char* mime_type;
406 DownloadContent download_content;
409 static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = {
410 {"application/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
411 {"binary/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
412 {"application/pdf", DOWNLOAD_CONTENT_PDF},
413 {"application/msword", DOWNLOAD_CONTENT_DOC},
414 {"application/vnd.ms-excel", DOWNLOAD_CONTENT_XLS},
415 {"application/vns.ms-powerpoint", DOWNLOAD_CONTENT_PPT},
416 {"application/zip", DOWNLOAD_CONTENT_ARCHIVE},
417 {"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE},
418 {"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE},
419 {"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE},
420 {"application/x-bzip", DOWNLOAD_CONTENT_ARCHIVE},
421 {"application/x-exe", DOWNLOAD_CONTENT_EXE},
422 {"application/x-apple-diskimage", DOWNLOAD_CONTENT_DMG},
423 {"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX},
426 enum DownloadImage {
427 DOWNLOAD_IMAGE_UNRECOGNIZED = 0,
428 DOWNLOAD_IMAGE_GIF = 1,
429 DOWNLOAD_IMAGE_JPEG = 2,
430 DOWNLOAD_IMAGE_PNG = 3,
431 DOWNLOAD_IMAGE_TIFF = 4,
432 DOWNLOAD_IMAGE_ICON = 5,
433 DOWNLOAD_IMAGE_WEBP = 6,
434 DOWNLOAD_IMAGE_MAX = 7,
437 struct MimeTypeToDownloadImage {
438 const char* mime_type;
439 DownloadImage download_image;
442 static MimeTypeToDownloadImage kMapMimeTypeToDownloadImage[] = {
443 {"image/gif", DOWNLOAD_IMAGE_GIF},
444 {"image/jpeg", DOWNLOAD_IMAGE_JPEG},
445 {"image/png", DOWNLOAD_IMAGE_PNG},
446 {"image/tiff", DOWNLOAD_IMAGE_TIFF},
447 {"image/vnd.microsoft.icon", DOWNLOAD_IMAGE_ICON},
448 {"image/webp", DOWNLOAD_IMAGE_WEBP},
451 void RecordDownloadImageType(const std::string& mime_type_string) {
452 DownloadImage download_image = DOWNLOAD_IMAGE_UNRECOGNIZED;
454 // Look up exact matches.
455 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadImage); ++i) {
456 const MimeTypeToDownloadImage& entry = kMapMimeTypeToDownloadImage[i];
457 if (mime_type_string == entry.mime_type) {
458 download_image = entry.download_image;
459 break;
463 UMA_HISTOGRAM_ENUMERATION("Download.ContentImageType",
464 download_image,
465 DOWNLOAD_IMAGE_MAX);
468 } // namespace
470 void RecordDownloadMimeType(const std::string& mime_type_string) {
471 DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED;
473 // Look up exact matches.
474 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) {
475 const MimeTypeToDownloadContent& entry = kMapMimeTypeToDownloadContent[i];
476 if (mime_type_string == entry.mime_type) {
477 download_content = entry.download_content;
478 break;
482 // Do partial matches.
483 if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) {
484 if (base::StartsWith(mime_type_string, "text/",
485 base::CompareCase::SENSITIVE)) {
486 download_content = DOWNLOAD_CONTENT_TEXT;
487 } else if (base::StartsWith(mime_type_string, "image/",
488 base::CompareCase::SENSITIVE)) {
489 download_content = DOWNLOAD_CONTENT_IMAGE;
490 RecordDownloadImageType(mime_type_string);
491 } else if (base::StartsWith(mime_type_string, "audio/",
492 base::CompareCase::SENSITIVE)) {
493 download_content = DOWNLOAD_CONTENT_AUDIO;
494 } else if (base::StartsWith(mime_type_string, "video/",
495 base::CompareCase::SENSITIVE)) {
496 download_content = DOWNLOAD_CONTENT_VIDEO;
500 // Record the value.
501 UMA_HISTOGRAM_ENUMERATION("Download.ContentType",
502 download_content,
503 DOWNLOAD_CONTENT_MAX);
506 void RecordDownloadContentDisposition(
507 const std::string& content_disposition_string) {
508 if (content_disposition_string.empty())
509 return;
510 net::HttpContentDisposition content_disposition(content_disposition_string,
511 std::string());
512 int result = content_disposition.parse_result_flags();
514 bool is_valid = !content_disposition.filename().empty();
515 RecordContentDispositionCount(CONTENT_DISPOSITION_HEADER_PRESENT, true);
516 RecordContentDispositionCount(CONTENT_DISPOSITION_IS_VALID, is_valid);
517 if (!is_valid)
518 return;
520 RecordContentDispositionCountFlag(
521 CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE, result,
522 net::HttpContentDisposition::HAS_DISPOSITION_TYPE);
523 RecordContentDispositionCountFlag(
524 CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE, result,
525 net::HttpContentDisposition::HAS_UNKNOWN_DISPOSITION_TYPE);
526 RecordContentDispositionCountFlag(
527 CONTENT_DISPOSITION_HAS_FILENAME, result,
528 net::HttpContentDisposition::HAS_FILENAME);
529 RecordContentDispositionCountFlag(
530 CONTENT_DISPOSITION_HAS_EXT_FILENAME, result,
531 net::HttpContentDisposition::HAS_EXT_FILENAME);
532 RecordContentDispositionCountFlag(
533 CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS, result,
534 net::HttpContentDisposition::HAS_NON_ASCII_STRINGS);
535 RecordContentDispositionCountFlag(
536 CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS, result,
537 net::HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS);
538 RecordContentDispositionCountFlag(
539 CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS, result,
540 net::HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS);
543 void RecordFileThreadReceiveBuffers(size_t num_buffers) {
544 UMA_HISTOGRAM_CUSTOM_COUNTS(
545 "Download.FileThreadReceiveBuffers", num_buffers, 1,
546 100, 100);
549 void RecordBandwidth(double actual_bandwidth, double potential_bandwidth) {
550 UMA_HISTOGRAM_CUSTOM_COUNTS(
551 "Download.ActualBandwidth", actual_bandwidth, 1, 1000000000, 50);
552 UMA_HISTOGRAM_CUSTOM_COUNTS(
553 "Download.PotentialBandwidth", potential_bandwidth, 1, 1000000000, 50);
554 UMA_HISTOGRAM_PERCENTAGE(
555 "Download.BandwidthUsed",
556 (int) ((actual_bandwidth * 100)/ potential_bandwidth));
559 void RecordOpen(const base::Time& end, bool first) {
560 if (!end.is_null()) {
561 UMA_HISTOGRAM_LONG_TIMES("Download.OpenTime", (base::Time::Now() - end));
562 if (first) {
563 UMA_HISTOGRAM_LONG_TIMES("Download.FirstOpenTime",
564 (base::Time::Now() - end));
569 void RecordClearAllSize(int size) {
570 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.ClearAllSize",
571 size,
572 0/*min*/,
573 (1 << 10)/*max*/,
574 32/*num_buckets*/);
577 void RecordOpensOutstanding(int size) {
578 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.OpensOutstanding",
579 size,
580 0/*min*/,
581 (1 << 10)/*max*/,
582 64/*num_buckets*/);
585 void RecordContiguousWriteTime(base::TimeDelta time_blocked) {
586 UMA_HISTOGRAM_TIMES("Download.FileThreadBlockedTime", time_blocked);
589 // Record what percentage of the time we have the network flow controlled.
590 void RecordNetworkBlockage(base::TimeDelta resource_handler_lifetime,
591 base::TimeDelta resource_handler_blocked_time) {
592 int percentage = 0;
593 // Avoid division by zero errors.
594 if (resource_handler_blocked_time != base::TimeDelta()) {
595 percentage =
596 resource_handler_blocked_time * 100 / resource_handler_lifetime;
599 UMA_HISTOGRAM_COUNTS_100("Download.ResourceHandlerBlockedPercentage",
600 percentage);
603 void RecordFileBandwidth(size_t length,
604 base::TimeDelta disk_write_time,
605 base::TimeDelta elapsed_time) {
606 size_t elapsed_time_ms = elapsed_time.InMilliseconds();
607 if (0u == elapsed_time_ms)
608 elapsed_time_ms = 1;
609 size_t disk_write_time_ms = disk_write_time.InMilliseconds();
610 if (0u == disk_write_time_ms)
611 disk_write_time_ms = 1;
613 UMA_HISTOGRAM_CUSTOM_COUNTS(
614 "Download.BandwidthOverallBytesPerSecond",
615 (1000 * length / elapsed_time_ms), 1, 50000000, 50);
616 UMA_HISTOGRAM_CUSTOM_COUNTS(
617 "Download.BandwidthDiskBytesPerSecond",
618 (1000 * length / disk_write_time_ms), 1, 50000000, 50);
619 UMA_HISTOGRAM_COUNTS_100("Download.DiskBandwidthUsedPercentage",
620 disk_write_time_ms * 100 / elapsed_time_ms);
623 void RecordDownloadFileRenameResultAfterRetry(
624 base::TimeDelta time_since_first_failure,
625 DownloadInterruptReason interrupt_reason) {
626 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) {
627 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure",
628 time_since_first_failure);
629 } else {
630 UMA_HISTOGRAM_TIMES("Download.TimeToRenameFailureAfterInitialFailure",
631 time_since_first_failure);
635 void RecordSavePackageEvent(SavePackageEvent event) {
636 UMA_HISTOGRAM_ENUMERATION("Download.SavePackage",
637 event,
638 SAVE_PACKAGE_LAST_ENTRY);
641 void RecordOriginStateOnResumption(bool is_partial,
642 int state) {
643 if (is_partial)
644 UMA_HISTOGRAM_ENUMERATION("Download.OriginStateOnPartialResumption", state,
645 ORIGIN_STATE_ON_RESUMPTION_MAX);
646 else
647 UMA_HISTOGRAM_ENUMERATION("Download.OriginStateOnFullResumption", state,
648 ORIGIN_STATE_ON_RESUMPTION_MAX);
651 } // namespace content