OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 /** |
| 6 * @fileoverview |
| 7 * Functions and event handlers to invite the user to participate in a survey |
| 8 * to help improve the product. |
| 9 */ |
| 10 |
| 11 'use strict'; |
| 12 |
| 13 /** @suppress {duplicate} */ |
| 14 var remoting = remoting || {}; |
| 15 |
| 16 var kStorageKey = 'feedback-survey-dismissed'; |
| 17 var kSurveyDivId = 'survey-opt-in'; |
| 18 var kSurveyAcceptId = 'survey-accept'; |
| 19 var kSurveyDeclineId = 'survey-decline'; |
| 20 |
| 21 /** |
| 22 * Hide the survey request and record some basic information about the current |
| 23 * state of the world in synced storage. This may be useful in the future if we |
| 24 * want to show the request again. At the moment, the data itself is ignored; |
| 25 * only its presence or absence is important. |
| 26 * |
| 27 * @param {boolean} optIn True if the user clicked the "Take the survey" link; |
| 28 * false if they clicked the close icon. |
| 29 */ |
| 30 remoting.dismissSurvey = function(optIn) { |
| 31 var value = {}; |
| 32 value[kStorageKey] = { |
| 33 optIn: optIn, |
| 34 date: new Date(), |
| 35 version: chrome.runtime.getManifest().version |
| 36 }; |
| 37 chrome.storage.sync.set(value); |
| 38 document.getElementById(kSurveyDivId).hidden = true; |
| 39 }; |
| 40 |
| 41 /** |
| 42 * Show or hide the survey request, depending on whether or not the user has |
| 43 * already seen it. |
| 44 */ |
| 45 remoting.initSurvey = function() { |
| 46 /** @param {Object} value */ |
| 47 var onFeedbackSurveyInfo = function(value) { |
| 48 /** @type {*} */ |
| 49 var dismissed = value[kStorageKey]; |
| 50 document.getElementById(kSurveyDivId).hidden = !!dismissed; |
| 51 }; |
| 52 chrome.storage.sync.get(kStorageKey, onFeedbackSurveyInfo); |
| 53 var accept = document.getElementById(kSurveyAcceptId); |
| 54 var decline = document.getElementById(kSurveyDeclineId); |
| 55 accept.addEventListener( |
| 56 'click', remoting.dismissSurvey.bind(null, true), false); |
| 57 decline.addEventListener( |
| 58 'click', remoting.dismissSurvey.bind(null, false), false); |
| 59 }; |
OLD | NEW |