Chromium Code Reviews| 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_EVENT: 6, | |
|
rgustafson
2013/05/22 01:18:29
Why location_event? location_update?
vadimt
2013/05/22 02:02:52
Done.
| |
| 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 */ |
| 376 function updateNotificationsCards(position) { | 379 function updateNotificationsCards(position) { |
| 377 console.log('updateNotificationsCards ' + JSON.stringify(position) + | 380 console.log('updateNotificationsCards ' + JSON.stringify(position) + |
| 378 ' @' + new Date()); | 381 ' @' + new Date()); |
| 382 recordEvent(DiagnosticEvent.LOCATION_EVENT); | |
|
rgustafson
2013/05/22 01:18:29
It's not clear that this should only be called fro
vadimt
2013/05/22 02:02:52
Laziness :)
| |
| 379 tasks.add(UPDATE_CARDS_TASK_NAME, function(callback) { | 383 tasks.add(UPDATE_CARDS_TASK_NAME, function(callback) { |
| 380 console.log('updateNotificationsCards-task-begin'); | 384 console.log('updateNotificationsCards-task-begin'); |
| 381 updateCardsAttempts.planForNext(function() { | 385 updateCardsAttempts.planForNext(function() { |
| 382 processPendingDismissals(function(success) { | 386 processPendingDismissals(function(success) { |
| 383 if (success) { | 387 if (success) { |
| 384 // The cards are requested only if there are no unsent dismissals. | 388 // The cards are requested only if there are no unsent dismissals. |
| 385 requestNotificationCards(position, callback); | 389 requestNotificationCards(position, callback); |
| 386 } else { | 390 } else { |
| 387 callback(); | 391 callback(); |
| 388 } | 392 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 if (!Array.isArray(actionUrls.buttonUrls)) | 601 if (!Array.isArray(actionUrls.buttonUrls)) |
| 598 return undefined; | 602 return undefined; |
| 599 | 603 |
| 600 return actionUrls.buttonUrls[buttonIndex]; | 604 return actionUrls.buttonUrls[buttonIndex]; |
| 601 }); | 605 }); |
| 602 }); | 606 }); |
| 603 | 607 |
| 604 chrome.notifications.onClosed.addListener(onNotificationClosed); | 608 chrome.notifications.onClosed.addListener(onNotificationClosed); |
| 605 | 609 |
| 606 chrome.location.onLocationUpdate.addListener(updateNotificationsCards); | 610 chrome.location.onLocationUpdate.addListener(updateNotificationsCards); |
| OLD | NEW |