Bug 1416987 - Force an update when safebrowsing tables are changed in preference. r=francois,johannh

This patch adds a |ForceUpdates| API in listmanager so when we change Safe Browsing tables,
we can use this API to force an update to ensure new tables are downloaded immediately.

If the update fails for any reason (Server is down for example), then the new tables will have
to wait until next update time.

MozReview-Commit-ID: 3Zh1pU8XaYo

--HG--
extra : rebase_source : 215cd2f4484b07663566024bfa5e182ee3807d4e
This commit is contained in:
DimiL 2017-11-29 10:33:26 +08:00
Родитель 13b5a0e017
Коммит b0c17b073d
5 изменённых файлов: 60 добавлений и 6 удалений

Просмотреть файл

@ -8,7 +8,6 @@ const CONTENT_LIST_ID = "content";
const TRACK_SUFFIX = "-track-digest256";
const TRACKING_TABLE_PREF = "urlclassifier.trackingTable";
const LISTS_PREF_BRANCH = "browser.safebrowsing.provider.mozilla.lists.";
const UPDATE_TIME_PREF = "browser.safebrowsing.provider.mozilla.nextupdatetime";
var gBlocklistManager = {
_type: "",
@ -119,7 +118,13 @@ var gBlocklistManager = {
trackingTable += "," + CONTENT_LIST_ID + TRACK_SUFFIX;
}
Services.prefs.setCharPref(TRACKING_TABLE_PREF, trackingTable);
Services.prefs.setCharPref(UPDATE_TIME_PREF, 42);
// Force an update after changing the tracking protection table.
let listmanager = Components.classes["@mozilla.org/url-classifier/listmanager;1"]
.getService(Components.interfaces.nsIUrlListManager);
if (listmanager) {
listmanager.forceUpdates(trackingTable);
}
}
window.close();

Просмотреть файл

@ -1127,6 +1127,13 @@ var gPrivacyPane = {
malware.sort();
malwareTable.value = malware.join(",");
// Force an update after changing the malware table.
let listmanager = Components.classes["@mozilla.org/url-classifier/listmanager;1"]
.getService(Components.interfaces.nsIUrlListManager);
if (listmanager) {
listmanager.forceUpdates(malwareTable.value);
}
});
// set initial values

Просмотреть файл

@ -66,6 +66,14 @@ interface nsIUrlListManager : nsISupports
*/
boolean checkForUpdates(in ACString updateUrl);
/**
* Force updates for the given tables, updates are still restricted to
* backoff algorithm.
* @param tables A string lists all the tables that we want to trigger updates.
* table names are separated with ','.
*/
boolean forceUpdates(in ACString tableNames);
/**
* This is currently used by about:url-classifier to get back-off time
* (in millisecond since epoch) for the given provider. Return 0 if we

Просмотреть файл

@ -329,6 +329,42 @@ PROT_ListManager.prototype.maybeToggleUpdateChecking = function() {
}
};
/**
* Force updates for the given tables. This API may trigger more than one update
* if the table lists provided belong to multiple updateurl (multiple provider).
* Return false when any update is fail due to back-off algorithm.
*/
PROT_ListManager.prototype.forceUpdates = function(tables) {
log("forceUpdates with " + tables);
if (!tables) {
return false;
}
let updateUrls = new Set();
tables.split(",").forEach((table) => {
if (this.tablesData[table]) {
updateUrls.add(this.tablesData[table].updateUrl);
}
});
let ret = true;
updateUrls.forEach((url) => {
// Cancel current update timer for the url because we are forcing an update.
if (this.updateCheckers_[url]) {
this.updateCheckers_[url].cancel();
this.updateCheckers_[url] = null;
}
// Trigger an update for the given url.
if (!this.checkForUpdates(url)) {
ret = false;
}
});
return ret;
};
/**
* Updates our internal tables from the update server
*

Просмотреть файл

@ -174,11 +174,9 @@ var Provider = {
.getService(Ci.nsIUrlListManager);
let pref = "browser.safebrowsing.provider." + provider + ".lists";
let tables = Services.prefs.getCharPref(pref, "").split(",");
let table = tables.find(t => listmanager.getUpdateUrl(t) != "");
let tables = Services.prefs.getCharPref(pref, "");
let updateUrl = listmanager.getUpdateUrl(table);
if (!listmanager.checkForUpdates(updateUrl)) {
if (!listmanager.forceUpdates(tables)) {
// This may because of back-off algorithm.
let elem = document.getElementById(provider + "-col-lastupdateresult");
elem.childNodes[0].nodeValue = bundle.GetStringFromName("CannotUpdate");