Bug 1683031 - pt 5. Add an assertion and document idle request IDs r=smaug

Add assertions and comments to explain the behaviour/use of the idle request
IDs.

Depends on D99330

Differential Revision: https://phabricator.services.mozilla.com/D100300
This commit is contained in:
Paul Bone 2020-12-22 17:56:46 +00:00
parent df9efaa79e
commit 81d936b141
2 changed files with 11 additions and 5 deletions

View File

@ -170,12 +170,15 @@ IPCResult IdleSchedulerParent::RecvIdleTimeUsed(uint64_t aId) {
// could arrive after the parent has granted the request.
MOZ_ASSERT(IsWaitingForIdle() || IsDoingIdleTask());
if (mCurrentRequestId == aId) {
if (IsWaitingForIdle()) {
remove();
}
mRequestedIdleBudget = TimeDuration();
// The parent process will always know the ID of the current request (since
// the IPC channel is reliable). The IDs are provided so that the client can
// check them (it's possible for the client to race ahead of the server).
MOZ_ASSERT(mCurrentRequestId == aId);
if (IsWaitingForIdle()) {
remove();
}
mRequestedIdleBudget = TimeDuration();
Schedule(nullptr);
return IPC_OK();
}

View File

@ -196,6 +196,9 @@ void IdlePeriodState::RequestIdleToken(TimeStamp aLocalIdlePeriodHint) {
void IdlePeriodState::SetIdleToken(uint64_t aId, TimeDuration aDuration) {
MOZ_ASSERT(NS_IsMainThread(),
"Why are we touching idle state off the main thread?");
// We check the request ID. It's possible that the server may be granting a
// an ealier request that the client has since cancelled and re-requested.
if (mIdleRequestId == aId) {
mIdleToken = TimeStamp::Now() + aDuration;
}