OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/macros.h" | 7 #include "base/macros.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 571 |
572 // Look up exact matches. | 572 // Look up exact matches. |
573 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadImage); ++i) { | 573 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadImage); ++i) { |
574 const MimeTypeToDownloadImage& entry = kMapMimeTypeToDownloadImage[i]; | 574 const MimeTypeToDownloadImage& entry = kMapMimeTypeToDownloadImage[i]; |
575 if (mime_type_string == entry.mime_type) { | 575 if (mime_type_string == entry.mime_type) { |
576 download_image = entry.download_image; | 576 download_image = entry.download_image; |
577 break; | 577 break; |
578 } | 578 } |
579 } | 579 } |
580 | 580 |
581 UMA_HISTOGRAM_ENUMERATION("Download.ContentImageType", | 581 UMA_HISTOGRAM_ENUMERATION("Download.ContentImageType", download_image, |
582 download_image, | |
583 DOWNLOAD_IMAGE_MAX); | 582 DOWNLOAD_IMAGE_MAX); |
584 } | 583 } |
585 | 584 |
586 } // namespace | 585 DownloadContent DownloadContentFromMimeType( |
587 | 586 const std::string& mime_type_string) { |
588 void RecordDownloadMimeType(const std::string& mime_type_string) { | |
589 DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED; | 587 DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED; |
590 | 588 |
591 // Look up exact matches. | 589 // Look up exact matches. |
592 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) { | 590 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) { |
593 const MimeTypeToDownloadContent& entry = kMapMimeTypeToDownloadContent[i]; | 591 const MimeTypeToDownloadContent& entry = kMapMimeTypeToDownloadContent[i]; |
594 if (mime_type_string == entry.mime_type) { | 592 if (mime_type_string == entry.mime_type) { |
595 download_content = entry.download_content; | 593 download_content = entry.download_content; |
596 break; | 594 break; |
597 } | 595 } |
598 } | 596 } |
599 | 597 |
600 // Do partial matches. | 598 // Do partial matches. |
601 if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) { | 599 if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) { |
602 if (base::StartsWith(mime_type_string, "text/", | 600 if (base::StartsWith(mime_type_string, "text/", |
603 base::CompareCase::SENSITIVE)) { | 601 base::CompareCase::SENSITIVE)) { |
604 download_content = DOWNLOAD_CONTENT_TEXT; | 602 download_content = DOWNLOAD_CONTENT_TEXT; |
605 } else if (base::StartsWith(mime_type_string, "image/", | 603 } else if (base::StartsWith(mime_type_string, "image/", |
606 base::CompareCase::SENSITIVE)) { | 604 base::CompareCase::SENSITIVE)) { |
607 download_content = DOWNLOAD_CONTENT_IMAGE; | 605 download_content = DOWNLOAD_CONTENT_IMAGE; |
608 RecordDownloadImageType(mime_type_string); | 606 RecordDownloadImageType(mime_type_string); |
609 } else if (base::StartsWith(mime_type_string, "audio/", | 607 } else if (base::StartsWith(mime_type_string, "audio/", |
610 base::CompareCase::SENSITIVE)) { | 608 base::CompareCase::SENSITIVE)) { |
611 download_content = DOWNLOAD_CONTENT_AUDIO; | 609 download_content = DOWNLOAD_CONTENT_AUDIO; |
612 } else if (base::StartsWith(mime_type_string, "video/", | 610 } else if (base::StartsWith(mime_type_string, "video/", |
613 base::CompareCase::SENSITIVE)) { | 611 base::CompareCase::SENSITIVE)) { |
614 download_content = DOWNLOAD_CONTENT_VIDEO; | 612 download_content = DOWNLOAD_CONTENT_VIDEO; |
615 } | 613 } |
616 } | 614 } |
617 | 615 |
618 // Record the value. | 616 return download_content; |
| 617 } |
| 618 |
| 619 } // namespace |
| 620 |
| 621 void RecordDownloadMimeType(const std::string& mime_type_string) { |
619 UMA_HISTOGRAM_ENUMERATION("Download.ContentType", | 622 UMA_HISTOGRAM_ENUMERATION("Download.ContentType", |
620 download_content, | 623 DownloadContentFromMimeType(mime_type_string), |
621 DOWNLOAD_CONTENT_MAX); | 624 DOWNLOAD_CONTENT_MAX); |
622 } | 625 } |
623 | 626 |
| 627 void RecordDownloadMimeTypeForNormalProfile( |
| 628 const std::string& mime_type_string) { |
| 629 UMA_HISTOGRAM_ENUMERATION("Download.ContentType.NormalProfile", |
| 630 DownloadContentFromMimeType(mime_type_string), |
| 631 DOWNLOAD_CONTENT_MAX); |
| 632 } |
| 633 |
624 void RecordDownloadContentDisposition( | 634 void RecordDownloadContentDisposition( |
625 const std::string& content_disposition_string) { | 635 const std::string& content_disposition_string) { |
626 if (content_disposition_string.empty()) | 636 if (content_disposition_string.empty()) |
627 return; | 637 return; |
628 net::HttpContentDisposition content_disposition(content_disposition_string, | 638 net::HttpContentDisposition content_disposition(content_disposition_string, |
629 std::string()); | 639 std::string()); |
630 int result = content_disposition.parse_result_flags(); | 640 int result = content_disposition.parse_result_flags(); |
631 | 641 |
632 bool is_valid = !content_disposition.filename().empty(); | 642 bool is_valid = !content_disposition.filename().empty(); |
633 RecordContentDispositionCount(CONTENT_DISPOSITION_HEADER_PRESENT, true); | 643 RecordContentDispositionCount(CONTENT_DISPOSITION_HEADER_PRESENT, true); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 if (!page_transition) | 805 if (!page_transition) |
796 return; | 806 return; |
797 | 807 |
798 UMA_HISTOGRAM_ENUMERATION( | 808 UMA_HISTOGRAM_ENUMERATION( |
799 "Download.PageTransition", | 809 "Download.PageTransition", |
800 ui::PageTransitionStripQualifier(page_transition.value()), | 810 ui::PageTransitionStripQualifier(page_transition.value()), |
801 ui::PAGE_TRANSITION_LAST_CORE + 1); | 811 ui::PAGE_TRANSITION_LAST_CORE + 1); |
802 } | 812 } |
803 | 813 |
804 } // namespace content | 814 } // namespace content |
OLD | NEW |