Bug 1152264 - Push API constantly doing requests. r=nsm
authorFernando Rodriguez Sela <frsela@tid.es>
Mon, 11 May 2015 07:06:00 -0400
changeset 269381 b9efa70a359a85bbf673ba4d52e15315fe19c1df
parent 269380 f86c710c4074ea4700404c6d050c3d544e5c4655
child 269382 a281ea0a58e6fa186a622fadecd3aa1b2f2589fb
push id2501
push userjosea.olivera@gmail.com
push dateWed, 03 Jun 2015 06:55:32 +0000
reviewersnsm
bugs1152264
milestone41.0a1
Bug 1152264 - Push API constantly doing requests. r=nsm
dom/push/PushService.jsm
--- a/dom/push/PushService.jsm
+++ b/dom/push/PushService.jsm
@@ -55,16 +55,19 @@ const kUDP_WAKEUP_WS_STATUS_CODE = 4774;
                                           // by server to signal that it can
                                           // wake client up using UDP.
 
 const kCHILD_PROCESS_MESSAGES = ["Push:Register", "Push:Unregister",
                                  "Push:Registration"];
 
 const kWS_MAX_WENTDOWN = 2;
 
+// 1 minute is the least allowed ping interval
+const kWS_MIN_PING_INTERVAL = 60000;
+
 // This is a singleton
 this.PushDB = function PushDB() {
   debug("PushDB()");
 
   // set the indexeddb database
   this.initDBHelper(kPUSHDB_DB_NAME, kPUSHDB_DB_VERSION,
                     [kPUSHDB_STORE_NAME]);
 };
@@ -798,17 +801,21 @@ this.PushService = {
     if (!this._recalculatePing && wsWentDown) {
       debug('Websocket disconnected without ping adaptative algorithm running');
       this._wsWentDownCounter++;
       if (this._wsWentDownCounter > kWS_MAX_WENTDOWN) {
         debug('Too many disconnects. Reenabling ping adaptative algoritm');
         this._wsWentDownCounter = 0;
         this._recalculatePing = true;
         this._lastGoodPingInterval = Math.floor(lastTriedPingInterval / 2);
-        nextPingInterval = this._lastGoodPingInterval;
+        if (this._lastGoodPingInterval < kWS_MIN_PING_INTERVAL) {
+          nextPingInterval = kWS_MIN_PING_INTERVAL;
+        } else {
+          nextPingInterval = this._lastGoodPingInterval;
+        }
         prefs.set('pingInterval', nextPingInterval);
         this._save(ns, nextPingInterval);
         return;
       }
 
       debug('We do not need to recalculate the ping, based on previous data');
     }