Skip to content

Commit

Permalink
Add UMA stats for new Print Preview UI elements.
Browse files Browse the repository at this point in the history
BUG=397741

Review URL: https://codereview.chromium.org/601573002

Cr-Commit-Position: refs/heads/master@{#296552}
  • Loading branch information
alekseys authored and Commit bot committed Sep 24, 2014
1 parent 8f00db8 commit d6a8369
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 3 deletions.
18 changes: 16 additions & 2 deletions chrome/browser/resources/print_preview/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ cr.define('print_preview', function() {
ACCOUNT_CHANGED: 9,
// User tried to log into another account.
ADD_ACCOUNT_SELECTED: 10,
// Printer sharing invitation was shown to the user.
INVITATION_AVAILABLE: 11,
// User accepted printer sharing invitation.
INVITATION_ACCEPTED: 12,
// User rejected printer sharing invitation.
INVITATION_REJECTED: 13,
// Max value.
DESTINATION_SEARCH_MAX_BUCKET: 11
DESTINATION_SEARCH_MAX_BUCKET: 14
};

/**
Expand Down Expand Up @@ -75,8 +81,16 @@ cr.define('print_preview', function() {
ADVANCED_SETTINGS_DIALOG_SHOWN: 0,
// Advanced settings dialog is closed without saving a selection.
ADVANCED_SETTINGS_DIALOG_CANCELED: 1,
// 'More/less settings' expanded.
MORE_SETTINGS_CLICKED: 2,
// 'More/less settings' collapsed.
LESS_SETTINGS_CLICKED: 3,
// User printed with extra settings expanded.
PRINT_WITH_SETTINGS_EXPANDED: 4,
// User printed with extra settings collapsed.
PRINT_WITH_SETTINGS_COLLAPSED: 5,
// Max value.
PRINT_SETTINGS_UI_MAX_BUCKET: 2
PRINT_SETTINGS_UI_MAX_BUCKET: 6
};

/**
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/resources/print_preview/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ cr.define('print_preview', function() {
this.nativeLayer_.startShowCloudPrintDialog(
this.printTicketStore_.pageRange.getPageNumberSet().size);
} else {
if (getIsVisible(this.moreSettings_.getElement())) {
new print_preview.PrintSettingsUiMetricsContext().record(
this.moreSettings_.isExpanded ?
print_preview.Metrics.PrintSettingsUiBucket.
PRINT_WITH_SETTINGS_EXPANDED :
print_preview.Metrics.PrintSettingsUiBucket.
PRINT_WITH_SETTINGS_COLLAPSED);
}
this.nativeLayer_.startPrint(
this.destinationStore_.selectedDestination,
this.printTicketStore_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ cr.define('print_preview', function() {
var invitations = this.userInfo_.activeUser ?
this.invitationStore_.invitations(this.userInfo_.activeUser) : [];
if (invitations.length > 0) {
if (this.invitation_ != invitations[0]) {
this.metrics_.record(print_preview.Metrics.DestinationSearchBucket.
INVITATION_AVAILABLE);
}
this.invitation_ = invitations[0];
this.showInvitation_(this.invitation_);
} else {
Expand Down Expand Up @@ -660,6 +664,9 @@ cr.define('print_preview', function() {
* @private
*/
onInvitationProcessButtonClick_: function(accept) {
this.metrics_.record(accept ?
print_preview.Metrics.DestinationSearchBucket.INVITATION_ACCEPTED :
print_preview.Metrics.DestinationSearchBucket.INVITATION_REJECTED);
this.invitationStore_.processInvitation(this.invitation_, accept);
this.updateInvitations_();
},
Expand Down
14 changes: 14 additions & 0 deletions chrome/browser/resources/print_preview/settings/more_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ cr.define('print_preview', function() {

/** @private {boolean} */
this.firstDestinationReady_ = false;

/**
* Used to record usage statistics.
* @private {!print_preview.PrintSettingsUiMetricsContext}
*/
this.metrics_ = new print_preview.PrintSettingsUiMetricsContext();
};

/**
Expand All @@ -45,6 +51,11 @@ cr.define('print_preview', function() {
MoreSettings.prototype = {
__proto__: print_preview.Component.prototype,

/** @return {boolean} Returns {@code true} if settings are expanded. */
get isExpanded() {
return this.settingsToShow_ == MoreSettings.SettingsToShow.ALL;
},

/** @override */
enterDocument: function() {
print_preview.Component.prototype.enterDocument.call(this);
Expand Down Expand Up @@ -80,6 +91,9 @@ cr.define('print_preview', function() {
MoreSettings.SettingsToShow.ALL :
MoreSettings.SettingsToShow.MOST_POPULAR;
this.updateState_(false);
this.metrics_.record(this.isExpanded ?
print_preview.Metrics.PrintSettingsUiBucket.MORE_SETTINGS_CLICKED :
print_preview.Metrics.PrintSettingsUiBucket.LESS_SETTINGS_CLICKED);
},

/**
Expand Down
37 changes: 36 additions & 1 deletion chrome/browser/ui/webui/print_preview/print_preview_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ enum PrintSettingsBuckets {
CSS_BACKGROUND,
SELECTION_ONLY,
EXTERNAL_PDF_PREVIEW,
PAGE_RANGE,
DEFAULT_MEDIA,
NON_DEFAULT_MEDIA,
COPIES,
NON_DEFAULT_MARGINS,
PRINT_SETTINGS_BUCKET_BOUNDARY
};

Expand Down Expand Up @@ -196,10 +201,33 @@ base::DictionaryValue* GetSettingsDictionary(const base::ListValue* args) {
void ReportPrintSettingsStats(const base::DictionaryValue& settings) {
ReportPrintSettingHistogram(TOTAL);

const base::ListValue* page_range_array = NULL;
if (settings.GetList(printing::kSettingPageRange, &page_range_array) &&
!page_range_array->empty()) {
ReportPrintSettingHistogram(PAGE_RANGE);
}

const base::DictionaryValue* media_size_value = NULL;
if (settings.GetDictionary(printing::kSettingMediaSize, &media_size_value) &&
!media_size_value->empty()) {
bool is_default = false;
if (media_size_value->GetBoolean(printing::kSettingMediaSizeIsDefault,
&is_default) &&
is_default) {
ReportPrintSettingHistogram(DEFAULT_MEDIA);
} else {
ReportPrintSettingHistogram(NON_DEFAULT_MEDIA);
}
}

bool landscape = false;
if (settings.GetBoolean(printing::kSettingLandscape, &landscape))
ReportPrintSettingHistogram(landscape ? LANDSCAPE : PORTRAIT);

int copies = 1;
if (settings.GetInteger(printing::kSettingCopies, &copies) && copies > 1)
ReportPrintSettingHistogram(COPIES);

bool collate = false;
if (settings.GetBoolean(printing::kSettingCollate, &collate) && collate)
ReportPrintSettingHistogram(COLLATE);
Expand All @@ -214,6 +242,12 @@ void ReportPrintSettingsStats(const base::DictionaryValue& settings) {
printing::IsColorModelSelected(color_mode) ? COLOR : BLACK_AND_WHITE);
}

int margins_type = 0;
if (settings.GetInteger(printing::kSettingMarginsType, &margins_type) &&
margins_type != 0) {
ReportPrintSettingHistogram(NON_DEFAULT_MARGINS);
}

bool headers = false;
if (settings.GetBoolean(printing::kSettingHeaderFooterEnabled, &headers) &&
headers) {
Expand Down Expand Up @@ -758,6 +792,8 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
if (!settings.get())
return;

ReportPrintSettingsStats(*settings);

// Never try to add headers/footers here. It's already in the generated PDF.
settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false);

Expand Down Expand Up @@ -836,7 +872,6 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count);
ReportUserActionHistogram(PRINT_TO_PRINTER);
}
ReportPrintSettingsStats(*settings);

// This tries to activate the initiator as well, so do not clear the
// association with the initiator yet.
Expand Down
3 changes: 3 additions & 0 deletions printing/print_job_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const char kSettingMediaSizeWidthMicrons[] = "width_microns";
// Key that specifies the requested media platform specific vendor id.
const char kSettingMediaSizeVendorId[] = "vendor_id";

// Key that specifies whether the requested media is a default one.
const char kSettingMediaSizeIsDefault[] = "is_default";

// Key that specifies the bottom margin of the page.
const char kSettingMarginBottom[] = "marginBottom";

Expand Down
1 change: 1 addition & 0 deletions printing/print_job_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ PRINTING_EXPORT extern const char kSettingMediaSize[];
PRINTING_EXPORT extern const char kSettingMediaSizeHeightMicrons[];
PRINTING_EXPORT extern const char kSettingMediaSizeWidthMicrons[];
PRINTING_EXPORT extern const char kSettingMediaSizeVendorId[];
PRINTING_EXPORT extern const char kSettingMediaSizeIsDefault[];
PRINTING_EXPORT extern const char kSettingMarginBottom[];
PRINTING_EXPORT extern const char kSettingMarginLeft[];
PRINTING_EXPORT extern const char kSettingMarginRight[];
Expand Down
12 changes: 12 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49004,11 +49004,18 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="8" label="REGISTER_PROMO_SELECTED"/>
<int value="9" label="ACCOUNT_CHANGED"/>
<int value="10" label="ADD_ACCOUNT_SELECTED"/>
<int value="11" label="INVITATION_AVAILABLE"/>
<int value="12" label="INVITATION_ACCEPTED"/>
<int value="13" label="INVITATION_REJECTED"/>
</enum>

<enum name="PrintPreviewPrintSettingsUiBuckets" type="int">
<int value="0" label="ADVANCED_SETTINGS_DIALOG_SHOWN"/>
<int value="1" label="ADVANCED_SETTINGS_DIALOG_CANCELED"/>
<int value="2" label="MORE_SETTINGS_CLICKED"/>
<int value="3" label="LESS_SETTINGS_CLICKED"/>
<int value="4" label="PRINT_WITH_SETTINGS_EXPANDED"/>
<int value="5" label="PRINT_WITH_SETTINGS_COLLAPSED"/>
</enum>

<enum name="PrintPreviewUserActionType" type="int">
Expand Down Expand Up @@ -49037,6 +49044,11 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="9" label="CSS_BACKGROUND"/>
<int value="10" label="SELECTION_ONLY"/>
<int value="11" label="EXTERNAL_PDF_PREVIEW"/>
<int value="12" label="PAGE_RANGE"/>
<int value="13" label="DEFAULT_MEDIA"/>
<int value="14" label="NON_DEFAULT_MEDIA"/>
<int value="15" label="COPIES"/>
<int value="16" label="NON_DEFAULT_MARGINS"/>
</enum>

<enum name="PrivetNotificationsEvent" type="int">
Expand Down

0 comments on commit d6a8369

Please sign in to comment.