OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * @fileoverview The event page for Google Now for Chrome implementation. | 8 * @fileoverview The event page for Google Now for Chrome implementation. |
9 * The Google Now event page gets Google Now cards from the server and shows | 9 * The Google Now event page gets Google Now cards from the server and shows |
10 * them as Chrome notifications. | 10 * them as Chrome notifications. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 REQUEST_FOR_CARDS_SUCCESS: 1, | 220 REQUEST_FOR_CARDS_SUCCESS: 1, |
221 CARDS_PARSE_SUCCESS: 2, | 221 CARDS_PARSE_SUCCESS: 2, |
222 DISMISS_REQUEST_TOTAL: 3, | 222 DISMISS_REQUEST_TOTAL: 3, |
223 DISMISS_REQUEST_SUCCESS: 4, | 223 DISMISS_REQUEST_SUCCESS: 4, |
224 LOCATION_REQUEST: 5, | 224 LOCATION_REQUEST: 5, |
225 DELETED_LOCATION_UPDATE: 6, | 225 DELETED_LOCATION_UPDATE: 6, |
226 EXTENSION_START: 7, | 226 EXTENSION_START: 7, |
227 DELETED_SHOW_WELCOME_TOAST: 8, | 227 DELETED_SHOW_WELCOME_TOAST: 8, |
228 STOPPED: 9, | 228 STOPPED: 9, |
229 DELETED_USER_SUPPRESSED: 10, | 229 DELETED_USER_SUPPRESSED: 10, |
230 EVENTS_TOTAL: 11 // EVENTS_TOTAL is not an event; all new events need to be | 230 SIGNED_OUT: 11, |
231 NOTIFICATION_DISABLED: 12, | |
232 GOOGLE_NOW_DISABLED: 13, | |
233 EVENTS_TOTAL: 14 // EVENTS_TOTAL is not an event; all new events need to be | |
231 // added before it. | 234 // added before it. |
232 }; | 235 }; |
233 | 236 |
234 /** | 237 /** |
235 * Records a Google Now Event. | 238 * Records a Google Now Event. |
236 * @param {GoogleNowEvent} event Event identifier. | 239 * @param {GoogleNowEvent} event Event identifier. |
237 */ | 240 */ |
238 function recordEvent(event) { | 241 function recordEvent(event) { |
239 var metricDescription = { | 242 var metricDescription = { |
240 metricName: 'GoogleNow.Event', | 243 metricName: 'GoogleNow.Event', |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
946 chrome.permissions.request({permissions: ['background']}); | 949 chrome.permissions.request({permissions: ['background']}); |
947 else | 950 else |
948 chrome.permissions.remove({permissions: ['background']}); | 951 chrome.permissions.remove({permissions: ['background']}); |
949 } else { | 952 } else { |
950 console.log('Action Ignored setBackgroundEnable=' + backgroundEnable); | 953 console.log('Action Ignored setBackgroundEnable=' + backgroundEnable); |
951 } | 954 } |
952 }); | 955 }); |
953 } | 956 } |
954 | 957 |
955 /** | 958 /** |
959 * Report why this extension would not poll for cards. | |
960 * @param {boolean} signedIn true if the user is signed in. | |
961 * @param {boolean} notificationEnabled true if | |
962 * Google Now for Chrome is allowed to show notifications. | |
963 * @param {boolean} googleNowEnabled true if | |
964 * the Google Now is enabled for the user. | |
965 */ | |
966 function reportNoCardsMetrics(signedIn, notificationEnabled, googleNowEnabled) { | |
rgustafson
2014/03/24 23:18:26
recordEventsIfNoCards possibly?
recordEvent is th
robliao
2014/03/24 23:27:03
sgtm
On 2014/03/24 23:18:26, rgustafson wrote:
| |
967 if (!signedIn) { | |
968 recordEvent(GoogleNowEvent.SIGNED_OUT); | |
969 } else if (!notificationEnabled) { | |
970 recordEvent(GoogleNowEvent.NOTIFICATION_DISABLED); | |
971 } else if (!googleNowEnabled) { | |
972 recordEvent(GoogleNowEvent.GOOGLE_NOW_DISABLED); | |
973 } | |
974 } | |
975 | |
976 /** | |
956 * Does the actual work of deciding what Google Now should do | 977 * Does the actual work of deciding what Google Now should do |
957 * based off of the current state of Chrome. | 978 * based off of the current state of Chrome. |
958 * @param {boolean} signedIn true if the user is signed in. | 979 * @param {boolean} signedIn true if the user is signed in. |
959 * @param {boolean} canEnableBackground true if | 980 * @param {boolean} canEnableBackground true if |
960 * the background permission can be requested. | 981 * the background permission can be requested. |
961 * @param {boolean} notificationEnabled true if | 982 * @param {boolean} notificationEnabled true if |
962 * Google Now for Chrome is allowed to show notifications. | 983 * Google Now for Chrome is allowed to show notifications. |
963 * @param {boolean} googleNowEnabled true if | 984 * @param {boolean} googleNowEnabled true if |
964 * the Google Now is enabled for the user. | 985 * the Google Now is enabled for the user. |
965 */ | 986 */ |
(...skipping 13 matching lines...) Expand all Loading... | |
979 | 1000 |
980 if (signedIn && notificationEnabled) { | 1001 if (signedIn && notificationEnabled) { |
981 if (canEnableBackground && googleNowEnabled) | 1002 if (canEnableBackground && googleNowEnabled) |
982 shouldSetBackground = true; | 1003 shouldSetBackground = true; |
983 | 1004 |
984 shouldPollCards = true; | 1005 shouldPollCards = true; |
985 } else { | 1006 } else { |
986 recordEvent(GoogleNowEvent.STOPPED); | 1007 recordEvent(GoogleNowEvent.STOPPED); |
987 } | 1008 } |
988 | 1009 |
1010 reportNoCardsMetrics(signedIn, notificationEnabled, googleNowEnabled); | |
1011 | |
989 console.log( | 1012 console.log( |
990 'Requested Actions shouldSetBackground=' + shouldSetBackground + ' ' + | 1013 'Requested Actions shouldSetBackground=' + shouldSetBackground + ' ' + |
991 'setShouldPollCards=' + shouldPollCards); | 1014 'setShouldPollCards=' + shouldPollCards); |
992 | 1015 |
993 setBackgroundEnable(shouldSetBackground); | 1016 setBackgroundEnable(shouldSetBackground); |
994 setShouldPollCards(shouldPollCards); | 1017 setShouldPollCards(shouldPollCards); |
995 } | 1018 } |
996 | 1019 |
997 /** | 1020 /** |
998 * Coordinates the behavior of Google Now for Chrome depending on | 1021 * Coordinates the behavior of Google Now for Chrome depending on |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1143 lastPollNowPayloads: items.lastPollNowPayloads, | 1166 lastPollNowPayloads: items.lastPollNowPayloads, |
1144 notificationGroups: items.notificationGroups | 1167 notificationGroups: items.notificationGroups |
1145 }); | 1168 }); |
1146 | 1169 |
1147 requestCards(); | 1170 requestCards(); |
1148 } | 1171 } |
1149 }); | 1172 }); |
1150 }); | 1173 }); |
1151 } | 1174 } |
1152 }); | 1175 }); |
OLD | NEW |