Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4451)

Unified Diff: chrome/browser/resources/google_now/background.js

Issue 22912021: Handling errors from chrome APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/background_unittest.gtestjs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/google_now/background.js
diff --git a/chrome/browser/resources/google_now/background.js b/chrome/browser/resources/google_now/background.js
index 787c3329dc3cd645d454dbfd2a013156656c31f4..399ed960aeb7b15217cf72f68711bb59e0309814 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -23,8 +23,7 @@
// TODO(vadimt): Honor the flag the enables Google Now integration.
// TODO(vadimt): Figure out the final values of the constants.
// TODO(vadimt): Remove 'console' calls.
-// TODO(vadimt): Consider sending JS stacks for chrome.* API errors and
-// malformed server responses.
+// TODO(vadimt): Consider sending JS stacks for malformed server responses.
/**
* Standard response code for successful HTTP requests. This is the only success
@@ -346,6 +345,7 @@ function removeAllCards() {
// notifications center and bug 260376 is fixed, the below clearing
// code is no longer necessary.
instrumented.notifications.getAll(function(notifications) {
+ notifications = notifications || {};
for (var notificationId in notifications) {
chrome.notifications.clear(notificationId, function() {});
}
@@ -405,7 +405,7 @@ function requestLocation() {
console.log('requestLocation');
recordEvent(GoogleNowEvent.LOCATION_REQUEST);
// TODO(vadimt): Figure out location request options.
- chrome.metricsPrivate.getVariationParams('GoogleNow', function(params) {
+ instrumented.metricsPrivate.getVariationParams('GoogleNow', function(params) {
var minDistanceInMeters =
parseInt(params && params.minDistanceInMeters, 10) ||
100;
@@ -582,15 +582,12 @@ function retryPendingDismissals() {
*/
function onNotificationClicked(notificationId, selector) {
instrumented.storage.local.get('notificationsData', function(items) {
- items.notificationsData = items.notificationsData || {};
-
- var notificationData = items.notificationsData[notificationId];
+ var notificationData = items &&
+ items.notificationsData &&
+ items.notificationsData[notificationId];
- if (!notificationData) {
- // 'notificationsData' in storage may not match the actual list of
- // notifications.
+ if (!notificationData)
return;
- }
var actionUrls = notificationData.actionUrls;
if (typeof actionUrls != 'object') {
@@ -598,8 +595,7 @@ function onNotificationClicked(notificationId, selector) {
}
var url = selector(actionUrls);
-
- if (typeof url != 'string')
+ if (!url)
return;
instrumented.tabs.create({url: url}, function(tab) {
@@ -886,7 +882,8 @@ function onStateChange() {
instrumented.storage.local.get(
'userRespondedToToast',
function(items) {
- var userRespondedToToast = !!items.userRespondedToToast;
+ var userRespondedToToast =
+ !items || !!items.userRespondedToToast;
updateRunningState(
signedIn,
geolocationEnabled,
@@ -974,10 +971,9 @@ instrumented.notifications.onButtonClicked.addListener(
chrome.metricsPrivate.recordUserAction(
'GoogleNow.ButtonClicked' + buttonIndex);
onNotificationClicked(notificationId, function(actionUrls) {
- if (!Array.isArray(actionUrls.buttonUrls))
- return undefined;
-
- return actionUrls.buttonUrls[buttonIndex];
+ var url = actionUrls.buttonUrls[buttonIndex];
+ verify(url, 'onButtonClicked: no url for a button');
+ return url;
});
}
});
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/background_unittest.gtestjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698