On Tue, Apr 3, 2012 at 5:04 AM, Gervase Markham <
ge...@mozilla.org> wrote:
> On 02/04/12 22:01, Justin Lebar wrote:
>> Since we need to give pages a way to ask to stay alive and be
>> awoken, it's my view that we should aggressively throttle, pause, and
>> kill other pages.
>
> The downside to this policy is that pages then need to be explicitly
> coded to use the new APIs to work as apps; if they aren't, they'll be
> unbackground-able.
That's not the downside of specifically this policy. It's the
downside of the policy of "we can shoot any tab at any time for the
sake of memory pressure", which, as far as I know, is common to all
proposals here.
Indeed, Fennec (at one point, anyway) would nuke all but the active
tab on memory pressure. If you later opened a nuked tab, it would be
session-restored.
We're even thinking of doing something like this in desktop Firefox [1].
> I don't know what the B2G/Apps team's view is on whether one of our
> goals is for current web pages to work well as apps without special
> enhancement, but if we'd like that, then our defaults for background
> permissions stuff might need to support that use case.
None of the proposals thus far would allow background apps to work
without modification. I do not think unmodified background apps
working is compatible with allowing us to close apps on memory
pressure, and I think the latter is critical to the platform's
success.
I'd further argue that we'd need a "background app" API even if we
were to decide never to shoot apps when we're under memory pressure.
(Therefore we might as well aggressively pause and kill apps.) On a
mobile device, when the screen goes to sleep, we would like to put the
CPU into a low-power state.
But obviously, if you're playing music, or you're on a phone call, or
whatever, we want the CPU to stay alive.
Android has the concept of a "CPU wake lock" for this purpose. We're
implementing something similar for b2g. [2]. It will be a privileged
API, just like geolocation.
It seems to me that we can just say "if you hold a CPU wake lock,
we'll make every effort not to kill you while you're in the
background. Otherwise, we may aggressively pause you, and we may kill
you at any point."
If an app really wanted to stay alive only while your phone's screen
was on, then turn off as soon as the screen turns off, it could hold a
CPU wake lock and listen for an event indicating that the screen is
off. But I can't think of a use-case for this behavior, so I suspect
it would be rare.
-Justin
[1]
https://bugzilla.mozilla.org/show_bug.cgi?id=675539
[2]
https://bugzilla.mozilla.org/show_bug.cgi?id=739913
> Gerv