6a034850419b7bbfbea8a894672c836c2fa6dae0
[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     // Max value.
47     DESTINATION_SEARCH_MAX_BUCKET: 11
48   };
49
50   /**
51    * Enumeration of buckets that a user can enter while using the Google Cloud
52    * Print promotion.
53    * @enum {number}
54    */
55   Metrics.GcpPromoBucket = {
56     // Used when the Google Cloud Print promotion (shown above the PDF preview
57     // plugin) is shown to the user.
58     PROMO_SHOWN: 0,
59     // Used when the user clicks the "Get started" link in the promotion shown
60     // in CLOUDPRINT_BIG_PROMO_SHOWN.
61     PROMO_CLICKED: 1,
62     // Used when the user dismisses the promotion shown in
63     // CLOUDPRINT_BIG_PROMO_SHOWN.
64     PROMO_CLOSED: 2,
65     // Max value.
66     GCP_PROMO_MAX_BUCKET: 3
67   };
68
69   /**
70    * Print settings UI usage metrics buckets.
71    * @enum {number}
72    */
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,
78     // Max value.
79     PRINT_SETTINGS_UI_MAX_BUCKET: 2
80   };
81
82   /**
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.
86    * @constructor
87    */
88   function MetricsContext(histogram, maxBucket) {
89     /** @private {string} */
90     this.histogram_ = histogram;
91
92     /** @private {number} */
93     this.maxBucket_ = maxBucket;
94   };
95
96   MetricsContext.prototype = {
97     /**
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.
101      */
102     record: function(bucket) {
103       chrome.send('metricsHandler:recordInHistogram',
104                   [this.histogram_,
105                    ((bucket > this.maxBucket_) ? this.maxBucket_ : bucket),
106                    this.maxBucket_]);
107     }
108   };
109
110   /**
111    * Destination Search specific usage statistics context.
112    * @constructor
113    * @implements {MetricsContext}
114    */
115   function DestinationSearchMetricsContext() {
116     MetricsContext.call(
117         this,
118         'PrintPreview.DestinationAction',
119         Metrics.DestinationSearchBucket.DESTINATION_SEARCH_MAX_BUCKET);
120   };
121
122   DestinationSearchMetricsContext.prototype = {
123     __proto__: MetricsContext.prototype
124   };
125
126   /**
127    * GCP promotion specific usage statistics context.
128    * @constructor
129    * @implements {MetricsContext}
130    */
131   function GcpPromoMetricsContext() {
132     MetricsContext.call(this,
133                         'PrintPreview.GcpPromo',
134                         Metrics.GcpPromoBucket.GCP_PROMO_MAX_BUCKET);
135   };
136
137   GcpPromoMetricsContext.prototype = {
138     __proto__: MetricsContext.prototype
139   };
140
141   /**
142    * Print settings UI specific usage statistics context.
143    * @constructor
144    * @implements {MetricsContext}
145    */
146   function PrintSettingsUiMetricsContext() {
147     MetricsContext.call(
148         this,
149         'PrintPreview.PrintSettingsUi',
150         Metrics.PrintSettingsUiBucket.PRINT_SETTINGS_UI_MAX_BUCKET);
151   };
152
153   PrintSettingsUiMetricsContext.prototype = {
154     __proto__: MetricsContext.prototype
155   };
156
157   // Export
158   return {
159     Metrics: Metrics,
160     MetricsContext: MetricsContext,
161     DestinationSearchMetricsContext: DestinationSearchMetricsContext,
162     GcpPromoMetricsContext: GcpPromoMetricsContext,
163     PrintSettingsUiMetricsContext: PrintSettingsUiMetricsContext
164   };
165 });