Open Bug 1307538 Opened 8 years ago Updated 3 months ago

Expose a nsIIdleService-like for user events

Categories

(Core :: Widget, defect, P5)

defect

Tracking

()

People

(Reporter: Yoric, Unassigned)

References

Details

(Whiteboard: tpi:+)

According to the documentation of nsIIdleService, it exposes the duration for which the entire OS has been idle. In many cases, it would be more interesting to know how many seconds since the user has last been active in the application.

The information is mostly available internally through the following:

mozilla::EventStateManager::LatestUserInputStart()
nsIdleService already supports app wide idle time if it's not using polling mode. I think we could make nsIdleService support both modes by adding a new flag to nsIIdleService::AddIdleObserver to choose app-wide or system-wide idle timer.
Good idea. I don't think we can add optional arguments in XPCOM, so this means either adding a new method pair `addIdleObserver2`/ `removeIdleObserver2` or being creative (e.g. use negative durations for event-idle).
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #2)
> Good idea. I don't think we can add optional arguments in XPCOM, so this
> means either adding a new method pair `addIdleObserver2`/
> `removeIdleObserver2` or being creative (e.g. use negative durations for
> event-idle).

Actually you can use [optional] in XPCOM so we can use the same method name.
Mmmh... I'm looking at nsIdleService, and while I see claims that it's listening for application events, I don't find any code backing that claim. What am I missing?
> Actually you can use [optional] in XPCOM so we can use the same method name.

(ah, right, long time no XPIDL)
Flags: needinfo?(kchen)
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #4)
> Mmmh... I'm looking at nsIdleService, and while I see claims that it's
> listening for application events, I don't find any code backing that claim.
> What am I missing?

It uses nsIIdleServiceInternal::ResetIdleTimeout to record input events in widget event handler
 [1] http://searchfox.org/mozilla-central/search?q=ResetIdleTimeout&case=false&regexp=false&path=
 [2] http://searchfox.org/mozilla-central/rev/76609a05d6ef7ba4223ed79e479c73fb2543a107/widget/nsIdleService.cpp#528
and here it computes the idle time based on the last input event
 [3] http://searchfox.org/mozilla-central/rev/76609a05d6ef7ba4223ed79e479c73fb2543a107/widget/nsIdleService.cpp#632-637
 [4] http://searchfox.org/mozilla-central/rev/76609a05d6ef7ba4223ed79e479c73fb2543a107/widget/nsIdleService.cpp#672-687

I think we need to extract that to two classes and use them in nsIdleService

  nsIdleService  <--+----- nsAppIdleService
                    |
                    `----- nsSystemIdleService

And make AddIdleObserver queue observers to the appropriate service.
Flags: needinfo?(kchen)
Component: Performance Monitoring → Widget
Product: Toolkit → Core
Priority: -- → P5
Whiteboard: tpi:+
Blocks: 1353440
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.