Bug 1159310 - Remember the push count and last push time for push events. r=kit
authorDoug Turner <doug.turner@gmail.com>
Tue, 28 Apr 2015 09:44:00 -0400
changeset 242069 12e0846f854f893bab053cd4920ee2fe76d080b6
parent 242068 bdebff6d07700847e3a0ff55f9ef5a750fc95b08
child 242070 b995a74f067b2c3e4f095826f9b214c28f81164a
push id28679
push userphilringnalda@gmail.com
push dateSat, 02 May 2015 17:02:29 +0000
treeherdermozilla-central@0f5eacc986e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskit
bugs1159310
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1159310 - Remember the push count and last push time for push events. r=kit
dom/interfaces/push/nsIPushObserverNotification.idl
dom/push/PushService.jsm
--- a/dom/interfaces/push/nsIPushObserverNotification.idl
+++ b/dom/interfaces/push/nsIPushObserverNotification.idl
@@ -4,17 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 /**
  * A push message received by an `nsIPushNotificationService`, used as the
  * subject of a `push-notification` observer notification.
  */
-[scriptable, uuid(66a87970-6dc9-46e0-ac61-adb4a13791de)]
+[scriptable, uuid(56f57607-28b6-44b0-aa56-3d4d3c88be15)]
 interface nsIPushObserverNotification : nsISupports
 {
   /* The URL that receives push messages from an application server. */
   attribute string pushEndpoint;
 
   /**
    * The notification version sent by the application server. This is a
    * monotonically increasing number.
@@ -22,9 +22,19 @@ interface nsIPushObserverNotification : 
   attribute long long version;
 
   /**
    * The notification payload. Delivery is not guaranteed; if the browser is
    * offline when the application server sends the push message, the payload
    * may be discarded.
    */
   attribute string data;
+
+  /**
+   * How many times has a push event occured against this pushEndpoint
+   */
+  attribute long long pushCount;
+
+  /**
+   * The last time a push occured against this this pushEndpoint
+   */
+   attribute long long lastPush;
 };
--- a/dom/push/PushService.jsm
+++ b/dom/push/PushService.jsm
@@ -1329,16 +1329,18 @@ this.PushService = {
         debug("No record for channel ID " + aChannelID);
         return;
       }
 
       if (aPushRecord.version == null ||
           aPushRecord.version < aLatestVersion) {
         debug("Version changed, notifying app and updating DB");
         aPushRecord.version = aLatestVersion;
+        aPushRecord.pushCount = aPushRecord.pushCount + 1;
+        aPushRecord.lastPush = new Date().getTime();
         this._notifyApp(aPushRecord);
         this._updatePushRecord(aPushRecord)
           .then(
             null,
             function(e) {
               debug("Error updating push record");
             }
           );
@@ -1393,16 +1395,19 @@ this.PushService = {
     debug("notifyApp() " + aPushRecord.scope);
     let scopeURI = Services.io.newURI(aPushRecord.scope, null, null);
     // Notify XPCOM observers.
     let notification = Cc["@mozilla.org/push/ObserverNotification;1"]
                          .createInstance(Ci.nsIPushObserverNotification);
     notification.pushEndpoint = aPushRecord.pushEndpoint;
     notification.version = aPushRecord.version;
     notification.data = "";
+    notification.lastPush = aPushRecord.lastPush;
+    notification.pushCount = aPushRecord.pushCount;
+
     Services.obs.notifyObservers(
       notification,
       "push-notification",
       aPushRecord.scope
     );
 
     // If permission has been revoked, trash the message.
     if(Services.perms.testExactPermission(scopeURI, "push") != Ci.nsIPermissionManager.ALLOW_ACTION) {
@@ -1533,16 +1538,18 @@ this.PushService = {
       throw "Invalid pushEndpoint " + data.pushEndpoint;
     }
 
     let record = {
       channelID: data.channelID,
       pushEndpoint: data.pushEndpoint,
       pageURL: aPageRecord.pageURL,
       scope: aPageRecord.scope,
+      pushCount: 0,
+      lastPush: 0,
       version: null
     };
 
     debug("scope in _onRegisterSuccess: " + aPageRecord.scope)
 
     return this._updatePushRecord(record)
       .then(
         function() {
@@ -1661,17 +1668,19 @@ this.PushService = {
         return;
       }
       this._db.getByScope(aPageRecord.scope,
         pushRecord => {
           let registration = null;
           if (pushRecord) {
             registration = {
               pushEndpoint: pushRecord.pushEndpoint,
-              version: pushRecord.version
+              version: pushRecord.version,
+              lastPush: pushRecord.lastPush,
+              pushCount: pushRecord.pushCount
             };
           }
           resolve(registration);
         },
         () => reject("Database error")
       );
     });
   },