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,
47 DESTINATION_SEARCH_MAX_BUCKET
: 11
51 * Enumeration of buckets that a user can enter while using the Google Cloud
55 Metrics
.GcpPromoBucket
= {
56 // Used when the Google Cloud Print promotion (shown above the PDF preview
57 // plugin) is shown to the user.
59 // Used when the user clicks the "Get started" link in the promotion shown
60 // in CLOUDPRINT_BIG_PROMO_SHOWN.
62 // Used when the user dismisses the promotion shown in
63 // CLOUDPRINT_BIG_PROMO_SHOWN.
66 GCP_PROMO_MAX_BUCKET
: 3
70 * Print settings UI usage metrics buckets.
73 Metrics
.PrintSettingsUiBucket
= {
74 // Advanced settings dialog is shown.
75 ADVANCED_SETTINGS_DIALOG_SHOWN
: 0,
76 // Advanced settings dialog is closed without saving a selection.
77 ADVANCED_SETTINGS_DIALOG_CANCELED
: 1,
79 PRINT_SETTINGS_UI_MAX_BUCKET
: 2
83 * A context for recording a value in a specific UMA histogram.
84 * @param {string} histogram The name of the histogram to be recorded in.
85 * @param {number} maxBucket The max value for the last histogram bucket.
88 function MetricsContext(histogram
, maxBucket
) {
89 /** @private {string} */
90 this.histogram_
= histogram
;
92 /** @private {number} */
93 this.maxBucket_
= maxBucket
;
96 MetricsContext
.prototype = {
98 * Record a histogram value in UMA. If specified value is larger than the
99 * max bucket value, record the value in the largest bucket
100 * @param {number} bucket Value to record.
102 record: function(bucket
) {
103 chrome
.send('metricsHandler:recordInHistogram',
105 ((bucket
> this.maxBucket_
) ? this.maxBucket_
: bucket
),
111 * Destination Search specific usage statistics context.
113 * @implements {MetricsContext}
115 function DestinationSearchMetricsContext() {
118 'PrintPreview.DestinationAction',
119 Metrics
.DestinationSearchBucket
.DESTINATION_SEARCH_MAX_BUCKET
);
122 DestinationSearchMetricsContext
.prototype = {
123 __proto__
: MetricsContext
.prototype
127 * GCP promotion specific usage statistics context.
129 * @implements {MetricsContext}
131 function GcpPromoMetricsContext() {
132 MetricsContext
.call(this,
133 'PrintPreview.GcpPromo',
134 Metrics
.GcpPromoBucket
.GCP_PROMO_MAX_BUCKET
);
137 GcpPromoMetricsContext
.prototype = {
138 __proto__
: MetricsContext
.prototype
142 * Print settings UI specific usage statistics context.
144 * @implements {MetricsContext}
146 function PrintSettingsUiMetricsContext() {
149 'PrintPreview.PrintSettingsUi',
150 Metrics
.PrintSettingsUiBucket
.PRINT_SETTINGS_UI_MAX_BUCKET
);
153 PrintSettingsUiMetricsContext
.prototype = {
154 __proto__
: MetricsContext
.prototype
160 MetricsContext
: MetricsContext
,
161 DestinationSearchMetricsContext
: DestinationSearchMetricsContext
,
162 GcpPromoMetricsContext
: GcpPromoMetricsContext
,
163 PrintSettingsUiMetricsContext
: PrintSettingsUiMetricsContext