mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1212649 - Put an upper limit on Safe Browsing polling interval. r=gcp
This commit is contained in:
parent
aba451034e
commit
04bf0e5958
@ -15,6 +15,10 @@ Cu.import("resource://gre/modules/Services.jsm");
|
||||
// TODO more comprehensive update tests, for example add unittest check
|
||||
// that the listmanagers tables are properly written on updates
|
||||
|
||||
// Lower and upper limits on the server-provided polling frequency
|
||||
const minDelayMs = 5 * 60 * 1000;
|
||||
const maxDelayMs = 24 * 60 * 60 * 1000;
|
||||
|
||||
// Log only if browser.safebrowsing.debug is true
|
||||
this.log = function log(...stuff) {
|
||||
var prefs_ = new G_Preferences();
|
||||
@ -232,7 +236,7 @@ PROT_ListManager.prototype.kickoffUpdate_ = function (onDiskTableData)
|
||||
let targetPref = "browser.safebrowsing.provider." + provider + ".nextupdatetime";
|
||||
let nextUpdate = this.prefs_.getPref(targetPref);
|
||||
if (nextUpdate) {
|
||||
updateDelay = Math.max(0, nextUpdate - Date.now());
|
||||
updateDelay = Math.min(maxDelayMs, Math.max(0, nextUpdate - Date.now()));
|
||||
log("Next update at " + nextUpdate);
|
||||
}
|
||||
log("Next update " + updateDelay + "ms from now");
|
||||
@ -429,19 +433,23 @@ PROT_ListManager.prototype.updateSuccess_ = function(tableList, updateUrl,
|
||||
waitForUpdate) {
|
||||
log("update success for " + tableList + " from " + updateUrl + ": " +
|
||||
waitForUpdate + "\n");
|
||||
var delay;
|
||||
var delay = 0;
|
||||
if (waitForUpdate) {
|
||||
delay = parseInt(waitForUpdate, 10);
|
||||
delay = parseInt(waitForUpdate, 10) * 1000;
|
||||
}
|
||||
// As long as the delay is something sane (5 minutes or more), update
|
||||
// As long as the delay is something sane (5 min to 1 day), update
|
||||
// our delay time for requesting updates. We always use a non-repeating
|
||||
// timer since the delay is set differently at every callback.
|
||||
if (delay >= (5 * 60)) {
|
||||
log("Waiting " + delay + " seconds");
|
||||
delay = delay * 1000;
|
||||
} else {
|
||||
log("Ignoring delay from server, waiting " + this.updateInterval / 1000);
|
||||
if (delay > maxDelayMs) {
|
||||
log("Ignoring delay from server (too long), waiting " +
|
||||
maxDelayMs + "ms");
|
||||
delay = maxDelayMs;
|
||||
} else if (delay < minDelayMs) {
|
||||
log("Ignoring delay from server (too short), waiting " +
|
||||
this.updateInterval + "ms");
|
||||
delay = this.updateInterval;
|
||||
} else {
|
||||
log("Waiting " + delay + "ms");
|
||||
}
|
||||
this.updateCheckers_[updateUrl] =
|
||||
new G_Alarm(BindToObject(this.checkForUpdates, this, updateUrl),
|
||||
|
Loading…
Reference in New Issue
Block a user