Bug 1159310 - Remember the push count and last push time for
☠☠ backed out by dba7f19ace95 ☠ ☠
authorDoug Turner <doug.turner@gmail.com>
Tue, 28 Apr 2015 09:40:57 -0700
changeset 272885 0efce0a97efed09025032ae8e1af0a663e9a7feb
parent 272884 6efd5103d7661ae23a16e01006376eb60281aafa
child 272886 e615ea7d9f2123787064c5ed1974c0c2da158005
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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(a28aba06-8582-4030-8f43-ba15f14061e5)]
 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")
       );
     });
   },