1 // Copyright (c) 2012 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.
5 cr
.define('print_preview', function() {
9 * Object used to measure usage statistics.
12 function Metrics() {};
15 * Enumeration of buckets that a user can enter while using the destination
19 Metrics
.DestinationSearchBucket
= {
20 // Used when the print destination search widget is shown.
22 // Used when the user selects a print destination.
23 DESTINATION_CLOSED_CHANGED
: 1,
24 // Used when the print destination search widget is closed without selecting
25 // a print destination.
26 DESTINATION_CLOSED_UNCHANGED
: 2,
27 // Used when the Google Cloud Print promotion (shown in the destination
28 // search widget) is shown to the user.
30 // Used when the user chooses to sign-in to their Google account.
32 // Used when a user selects the Privet printer in a pair of duplicate
33 // Privet and cloud printers.
34 PRIVET_DUPLICATE_SELECTED
: 5,
35 // Used when a user selects the cloud printer in a pair of duplicate
36 // Privet and cloud printers.
37 CLOUD_DUPLICATE_SELECTED
: 6,
38 // Used when a user sees a register promo for a cloud print printer.
39 REGISTER_PROMO_SHOWN
: 7,
40 // Used when a user selects a register promo for a cloud print printer.
41 REGISTER_PROMO_SELECTED
: 8,
42 // User changed active account.
44 // User tried to log into another account.
45 ADD_ACCOUNT_SELECTED
: 10,
46 // Printer sharing invitation was shown to the user.
47 INVITATION_AVAILABLE
: 11,
48 // User accepted printer sharing invitation.
49 INVITATION_ACCEPTED
: 12,
50 // User rejected printer sharing invitation.
51 INVITATION_REJECTED
: 13,
53 DESTINATION_SEARCH_MAX_BUCKET
: 14
57 * Enumeration of buckets that a user can enter while using the Google Cloud
61 Metrics
.GcpPromoBucket
= {
62 // Used when the Google Cloud Print promotion (shown above the PDF preview
63 // plugin) is shown to the user.
65 // Used when the user clicks the "Get started" link in the promotion shown
66 // in CLOUDPRINT_BIG_PROMO_SHOWN.
68 // Used when the user dismisses the promotion shown in
69 // CLOUDPRINT_BIG_PROMO_SHOWN.
72 GCP_PROMO_MAX_BUCKET
: 3
76 * Print settings UI usage metrics buckets.
79 Metrics
.PrintSettingsUiBucket
= {
80 // Advanced settings dialog is shown.
81 ADVANCED_SETTINGS_DIALOG_SHOWN
: 0,
82 // Advanced settings dialog is closed without saving a selection.
83 ADVANCED_SETTINGS_DIALOG_CANCELED
: 1,
84 // 'More/less settings' expanded.
85 MORE_SETTINGS_CLICKED
: 2,
86 // 'More/less settings' collapsed.
87 LESS_SETTINGS_CLICKED
: 3,
88 // User printed with extra settings expanded.
89 PRINT_WITH_SETTINGS_EXPANDED
: 4,
90 // User printed with extra settings collapsed.
91 PRINT_WITH_SETTINGS_COLLAPSED
: 5,
93 PRINT_SETTINGS_UI_MAX_BUCKET
: 6
97 * A context for recording a value in a specific UMA histogram.
98 * @param {string} histogram The name of the histogram to be recorded in.
99 * @param {number} maxBucket The max value for the last histogram bucket.
102 function MetricsContext(histogram
, maxBucket
) {
103 /** @private {string} */
104 this.histogram_
= histogram
;
106 /** @private {number} */
107 this.maxBucket_
= maxBucket
;
110 MetricsContext
.prototype = {
112 * Record a histogram value in UMA. If specified value is larger than the
113 * max bucket value, record the value in the largest bucket
114 * @param {number} bucket Value to record.
116 record: function(bucket
) {
117 chrome
.send('metricsHandler:recordInHistogram',
119 ((bucket
> this.maxBucket_
) ? this.maxBucket_
: bucket
),
125 * Destination Search specific usage statistics context.
127 * @extends {print_preview.MetricsContext}
129 function DestinationSearchMetricsContext() {
132 'PrintPreview.DestinationAction',
133 Metrics
.DestinationSearchBucket
.DESTINATION_SEARCH_MAX_BUCKET
);
136 DestinationSearchMetricsContext
.prototype = {
137 __proto__
: MetricsContext
.prototype
141 * GCP promotion specific usage statistics context.
143 * @extends {print_preview.MetricsContext}
145 function GcpPromoMetricsContext() {
146 MetricsContext
.call(this,
147 'PrintPreview.GcpPromo',
148 Metrics
.GcpPromoBucket
.GCP_PROMO_MAX_BUCKET
);
151 GcpPromoMetricsContext
.prototype = {
152 __proto__
: MetricsContext
.prototype
156 * Print settings UI specific usage statistics context.
158 * @extends {print_preview.MetricsContext}
160 function PrintSettingsUiMetricsContext() {
163 'PrintPreview.PrintSettingsUi',
164 Metrics
.PrintSettingsUiBucket
.PRINT_SETTINGS_UI_MAX_BUCKET
);
167 PrintSettingsUiMetricsContext
.prototype = {
168 __proto__
: MetricsContext
.prototype
174 MetricsContext
: MetricsContext
,
175 DestinationSearchMetricsContext
: DestinationSearchMetricsContext
,
176 GcpPromoMetricsContext
: GcpPromoMetricsContext
,
177 PrintSettingsUiMetricsContext
: PrintSettingsUiMetricsContext