Home | History | Annotate | Download | only in print_preview
      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 metrics bucket groups. Each group describes a set of events
     16    * that can happen in order. This implies that an event cannot occur twice and
     17    * an event that occurs semantically before another event, should not occur
     18    * after.
     19    * @enum {number}
     20    */
     21   Metrics.BucketGroup = {
     22     DESTINATION_SEARCH: 0,
     23     GCP_PROMO: 1
     24   };
     25 
     26   /**
     27    * Enumeration of buckets that a user can enter while using the destination
     28    * search widget.
     29    * @enum {number}
     30    */
     31   Metrics.DestinationSearchBucket = {
     32     // Used when the print destination search widget is shown.
     33     SHOWN: 0,
     34     // Used when the user selects a print destination.
     35     DESTINATION_SELECTED: 1,
     36     // Used when the print destination search widget is closed without selecting
     37     // a print destination.
     38     CANCELED: 2,
     39     // Used when the Google Cloud Print promotion (shown in the destination
     40     // search widget) is shown to the user.
     41     CLOUDPRINT_PROMO_SHOWN: 3,
     42     // Used when the user chooses to sign-in to their Google account.
     43     SIGNIN_TRIGGERED: 4,
     44     // Used when a user selects the privet printer in a pair of duplicate
     45     // privet and cloud printers.
     46     PRIVET_DUPLICATE_SELECTED: 5,
     47     // Used when a user selects the cloud printer in a pair of duplicate
     48     // privet and cloud printers.
     49     CLOUD_DUPLICATE_SELECTED: 6,
     50     // Used when a user sees a register promo for a cloud print printer.
     51     REGISTER_PROMO_SHOWN: 7,
     52     // Used when a user selects a register promo for a cloud print printer.
     53     REGISTER_PROMO_SELECTED: 8,
     54     // User changed active account.
     55     ACCOUNT_CHANGED: 9,
     56     // User tried to log into another account.
     57     ADD_ACCOUNT_SELECTED: 10
     58   };
     59 
     60   /**
     61    * Enumeration of buckets that a user can enter while using the Google Cloud
     62    * Print promotion.
     63    * @enum {number}
     64    */
     65   Metrics.GcpPromoBucket = {
     66     // Used when the Google Cloud Print pomotion (shown above the pdf preview
     67     // plugin) is shown to the user.
     68     SHOWN: 0,
     69     // Used when the user clicks the "Get started" link in the promotion shown
     70     // in CLOUDPRINT_BIG_PROMO_SHOWN.
     71     CLICKED: 1,
     72     // Used when the user dismisses the promotion shown in
     73     // CLOUDPRINT_BIG_PROMO_SHOWN.
     74     DISMISSED: 2
     75   };
     76 
     77   /**
     78    * Name of the C++ function to call to increment bucket counts.
     79    * @type {string}
     80    * @const
     81    * @private
     82    */
     83   Metrics.NATIVE_FUNCTION_NAME_ = 'reportUiEvent';
     84 
     85   Metrics.prototype = {
     86     /**
     87      * Increments the counter of a destination-search bucket.
     88      * @param {!Metrics.DestinationSearchBucket} bucket Bucket to increment.
     89      */
     90     incrementDestinationSearchBucket: function(bucket) {
     91       chrome.send(Metrics.NATIVE_FUNCTION_NAME_,
     92                   [Metrics.BucketGroup.DESTINATION_SEARCH, bucket]);
     93     },
     94 
     95     /**
     96      * Increments the counter of a gcp-promo bucket.
     97      * @param {!Metrics.GcpPromoBucket} bucket Bucket to increment.
     98      */
     99     incrementGcpPromoBucket: function(bucket) {
    100       chrome.send(Metrics.NATIVE_FUNCTION_NAME_,
    101                   [Metrics.BucketGroup.GCP_PROMO, bucket]);
    102     }
    103   };
    104 
    105   // Export
    106   return {
    107     Metrics: Metrics
    108   };
    109 });
    110