metrics_handler.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2022 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.
  4. #include "pdf/metrics_handler.h"
  5. #include <vector>
  6. #include "base/metrics/histogram_functions.h"
  7. #include "pdf/document_metadata.h"
  8. #include "pdf/file_extension.h"
  9. namespace chrome_pdf {
  10. namespace {
  11. // These values are persisted to logs. Entries should not be renumbered and
  12. // numeric values should never be reused.
  13. enum class PdfHasAttachment {
  14. kNo = 0,
  15. kYes = 1,
  16. kMaxValue = kYes,
  17. };
  18. } // namespace
  19. MetricsHandler::MetricsHandler() = default;
  20. MetricsHandler::~MetricsHandler() = default;
  21. void MetricsHandler::RecordAttachmentTypes(
  22. const std::vector<DocumentAttachmentInfo>& attachments) {
  23. for (const auto& info : attachments) {
  24. base::UmaHistogramEnumeration("PDF.AttachmentType",
  25. FileNameToExtensionIndex(info.name));
  26. }
  27. }
  28. void MetricsHandler::RecordDocumentMetrics(const DocumentMetadata& metadata) {
  29. base::UmaHistogramEnumeration("PDF.Version", metadata.version);
  30. base::UmaHistogramCustomCounts("PDF.PageCount", metadata.page_count, 1,
  31. 1000000, 50);
  32. base::UmaHistogramEnumeration(
  33. "PDF.HasAttachment", metadata.has_attachments ? PdfHasAttachment::kYes
  34. : PdfHasAttachment::kNo);
  35. base::UmaHistogramEnumeration("PDF.FormType", metadata.form_type);
  36. }
  37. } // namespace chrome_pdf