Bug 1369734 - Spin the scheduler tick on idle after sleep-wake or idle-active cycles. r=chutten,florian

This allows to move it out of the user's way, in case we need to gather
telemetry data to build a daily/aborted-session ping.

MozReview-Commit-ID: BrKZHKOJzqk

--HG--
extra : rebase_source : 86ed84c014e98cb3bf88ac1c022a002a1b4adcbc
This commit is contained in:
Alessio Placitelli 2017-06-13 16:18:37 +02:00
parent c292851e8d
commit 0ffee57f11
2 changed files with 14 additions and 6 deletions

View File

@ -415,23 +415,25 @@ var TelemetryScheduler = {
case "active":
// User is back to work, restore the original tick interval.
this._isUserIdle = false;
return this._onSchedulerTick();
return this._onSchedulerTick(true);
case "wake_notification":
// The machine woke up from sleep, trigger a tick to avoid sessions
// spanning more than a day.
// This is needed because sleep time does not count towards timeouts
// on Mac & Linux - see bug 1262386, bug 1204823 et al.
return this._onSchedulerTick();
return this._onSchedulerTick(true);
}
return undefined;
},
/**
* Performs a scheduler tick. This function manages Telemetry recurring operations.
* @param {Boolean} [dispatchOnIdle=false] If true, the tick is dispatched in the
* next idle cycle of the main thread.
* @return {Promise} A promise, only used when testing, resolved when the scheduled
* operation completes.
*/
_onSchedulerTick() {
_onSchedulerTick(dispatchOnIdle = false) {
// This call might not be triggered from a timeout. In that case we don't want to
// leave any previously scheduled timeouts pending.
this._clearTimeout();
@ -443,7 +445,12 @@ var TelemetryScheduler = {
let promise = Promise.resolve();
try {
promise = this._schedulerTickLogic();
if (dispatchOnIdle) {
promise = new Promise((resolve, reject) =>
Services.tm.mainThread.idleDispatch(() => this._schedulerTickLogic().then(resolve, reject)));
} else {
promise = this._schedulerTickLogic();
}
} catch (e) {
Telemetry.getHistogramById("TELEMETRY_SCHEDULER_TICK_EXCEPTION").add(1);
this._log.error("_onSchedulerTick - There was an exception", e);

View File

@ -1870,9 +1870,10 @@ add_task(async function test_schedulerEnvironmentReschedules() {
[PREF_TEST, {what: TelemetryEnvironment.RECORD_PREF_VALUE}],
]);
await TelemetryController.testReset();
await TelemetryController.testShutdown();
await TelemetryStorage.testClearPendingPings();
PingServer.clearRequests();
await TelemetryController.testReset();
// Set a fake current date and start Telemetry.
let nowDate = fakeNow(2060, 10, 18, 0, 0, 0);
@ -2030,7 +2031,7 @@ add_task(async function test_schedulerUserIdle() {
Assert.equal(schedulerTimeout, SCHEDULER_TICK_IDLE_INTERVAL_MS);
// Send an "active" notification to the scheduler.
fakeIdleNotification("active");
await fakeIdleNotification("active");
// When user is back active, the scheduler tick should be 5 minutes again.
Assert.equal(schedulerTimeout, SCHEDULER_TICK_INTERVAL_MS);