Avi Drissman | db497b3 | 2022-09-15 19:47:28 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
Lei Zhang | 36a43841 | 2022-03-29 20:38:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "pdf/metrics_handler.h" |
| 6 | |
| 7 | #include <vector> |
| 8 | |
| 9 | #include "base/metrics/histogram_functions.h" |
| 10 | #include "pdf/document_metadata.h" |
| 11 | #include "pdf/file_extension.h" |
| 12 | |
| 13 | namespace chrome_pdf { |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | // These values are persisted to logs. Entries should not be renumbered and |
| 18 | // numeric values should never be reused. |
| 19 | enum class PdfHasAttachment { |
| 20 | kNo = 0, |
| 21 | kYes = 1, |
| 22 | kMaxValue = kYes, |
| 23 | }; |
| 24 | |
Lei Zhang | 36a43841 | 2022-03-29 20:38:21 | [diff] [blame] | 25 | } // namespace |
| 26 | |
| 27 | MetricsHandler::MetricsHandler() = default; |
| 28 | |
| 29 | MetricsHandler::~MetricsHandler() = default; |
| 30 | |
| 31 | void MetricsHandler::RecordAttachmentTypes( |
| 32 | const std::vector<DocumentAttachmentInfo>& attachments) { |
| 33 | for (const auto& info : attachments) { |
| 34 | base::UmaHistogramEnumeration("PDF.AttachmentType", |
| 35 | FileNameToExtensionIndex(info.name)); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void MetricsHandler::RecordDocumentMetrics(const DocumentMetadata& metadata) { |
| 40 | base::UmaHistogramEnumeration("PDF.Version", metadata.version); |
| 41 | base::UmaHistogramCustomCounts("PDF.PageCount", metadata.page_count, 1, |
| 42 | 1000000, 50); |
| 43 | base::UmaHistogramEnumeration( |
| 44 | "PDF.HasAttachment", metadata.has_attachments ? PdfHasAttachment::kYes |
| 45 | : PdfHasAttachment::kNo); |
Lei Zhang | 36a43841 | 2022-03-29 20:38:21 | [diff] [blame] | 46 | base::UmaHistogramEnumeration("PDF.FormType", metadata.form_type); |
| 47 | } |
| 48 | |
| 49 | } // namespace chrome_pdf |