Closed Bug 851253 Opened 11 years ago Closed 11 years ago

SimplePush: Only wake up registered applications using push-register

Categories

(Firefox OS Graveyard :: General, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(firefox21 wontfix, firefox22 wontfix, firefox23 fixed, b2g18+ fixed, b2g18-v1.0.0 wontfix, b2g18-v1.0.1 wontfix)

RESOLVED FIXED
Tracking Status
firefox21 --- wontfix
firefox22 --- wontfix
firefox23 --- fixed
b2g18 + fixed
b2g18-v1.0.0 --- wontfix
b2g18-v1.0.1 --- wontfix

People

(Reporter: nsm, Assigned: nsm)

References

Details

Attachments

(1 file, 2 obsolete files)

Broadcasting a system message has two drawbacks:

1) It could end up launching 10-20 push enabled apps at the same time, putting serious load on the system. Have a staggered wake up.

2) Don't start push enabled apps unless they actually have active registrations which will need to be refreshed. Apps that've never run or never acquired an endpoint, or no longer have active endpoints should not be started.
@Marcelino, input from Telefonica is welcome here. I'm going to fix this after 822712 lands, only if it is shown to be a problem
@Nikhil I have added Telefonica push guys in CC, so they can give you some feedback, better than me :-)
Attachment #728496 - Attachment is obsolete: true
Attachment #733618 - Flags: review?(justin.lebar+bug)
Comment on attachment 733618 [details] [diff] [review]
only push-register applications with registrations

To be clear, this patch does not appear to stagger the wakeup.  Which is fine.
Attachment #733618 - Flags: review?(justin.lebar+bug) → review+
Oops, I had review comments!

r=me with some nits.

>+      this._db.getAllChannelIDs(function(records) {
>+        this._notifyAllAppsRegister(records);
>+        this._dropRegistrations()
>+          .then(finishHandshake.bind(this));

Nit: I know this is inconsisent with how you did it when the .then() was a
multiline clause, but here it would match our style if you moved the "." in
".then" to align with the "." in the line above.

>@@ -804,21 +796,41 @@ PushService.prototype = {
>       debug("Could not get channelID " + aChannelIDFromServer + " from DB");
>     }
> 
>     this._db.getByChannelID(aChannelID,
>                             compareRecordVersionAndNotify.bind(this),
>                             recoverNoSuchChannelID.bind(this));
>   },
> 
>-  _notifyAllAppsRegister: function() {
>+  // Fires a push-register system message to all applications that have
>+  // registrations.
>+  _notifyAllAppsRegister: function(records) {

Can you please explain in the comment what |records| is supposed to be?  Or
even better: Can we make this function take no arguments and return a promise?
So you'd do something like

  this._notifyAllAppsRegister()
      .then(this._dropRegistrations.bind(this))
      .then(finishHandshake.bind(this));

>     debug("notifyAllAppsRegister()");
>     let messenger = Cc["@mozilla.org/system-message-internal;1"]
>                       .getService(Ci.nsISystemMessagesInternal);
>-    messenger.broadcastMessage('push-register', {});
>+
>+    // Pages to be notified.
>+    // wakeupTable[manifestURL] -> [ pageURL ]
>+    var wakeupTable = {};
>+    for (var i = 0; i < records.length; i++) {
>+      var record = records[i];
>+      if (!wakeupTable[record.manifestURL])

Nit: It's equivalent in this case, but it would be more idiomatic to do |if
(record.manifestURL in wakeupTable)|.
Carrying forward r+ from jlebar and landing.

Convert notifyAllAppsRegister() to promises and fix nits.
Attachment #733618 - Attachment is obsolete: true
Attachment #735414 - Flags: review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/01ffdd61fd94

Marking as [leave open] since part 1 of bug description hasn't been fixed.
Whiteboard: [leave open]
> Marking as [leave open] since part 1 of bug description hasn't been fixed.

Would you mind taking care of that in a separate bug?  Combining landings into multiple bugs often makes it really confusing to understand what's going on, particularly when uplifts are involved.
Summary: Smarter application wake up on push notification push-register message → SimplePush: Only wake up registered applications using push-register
Whiteboard: [leave open]
Filed bug 860041 for additional improvements.
https://hg.mozilla.org/mozilla-central/rev/01ffdd61fd94
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Comment on attachment 735414 [details] [diff] [review]
only push-register applications with registrations

NOTE: Please see https://wiki.mozilla.org/Release_Management/B2G_Landing to better understand the B2G approval process and landings.

[Approval Request Comment]
Bug caused by (feature/regressing bug #): 822712 Push Notifications

User impact if declined: 
Low impact while push has low usage. But if a user installs many applications with push notifications, they'll have a lot more background apps running when notifications arrive, unless this patch is applied.

Testing completed: 
Yes

Risk to taking this patch (and alternatives if risky): 
None as long as push is disabled.

String or UUID changes made by this patch:
None
Attachment #735414 - Flags: approval-mozilla-b2g18?
Attachment #735414 - Flags: approval-mozilla-b2g18? → approval-mozilla-b2g18+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: