Commit 736ca566 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

PDF Viewer: Add metrics for save original vs. save edited.

With the SaveEditedPDFForm feature, users have several new choices for
how to save PDFS. Extend the existing PDF.Actions histogram with new
ChromePDFViewerActions to cover these scenarios. This will help
developers understand how often these new features are being used.

Bug: 1130079
Change-Id: Ifb090f74b4f369d5e7c229bdaaf69138f430dc17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2439553Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812335}
parent 44803ec9
...@@ -183,7 +183,21 @@ export const UserAction = { ...@@ -183,7 +183,21 @@ export const UserAction = {
THUMBNAIL_NAVIGATE_FIRST: 45, THUMBNAIL_NAVIGATE_FIRST: 45,
THUMBNAIL_NAVIGATE: 46, THUMBNAIL_NAVIGATE: 46,
NUMBER_OF_ACTIONS: 47, // Recorded when the user triggers a save of the document and the document
// has never been modified.
SAVE_ORIGINAL_ONLY_FIRST: 47,
SAVE_ORIGINAL_ONLY: 48,
// Recorded when the user triggers a save of the original document, even
// though the document has been modified.
SAVE_ORIGINAL_FIRST: 49,
SAVE_ORIGINAL: 50,
// Recorded when the user triggers a save of the edited document.
SAVE_EDITED_FIRST: 51,
SAVE_EDITED: 52,
NUMBER_OF_ACTIONS: 53,
}; };
// Map from UserAction to the 'FIRST' action. These metrics are recorded // Map from UserAction to the 'FIRST' action. These metrics are recorded
...@@ -282,4 +296,16 @@ PDFMetrics.firstMap_ = new Map([ ...@@ -282,4 +296,16 @@ PDFMetrics.firstMap_ = new Map([
UserAction.THUMBNAIL_NAVIGATE, UserAction.THUMBNAIL_NAVIGATE,
UserAction.THUMBNAIL_NAVIGATE_FIRST, UserAction.THUMBNAIL_NAVIGATE_FIRST,
], ],
[
UserAction.SAVE_ORIGINAL_ONLY,
UserAction.SAVE_ORIGINAL_ONLY_FIRST,
],
[
UserAction.SAVE_ORIGINAL,
UserAction.SAVE_ORIGINAL_FIRST,
],
[
UserAction.SAVE_EDITED,
UserAction.SAVE_EDITED_FIRST,
],
]); ]);
...@@ -1084,14 +1084,13 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -1084,14 +1084,13 @@ export class PDFViewerElement extends PDFViewerBaseElement {
* @private * @private
*/ */
async save_(requestType) { async save_(requestType) {
PDFMetrics.record(UserAction.SAVE); this.recordSaveMetrics_(requestType);
// If we have entered annotation mode we must require the local // If we have entered annotation mode we must require the local
// contents to ensure annotations are saved, unless the user specifically // contents to ensure annotations are saved, unless the user specifically
// requested the original document. Otherwise we would save the cached // requested the original document. Otherwise we would save the cached
// remote copy without annotations. // remote copy without annotations.
if (requestType === SaveRequestType.ANNOTATION) { //
PDFMetrics.record(UserAction.SAVE_WITH_ANNOTATION);
}
// Always send requests of type ORIGINAL to the plugin controller, not the // Always send requests of type ORIGINAL to the plugin controller, not the
// ink controller. The ink controller always saves the edited document. // ink controller. The ink controller always saves the edited document.
// TODO(dstockwell): Report an error to user if this fails. // TODO(dstockwell): Report an error to user if this fails.
...@@ -1148,6 +1147,28 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -1148,6 +1147,28 @@ export class PDFViewerElement extends PDFViewerBaseElement {
// </if> // </if>
} }
/**
* Records metrics for saving PDFs.
* @param {SaveRequestType} requestType The type of save request.
* @private
*/
recordSaveMetrics_(requestType) {
PDFMetrics.record(UserAction.SAVE);
switch (requestType) {
case SaveRequestType.ANNOTATION:
PDFMetrics.record(UserAction.SAVE_WITH_ANNOTATION);
break;
case SaveRequestType.ORIGINAL:
PDFMetrics.record(
this.hasEdits_ ? UserAction.SAVE_ORIGINAL :
UserAction.SAVE_ORIGINAL_ONLY);
break;
case SaveRequestType.EDITED:
PDFMetrics.record(UserAction.SAVE_EDITED);
break;
}
}
/** @private */ /** @private */
async onPrint_() { async onPrint_() {
PDFMetrics.record(UserAction.PRINT); PDFMetrics.record(UserAction.PRINT);
......
...@@ -195,5 +195,48 @@ chrome.test.runTests(function() { ...@@ -195,5 +195,48 @@ chrome.test.runTests(function() {
chrome.metricsPrivate.actionCounter); chrome.metricsPrivate.actionCounter);
chrome.test.succeed(); chrome.test.succeed();
}, },
function testMetricsSaving() {
PDFMetrics.resetForTesting();
chrome.metricsPrivate = new MockMetricsPrivate();
PDFMetrics.record(UserAction.DOCUMENT_OPENED);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_ORIGINAL_ONLY);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_ORIGINAL_ONLY);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_ORIGINAL);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_EDITED);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_ORIGINAL);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_ORIGINAL);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_EDITED);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_WITH_ANNOTATION);
PDFMetrics.record(UserAction.SAVE);
PDFMetrics.record(UserAction.SAVE_WITH_ANNOTATION);
chrome.test.assertEq(
{
[UserAction.DOCUMENT_OPENED]: 1,
[UserAction.SAVE_FIRST]: 1,
[UserAction.SAVE]: 9,
[UserAction.SAVE_WITH_ANNOTATION_FIRST]: 1,
[UserAction.SAVE_WITH_ANNOTATION]: 2,
[UserAction.SAVE_ORIGINAL_ONLY_FIRST]: 1,
[UserAction.SAVE_ORIGINAL_ONLY]: 2,
[UserAction.SAVE_ORIGINAL_FIRST]: 1,
[UserAction.SAVE_ORIGINAL]: 3,
[UserAction.SAVE_EDITED_FIRST]: 1,
[UserAction.SAVE_EDITED]: 2
},
chrome.metricsPrivate.actionCounter);
chrome.test.succeed();
},
]; ];
}()); }());
...@@ -9824,6 +9824,12 @@ histogram as enum --> ...@@ -9824,6 +9824,12 @@ histogram as enum -->
<int value="44" label="ZoomCustom"/> <int value="44" label="ZoomCustom"/>
<int value="45" label="ThumbnailNavigateFirst"/> <int value="45" label="ThumbnailNavigateFirst"/>
<int value="46" label="ThumbnailNavigate"/> <int value="46" label="ThumbnailNavigate"/>
<int value="47" label="SaveOriginalOnlyFirst"/>
<int value="48" label="SaveOriginalOnly"/>
<int value="49" label="SaveOriginalFirst"/>
<int value="50" label="SaveOriginal"/>
<int value="51" label="SaveEditedFirst"/>
<int value="52" label="SaveEdited"/>
</enum> </enum>
<enum name="ChromePDFViewerAnnotationType"> <enum name="ChromePDFViewerAnnotationType">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment