summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/automatic_settings_reset_banner.js
blob: 15877ad4b7fdf8d69f24123a2546c291b873813d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Note: the native-side handler for this is AutomaticSettingsResetHandler.

cr.define('options', function() {
  /** @const */ var SettingsBannerBase = options.SettingsBannerBase;

  /**
   * AutomaticSettingsResetBanner class
   * Provides encapsulated handling of the Reset Profile Settings banner.
   * @constructor
   */
  function AutomaticSettingsResetBanner() {}

  cr.addSingletonGetter(AutomaticSettingsResetBanner);

  AutomaticSettingsResetBanner.prototype = {
    __proto__: SettingsBannerBase.prototype,

    /**
     * Initializes the banner's event handlers.
     */
    initialize: function() {
      this.showMetricName_ = 'AutomaticSettingsReset_WebUIBanner_BannerShown';

      this.dismissNativeCallbackName_ =
          'onDismissedAutomaticSettingsResetBanner';

      this.setVisibilibyDomElement_ = $('automatic-settings-reset-banner');

      $('automatic-settings-reset-banner-close').onclick = function(event) {
        chrome.send('metricsHandler:recordAction',
            ['AutomaticSettingsReset_WebUIBanner_ManuallyClosed']);
        AutomaticSettingsResetBanner.dismiss();
      };
      $('automatic-settings-reset-learn-more').onclick = function(event) {
        chrome.send('metricsHandler:recordAction',
            ['AutomaticSettingsReset_WebUIBanner_LearnMoreClicked']);
      };
    },
  };

  // Forward public APIs to private implementations.
  [
    'show',
    'dismiss',
  ].forEach(function(name) {
    AutomaticSettingsResetBanner[name] = function() {
      var instance = AutomaticSettingsResetBanner.getInstance();
      return instance[name + '_'].apply(instance, arguments);
    };
  });

  // Export
  return {
    AutomaticSettingsResetBanner: AutomaticSettingsResetBanner
  };
});