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'; TODO(vadimt): Uncomment once crbug.com/237617 is fixed. | 5 // 'use strict'; TODO(vadimt): Uncomment once crbug.com/237617 is fixed. |
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 /** | 134 /** |
135 * Diagnostic event identifier. | 135 * Diagnostic event identifier. |
136 * @enum {number} | 136 * @enum {number} |
137 */ | 137 */ |
138 var DiagnosticEvent = { | 138 var DiagnosticEvent = { |
139 REQUEST_FOR_CARDS_TOTAL: 0, | 139 REQUEST_FOR_CARDS_TOTAL: 0, |
140 REQUEST_FOR_CARDS_SUCCESS: 1, | 140 REQUEST_FOR_CARDS_SUCCESS: 1, |
141 CARDS_PARSE_SUCCESS: 2, | 141 CARDS_PARSE_SUCCESS: 2, |
142 DISMISS_REQUEST_TOTAL: 3, | 142 DISMISS_REQUEST_TOTAL: 3, |
143 DISMISS_REQUEST_SUCCESS: 4, | 143 DISMISS_REQUEST_SUCCESS: 4, |
144 EVENTS_TOTAL: 5 // EVENTS_TOTAL is not an event; all new events need to be | 144 LOCATION_REQUEST: 5, |
| 145 LOCATION_UPDATE: 6, |
| 146 EVENTS_TOTAL: 7 // EVENTS_TOTAL is not an event; all new events need to be |
145 // added before it. | 147 // added before it. |
146 }; | 148 }; |
147 | 149 |
148 /** | 150 /** |
149 * Records a diagnostic event. | 151 * Records a diagnostic event. |
150 * @param {DiagnosticEvent} event Event identifier. | 152 * @param {DiagnosticEvent} event Event identifier. |
151 */ | 153 */ |
152 function recordEvent(event) { | 154 function recordEvent(event) { |
153 var metricDescription = { | 155 var metricDescription = { |
154 metricName: 'GoogleNow.Event', | 156 metricName: 'GoogleNow.Event', |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | 358 request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); |
357 tasks.debugSetStepName('requestNotificationCards-send-request'); | 359 tasks.debugSetStepName('requestNotificationCards-send-request'); |
358 request.send(requestParameters); | 360 request.send(requestParameters); |
359 } | 361 } |
360 | 362 |
361 /** | 363 /** |
362 * Starts getting location for a cards update. | 364 * Starts getting location for a cards update. |
363 */ | 365 */ |
364 function requestLocation() { | 366 function requestLocation() { |
365 console.log('requestLocation'); | 367 console.log('requestLocation'); |
| 368 recordEvent(DiagnosticEvent.LOCATION_REQUEST); |
366 // TODO(vadimt): Figure out location request options. | 369 // TODO(vadimt): Figure out location request options. |
367 chrome.location.watchLocation(LOCATION_WATCH_NAME, {}); | 370 chrome.location.watchLocation(LOCATION_WATCH_NAME, {}); |
368 } | 371 } |
369 | 372 |
370 | 373 |
371 /** | 374 /** |
372 * Obtains new location; requests and shows notification cards based on this | 375 * Obtains new location; requests and shows notification cards based on this |
373 * location. | 376 * location. |
374 * @param {Location} position Location of this computer. | 377 * @param {Location} position Location of this computer. |
375 */ | 378 */ |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 onNotificationClicked(notificationId, function(actionUrls) { | 599 onNotificationClicked(notificationId, function(actionUrls) { |
597 if (!Array.isArray(actionUrls.buttonUrls)) | 600 if (!Array.isArray(actionUrls.buttonUrls)) |
598 return undefined; | 601 return undefined; |
599 | 602 |
600 return actionUrls.buttonUrls[buttonIndex]; | 603 return actionUrls.buttonUrls[buttonIndex]; |
601 }); | 604 }); |
602 }); | 605 }); |
603 | 606 |
604 chrome.notifications.onClosed.addListener(onNotificationClosed); | 607 chrome.notifications.onClosed.addListener(onNotificationClosed); |
605 | 608 |
606 chrome.location.onLocationUpdate.addListener(updateNotificationsCards); | 609 chrome.location.onLocationUpdate.addListener(function(position) { |
| 610 recordEvent(DiagnosticEvent.LOCATION_UPDATE); |
| 611 updateNotificationsCards(position); |
| 612 }); |
OLD | NEW |