New issue
Advanced search Search tips

Issue 748298 link

Starred by 3 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

chrome.power API should release requests when app windows are closed

Project Member Reported by derat@chromium.org, Jul 25 2017

Issue description

(branched from  issue 569981 )

If an app or extension uses chrome.power.requestKeepAwake to request that the system be kept awake or its screen stay on but fails to call releaseKeepAwake later, the request will stay active indefinitely.

This is probably reasonable in the case of a continuously-running extension, but it seems unexpected for an app that's attempting to tie its request to a window that can be closed. Specifically, we saw (and Lann fixed) an issue where Chrome OS's built-in video player didn't release its lock when its window was closed, resulting in the screen staying on.

In the implementation of the API, I tried to use OnExtensionUnloaded() to automatically release locks, but it turns out it's only called when the extension crashes or is disabled, uninstalled, or upgraded.

When I asked about this at https://groups.google.com/a/chromium.org/forum/#!topic/apps-dev/8Otp9etrT8I/discussion, Ken's recommendation was to make requestKeepAwake take an optional option tying the lifetime of the request to the caller's window.

I'm worried that this still requires callers to be aware of the issue and to do the right thing, and that if they're going to do that, they can just release the request when their window is closed instead.

So, I'd still like to find a way to handle window closure automatically if possible. Failing that, I ought to at least update the API docs to call out this subtlety.
 
Perhaps the keep awake should be persistent if called from the background/event page but should be cancelled if called from a closed app window or extension tab/popup.

Comment 2 by lannm@google.com, Jul 26 2017

How about: add a window lifetime option to requestKeepAwake and default it to the current window where that makes sense.

Comment 3 by derat@chromium.org, Aug 4 2017

Ken, would UIThreadExtensionFunction::GetSenderWebContents() be the route to take to get the "caller's window"?

I'm a bit concerned about making a non-backwards-compatible change to an existing API. It probably can't be avoided here without instead depending on app authors to do the right thing themselves, though. :-/
That sounds right to me, yes.

I generally agree regarding non-backwards-compatible changes, but this one seems relatively low-risk, and is something that developers can adapt to relatively easily.
Cc: -roc...@chromium.org rockot@google.com

Sign in to add a comment