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

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

Issue 121983002: Restoring recently deleted unit tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rgustafson's notes Created 6 years, 11 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 94b019e8df23fc3a0cb13887d0623d7ba3b7ce29..aac89c11d3ac2be6422066026dbb43ab9d70e66b 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -442,33 +442,31 @@ function combineAndShowNotificationCards(
}
/**
- * Parses JSON response from the notification server, shows notifications and
+ * Based on a response from the notification server, shows notifications and
* schedules next update.
- * @param {string} response Server response.
+ * @param {ServerResponse} response Server response.
* @param {function(ReceivedNotification)=} onCardShown Optional parameter
* called when each card is shown.
*/
-function parseAndShowNotificationCards(response, onCardShown) {
- console.log('parseAndShowNotificationCards ' + response);
- /** @type {ServerResponse} */
- var parsedResponse = JSON.parse(response);
+function processServerResponse(response, onCardShown) {
+ console.log('processServerResponse ' + JSON.stringify(response));
- if (parsedResponse.googleNowDisabled) {
+ if (response.googleNowDisabled) {
chrome.storage.local.set({googleNowEnabled: false});
// TODO(vadimt): Remove the line below once the server stops sending groups
// with 'googleNowDisabled' responses.
- parsedResponse.groups = {};
+ response.groups = {};
// Google Now was enabled; now it's disabled. This is a state change.
onStateChange();
}
- var receivedGroups = parsedResponse.groups;
+ var receivedGroups = response.groups;
instrumented.storage.local.get(
['notificationGroups', 'recentDismissals'],
function(items) {
console.log(
- 'parseAndShowNotificationCards-get ' + JSON.stringify(items));
+ 'processServerResponse-get ' + JSON.stringify(items));
items = items || {};
/** @type {Object.<string, StoredNotificationGroup>} */
items.notificationGroups = items.notificationGroups || {};
@@ -489,10 +487,10 @@ function parseAndShowNotificationCards(response, onCardShown) {
}
// Populate groups with corresponding cards.
- if (parsedResponse.notifications) {
- for (var i = 0; i < parsedResponse.notifications.length; ++i) {
+ if (response.notifications) {
+ for (var i = 0; i < response.notifications.length; ++i) {
/** @type {ReceivedNotification} */
- var card = parsedResponse.notifications[i];
+ var card = response.notifications[i];
if (!(card.notificationId in updatedRecentDismissals)) {
var group = receivedGroups[card.groupName];
group.cards = group.cards || [];
@@ -539,7 +537,7 @@ function parseAndShowNotificationCards(response, onCardShown) {
updatedGroups[groupName] = storedGroup;
}
- scheduleNextPoll(updatedGroups, !parsedResponse.googleNowDisabled);
+ scheduleNextPoll(updatedGroups, !response.googleNowDisabled);
combineAndShowNotificationCards(
updatedGroups,
function() {
@@ -595,7 +593,8 @@ function requestNotificationGroups(groupNames) {
console.log('requestNotificationGroups-onloadend ' + request.status);
if (request.status == HTTP_OK) {
recordEvent(GoogleNowEvent.REQUEST_FOR_CARDS_SUCCESS);
- parseAndShowNotificationCards(request.responseText, cardShownCallback);
+ processServerResponse(
+ JSON.parse(request.responseText), cardShownCallback);
}
};
« 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