Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / print_preview / metrics.js
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.
4
5 cr.define('print_preview', function() {
6   'use strict';
7
8   /**
9    * Object used to measure usage statistics.
10    * @constructor
11    */
12   function Metrics() {};
13
14   /**
15    * Enumeration of buckets that a user can enter while using the destination
16    * search widget.
17    * @enum {number}
18    */
19   Metrics.DestinationSearchBucket = {
20     // Used when the print destination search widget is shown.
21     DESTINATION_SHOWN: 0,
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.
29     SIGNIN_PROMPT: 3,
30     // Used when the user chooses to sign-in to their Google account.
31     SIGNIN_TRIGGERED: 4,
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.
43     ACCOUNT_CHANGED: 9,
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,
52     // Max value.
53     DESTINATION_SEARCH_MAX_BUCKET: 14
54   };
55
56   /**
57    * Enumeration of buckets that a user can enter while using the Google Cloud
58    * Print promotion.
59    * @enum {number}
60    */
61   Metrics.GcpPromoBucket = {
62     // Used when the Google Cloud Print promotion (shown above the PDF preview
63     // plugin) is shown to the user.
64     PROMO_SHOWN: 0,
65     // Used when the user clicks the "Get started" link in the promotion shown
66     // in CLOUDPRINT_BIG_PROMO_SHOWN.
67     PROMO_CLICKED: 1,
68     // Used when the user dismisses the promotion shown in
69     // CLOUDPRINT_BIG_PROMO_SHOWN.
70     PROMO_CLOSED: 2,
71     // Max value.
72     GCP_PROMO_MAX_BUCKET: 3
73   };
74
75   /**
76    * Print settings UI usage metrics buckets.
77    * @enum {number}
78    */
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,
92     // Max value.
93     PRINT_SETTINGS_UI_MAX_BUCKET: 6
94   };
95
96   /**
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.
100    * @constructor
101    */
102   function MetricsContext(histogram, maxBucket) {
103     /** @private {string} */
104     this.histogram_ = histogram;
105
106     /** @private {number} */
107     this.maxBucket_ = maxBucket;
108   };
109
110   MetricsContext.prototype = {
111     /**
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.
115      */
116     record: function(bucket) {
117       chrome.send('metricsHandler:recordInHistogram',
118                   [this.histogram_,
119                    ((bucket > this.maxBucket_) ? this.maxBucket_ : bucket),
120                    this.maxBucket_]);
121     }
122   };
123
124   /**
125    * Destination Search specific usage statistics context.
126    * @constructor
127    * @implements {MetricsContext}
128    */
129   function DestinationSearchMetricsContext() {
130     MetricsContext.call(
131         this,
132         'PrintPreview.DestinationAction',
133         Metrics.DestinationSearchBucket.DESTINATION_SEARCH_MAX_BUCKET);
134   };
135
136   DestinationSearchMetricsContext.prototype = {
137     __proto__: MetricsContext.prototype
138   };
139
140   /**
141    * GCP promotion specific usage statistics context.
142    * @constructor
143    * @implements {MetricsContext}
144    */
145   function GcpPromoMetricsContext() {
146     MetricsContext.call(this,
147                         'PrintPreview.GcpPromo',
148                         Metrics.GcpPromoBucket.GCP_PROMO_MAX_BUCKET);
149   };
150
151   GcpPromoMetricsContext.prototype = {
152     __proto__: MetricsContext.prototype
153   };
154
155   /**
156    * Print settings UI specific usage statistics context.
157    * @constructor
158    * @implements {MetricsContext}
159    */
160   function PrintSettingsUiMetricsContext() {
161     MetricsContext.call(
162         this,
163         'PrintPreview.PrintSettingsUi',
164         Metrics.PrintSettingsUiBucket.PRINT_SETTINGS_UI_MAX_BUCKET);
165   };
166
167   PrintSettingsUiMetricsContext.prototype = {
168     __proto__: MetricsContext.prototype
169   };
170
171   // Export
172   return {
173     Metrics: Metrics,
174     MetricsContext: MetricsContext,
175     DestinationSearchMetricsContext: DestinationSearchMetricsContext,
176     GcpPromoMetricsContext: GcpPromoMetricsContext,
177     PrintSettingsUiMetricsContext: PrintSettingsUiMetricsContext
178   };
179 });