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

Side by Side Diff: chrome/browser/resources/google_now/background.js

Issue 154653003: Count All Cards for Explanatory Link Support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/cards.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 */ 77 */
78 var DEFAULT_OPTIN_CHECK_PERIOD_SECONDS = 60 * 60 * 24 * 7; // 1 week 78 var DEFAULT_OPTIN_CHECK_PERIOD_SECONDS = 60 * 60 * 24 * 7; // 1 week
79 79
80 /** 80 /**
81 * URL to open when the user clicked on a link for the our notification 81 * URL to open when the user clicked on a link for the our notification
82 * settings. 82 * settings.
83 */ 83 */
84 var SETTINGS_URL = 'https://support.google.com/chrome/?p=ib_google_now_welcome'; 84 var SETTINGS_URL = 'https://support.google.com/chrome/?p=ib_google_now_welcome';
85 85
86 /** 86 /**
87 * Number of location cards that need an explanatory link. 87 * Number of cards that need an explanatory link.
88 */ 88 */
89 var LOCATION_CARDS_LINK_THRESHOLD = 10; 89 var EXPLANATORY_CARDS_LINK_THRESHOLD = 4;
90 90
91 /** 91 /**
92 * Names for tasks that can be created by the extension. 92 * Names for tasks that can be created by the extension.
93 */ 93 */
94 var UPDATE_CARDS_TASK_NAME = 'update-cards'; 94 var UPDATE_CARDS_TASK_NAME = 'update-cards';
95 var DISMISS_CARD_TASK_NAME = 'dismiss-card'; 95 var DISMISS_CARD_TASK_NAME = 'dismiss-card';
96 var RETRY_DISMISS_TASK_NAME = 'retry-dismiss'; 96 var RETRY_DISMISS_TASK_NAME = 'retry-dismiss';
97 var STATE_CHANGED_TASK_NAME = 'state-changed'; 97 var STATE_CHANGED_TASK_NAME = 'state-changed';
98 var SHOW_ON_START_TASK_NAME = 'show-cards-on-start'; 98 var SHOW_ON_START_TASK_NAME = 'show-cards-on-start';
99 var ON_PUSH_MESSAGE_START_TASK_NAME = 'on-push-message'; 99 var ON_PUSH_MESSAGE_START_TASK_NAME = 'on-push-message';
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 notificationGroups: updatedGroups, 544 notificationGroups: updatedGroups,
545 recentDismissals: updatedRecentDismissals 545 recentDismissals: updatedRecentDismissals
546 }); 546 });
547 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); 547 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS);
548 }, 548 },
549 onCardShown); 549 onCardShown);
550 }); 550 });
551 } 551 }
552 552
553 /** 553 /**
554 * Update Location Cards Shown Count. 554 * Update the Explanatory Total Cards Shown Count.
555 * @param {ReceivedNotification} receivedNotification Notification as it was
556 * received from the server.
557 */ 555 */
558 function countLocationCard(receivedNotification) { 556 function countExplanatoryCard() {
559 if (receivedNotification.locationBased) { 557 localStorage['explanatoryCardsShown']++;
560 localStorage['locationCardsShown']++;
561 }
562 } 558 }
563 559
564 /** 560 /**
565 * Requests notification cards from the server for specified groups. 561 * Requests notification cards from the server for specified groups.
566 * @param {Array.<string>} groupNames Names of groups that need to be refreshed. 562 * @param {Array.<string>} groupNames Names of groups that need to be refreshed.
567 */ 563 */
568 function requestNotificationGroups(groupNames) { 564 function requestNotificationGroups(groupNames) {
569 console.log('requestNotificationGroups from ' + NOTIFICATION_CARDS_URL + 565 console.log('requestNotificationGroups from ' + NOTIFICATION_CARDS_URL +
570 ', groupNames=' + JSON.stringify(groupNames)); 566 ', groupNames=' + JSON.stringify(groupNames));
571 567
572 recordEvent(GoogleNowEvent.REQUEST_FOR_CARDS_TOTAL); 568 recordEvent(GoogleNowEvent.REQUEST_FOR_CARDS_TOTAL);
573 569
574 var requestParameters = '?timeZoneOffsetMs=' + 570 var requestParameters = '?timeZoneOffsetMs=' +
575 (-new Date().getTimezoneOffset() * MS_IN_MINUTE); 571 (-new Date().getTimezoneOffset() * MS_IN_MINUTE);
576 572
577 var cardShownCallback = undefined; 573 var cardShownCallback = undefined;
578 if (localStorage['locationCardsShown'] < LOCATION_CARDS_LINK_THRESHOLD) { 574 var belowExplanatoryThreshold =
579 requestParameters += '&locationExplanation=true'; 575 localStorage['explanatoryCardsShown'] < EXPLANATORY_CARDS_LINK_THRESHOLD;
580 cardShownCallback = countLocationCard; 576 if (belowExplanatoryThreshold) {
577 requestParameters += '&cardExplanation=true';
578 cardShownCallback = countExplanatoryCard;
581 } 579 }
582 580
583 groupNames.forEach(function(groupName) { 581 groupNames.forEach(function(groupName) {
584 requestParameters += ('&requestTypes=' + groupName); 582 requestParameters += ('&requestTypes=' + groupName);
585 }); 583 });
586 584
587 console.log('requestNotificationGroups: request=' + requestParameters); 585 console.log('requestNotificationGroups: request=' + requestParameters);
588 586
589 var request = buildServerRequest('GET', 'notifications' + requestParameters); 587 var request = buildServerRequest('GET', 'notifications' + requestParameters);
590 588
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 lastPollNowPayloads: items.lastPollNowPayloads, 1232 lastPollNowPayloads: items.lastPollNowPayloads,
1235 notificationGroups: items.notificationGroups 1233 notificationGroups: items.notificationGroups
1236 }); 1234 });
1237 1235
1238 updateNotificationsCards(); 1236 updateNotificationsCards();
1239 } 1237 }
1240 }); 1238 });
1241 }); 1239 });
1242 } 1240 }
1243 }); 1241 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/cards.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698