Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / google_now / background.js
index 99a7ef4..5d3eaf0 100644 (file)
@@ -48,7 +48,7 @@ var MINIMUM_POLLING_PERIOD_SECONDS = 5 * 60;  // 5 minutes
  * Maximal period for polling for Google Now Notifications cards to use when the
  * period from the server is not available.
  */
-var MAXIMUM_POLLING_PERIOD_SECONDS = 60 * 60;  // 1 hour
+var MAXIMUM_POLLING_PERIOD_SECONDS = 30 * 60;  // 30 minutes
 
 /**
  * Initial period for polling for Google Now optin notification after push
@@ -736,6 +736,17 @@ function requestNotificationCards() {
 }
 
 /**
+ * Determines if an immediate retry should occur based off of the given groups.
+ * The NOR group is expected most often and less latency sensitive, so we will
+ * simply wait MAXIMUM_POLLING_PERIOD_SECONDS before trying again.
+ * @param {Array.<string>} groupNames Names of groups that need to be refreshed.
+ * @return {boolean} Whether a retry should occur.
+ */
+function shouldScheduleRetryFromGroupList(groupNames) {
+  return (groupNames.length != 1) || (groupNames[0] !== 'NOR');
+}
+
+/**
  * Requests and shows notification cards.
  */
 function requestCards() {
@@ -751,7 +762,13 @@ function requestCards() {
         // The cards are requested only if there are no unsent dismissals.
         processPendingDismissals()
             .then(requestNotificationCards)
-            .catch(updateCardsAttempts.scheduleRetry);
+            .catch(function() {
+              return getGroupsToRequest().then(function(groupsToRequest) {
+                if (shouldScheduleRetryFromGroupList(groupsToRequest)) {
+                  updateCardsAttempts.scheduleRetry();
+                }
+              });
+            });
       }
     });
   });
@@ -801,6 +818,7 @@ function requestCardDismissal(
            Promise.resolve() :
            Promise.reject();
   }).catch(function(request) {
+    request = (typeof request === 'object') ? request : {};
     return (request.status == HTTP_BAD_REQUEST ||
            request.status == HTTP_METHOD_NOT_ALLOWED) ?
            Promise.resolve() :