Skip to content

Commit

Permalink
Add metric collection for form type in PDFs
Browse files Browse the repository at this point in the history
BUG=chromium:775519,chromium:768986

Change-Id: I485e4ec14fa2097f8d0ef7ff782ac2d086d78411
Reviewed-on: https://chromium-review.googlesource.com/723581
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510827}
  • Loading branch information
zoddicus authored and Commit Bot committed Oct 23, 2017
1 parent 8cddb0d commit 4de8f1e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,9 @@ void OutOfProcessInstance::DocumentLoadComplete(
HistogramEnumeration("PDF.IsLinearized",
document_features.is_linearized ? 1 : 0, 2);
HistogramEnumeration("PDF.IsTagged", document_features.is_tagged ? 1 : 0, 2);
HistogramEnumeration("PDF.FormType",
static_cast<int32_t>(document_features.form_type),
static_cast<int32_t>(PDFEngine::FormType::kCount));
}

void OutOfProcessInstance::RotateClockwise() {
Expand Down
12 changes: 12 additions & 0 deletions pdf/pdf_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ class PDFEngine {
PERMISSION_PRINT_HIGH_QUALITY,
};

// Values other then |kCount| are persisted to logs as part of metric
// collection, so should not be changed.
enum class FormType {
kNone = 0,
kAcroForm = 1,
kXFAFull = 2,
kXFAForeground = 3,
kCount = 4,
};

struct DocumentFeatures {
// Number of pages in document.
size_t page_count = 0;
Expand All @@ -69,6 +79,8 @@ class PDFEngine {
bool is_linearized = false;
// Whether the PDF is Tagged (see 10.7 "Tagged PDF" in PDF Reference 1.7).
bool is_tagged = false;
// What type of form the document contains.
FormType form_type = FormType::kNone;
};

// The interface that's provided to the rendering engine.
Expand Down
15 changes: 15 additions & 0 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ using printing::kPixelsPerInch;

namespace chrome_pdf {

static_assert(static_cast<int>(PDFEngine::FormType::kNone) == FORMTYPE_NONE,
"None form types must match");
static_assert(static_cast<int>(PDFEngine::FormType::kAcroForm) ==
FORMTYPE_ACRO_FORM,
"AcroForm form types must match");
static_assert(static_cast<int>(PDFEngine::FormType::kXFAFull) ==
FORMTYPE_XFA_FULL,
"XFA full form types must match");
static_assert(static_cast<int>(PDFEngine::FormType::kXFAForeground) ==
FORMTYPE_XFA_FOREGROUND,
"XFA foreground form types must match");
static_assert(static_cast<int>(PDFEngine::FormType::kCount) == FORMTYPE_COUNT,
"Form type counts must match");

namespace {

const int32_t kPageShadowTop = 3;
Expand Down Expand Up @@ -1282,6 +1296,7 @@ void PDFiumEngine::FinishLoadingDocument() {
document_features.is_linearized =
(FPDFAvail_IsLinearized(fpdf_availability_) == PDF_LINEARIZED);
document_features.is_tagged = FPDFCatalog_IsTagged(doc_);
document_features.form_type = static_cast<FormType>(FPDF_GetFormType(doc_));
client_->DocumentLoadComplete(document_features);
}
}
Expand Down
7 changes: 7 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31229,6 +31229,13 @@ from previous Chrome versions.
<int value="2" label="Has Bookmarks"/>
</enum>

<enum name="PDFFormTypes">
<int value="0" label="None"/>
<int value="1" label="AcroForm"/>
<int value="2" label="Full XFA"/>
<int value="3" label="Foreground XFA (XFAF)"/>
</enum>

<enum name="PeerConnectionCounters">
<int value="0" label="PeerConnection enabled with IPv4."/>
<int value="1" label="PeerConnection enabled with Ipv6."/>
Expand Down
8 changes: 8 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58368,6 +58368,14 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="PDF.FormType" enum="PDFFormTypes">
<owner>rharrison@chromium.org</owner>
<summary>
Tracks what types of forms are present in PDF document, logged when the
document finishes loading.
</summary>
</histogram>

<histogram name="PDF.HasAttachment" enum="Boolean">
<owner>hnakashima@chromium.org</owner>
<summary>
Expand Down

0 comments on commit 4de8f1e

Please sign in to comment.