1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "pdf/metrics_handler.h"
9 #include "base/metrics/histogram_functions.h"
10 #include "pdf/document_metadata.h"
11 #include "pdf/file_extension.h"
13 namespace chrome_pdf {
17 // These values are persisted to logs. Entries should not be renumbered and
18 // numeric values should never be reused.
19 enum class PdfHasAttachment {
27 MetricsHandler::MetricsHandler() = default;
29 MetricsHandler::~MetricsHandler() = default;
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));
39 void MetricsHandler::RecordDocumentMetrics(const DocumentMetadata& metadata) {
40 base::UmaHistogramEnumeration("PDF.Version", metadata.version);
41 base::UmaHistogramCustomCounts("PDF.PageCount", metadata.page_count, 1,
43 base::UmaHistogramEnumeration(
44 "PDF.HasAttachment", metadata.has_attachments ? PdfHasAttachment::kYes
45 : PdfHasAttachment::kNo);
46 base::UmaHistogramEnumeration("PDF.FormType", metadata.form_type);
49 } // namespace chrome_pdf