Bug 1357116 - Load the blocklist updater module lazily r=florian,mgoodwin

MozReview-Commit-ID: IjdpY9JZQPL

--HG--
extra : rebase_source : 1c2968fff0c0a11f0adf68f0bc9b0905ed4ac457
This commit is contained in:
Mathieu Leplatre 2017-04-27 14:45:57 +02:00
Родитель 3a39f96514
Коммит ec15502b47
3 изменённых файлов: 35 добавлений и 24 удалений

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

@ -18,12 +18,11 @@ const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {});
Cu.importGlobalProperties(["fetch"]);
const { Kinto } = Cu.import("resource://services-common/kinto-offline-client.js", {});
const { KintoHttpClient } = Cu.import("resource://services-common/kinto-http-client.js", {});
const { FirefoxAdapter } = Cu.import("resource://services-common/kinto-storage-adapter.js", {});
const { CanonicalJSON } = Components.utils.import("resource://gre/modules/CanonicalJSON.jsm", {});
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", "resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Kinto", "resource://services-common/kinto-offline-client.js");
XPCOMUtils.defineLazyModuleGetter(this, "KintoHttpClient", "resource://services-common/kinto-http-client.js");
XPCOMUtils.defineLazyModuleGetter(this, "FirefoxAdapter", "resource://services-common/kinto-storage-adapter.js");
XPCOMUtils.defineLazyModuleGetter(this, "CanonicalJSON", "resource://gre/modules/CanonicalJSON.jsm");
const KEY_APPDIR = "XCurProcD";
const PREF_SETTINGS_SERVER = "services.settings.server";
@ -96,10 +95,7 @@ class BlocklistClient {
this.bucketName = bucketName;
this.signerName = signerName;
this._kinto = new Kinto({
bucket: bucketName,
adapter: FirefoxAdapter,
});
this._kinto = null;
}
get identifier() {
@ -187,6 +183,13 @@ class BlocklistClient {
const enforceCollectionSigning =
Services.prefs.getBoolPref(PREF_BLOCKLIST_ENFORCE_SIGNING);
if (!this._kinto) {
this._kinto = new Kinto({
bucket: this.bucketName,
adapter: FirefoxAdapter,
});
}
// if there is a signerName and collection signing is enforced, add a
// hook for incoming changes that validates the signature
let hooks;

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

@ -6,10 +6,10 @@ this.EXPORTED_SYMBOLS = ["checkVersions", "addTestBlocklistClient"];
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.importGlobalProperties(["fetch"]);
const BlocklistClients = Cu.import("resource://services-common/blocklist-clients.js", {});
const PREF_SETTINGS_SERVER = "services.settings.server";
const PREF_SETTINGS_SERVER_BACKOFF = "services.settings.server.backoff";
@ -19,13 +19,18 @@ const PREF_BLOCKLIST_LAST_ETAG = "services.blocklist.last_etag";
const PREF_BLOCKLIST_CLOCK_SKEW_SECONDS = "services.blocklist.clock_skew_seconds";
const gBlocklistClients = {
[BlocklistClients.OneCRLBlocklistClient.collectionName]: BlocklistClients.OneCRLBlocklistClient,
[BlocklistClients.AddonBlocklistClient.collectionName]: BlocklistClients.AddonBlocklistClient,
[BlocklistClients.GfxBlocklistClient.collectionName]: BlocklistClients.GfxBlocklistClient,
[BlocklistClients.PluginBlocklistClient.collectionName]: BlocklistClients.PluginBlocklistClient,
[BlocklistClients.PinningPreloadClient.collectionName]: BlocklistClients.PinningPreloadClient
};
XPCOMUtils.defineLazyGetter(this, "gBlocklistClients", function() {
const BlocklistClients = Cu.import("resource://services-common/blocklist-clients.js", {});
return {
[BlocklistClients.OneCRLBlocklistClient.collectionName]: BlocklistClients.OneCRLBlocklistClient,
[BlocklistClients.AddonBlocklistClient.collectionName]: BlocklistClients.AddonBlocklistClient,
[BlocklistClients.GfxBlocklistClient.collectionName]: BlocklistClients.GfxBlocklistClient,
[BlocklistClients.PluginBlocklistClient.collectionName]: BlocklistClients.PluginBlocklistClient,
[BlocklistClients.PinningPreloadClient.collectionName]: BlocklistClients.PinningPreloadClient,
};
});
// Add a blocklist client for testing purposes. Do not use for any other purpose
this.addTestBlocklistClient = (name, client) => { gBlocklistClients[name] = client; }

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

@ -33,6 +33,12 @@ XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest",
"resource://gre/modules/ServiceRequest.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
// The blocklist updater is the new system in charge of fetching remote data
// securely and efficiently. It will replace the current XML-based system.
// See Bug 1257565 and Bug 1252456.
const BlocklistUpdater = {};
XPCOMUtils.defineLazyModuleGetter(BlocklistUpdater, "checkVersions",
"resource://services-common/blocklist-updater.js");
const TOOLKIT_ID = "toolkit@mozilla.org";
const KEY_PROFILEDIR = "ProfD";
@ -601,14 +607,11 @@ Blocklist.prototype = {
if (!this._isBlocklistLoaded())
this._loadBlocklist();
// If kinto update is enabled, do the kinto update
// If blocklist update via Kinto is enabled, poll for changes and sync.
// Currently certificates blocklist relies on it by default.
if (gPref.getBoolPref(PREF_BLOCKLIST_UPDATE_ENABLED)) {
const updater =
Components.utils.import("resource://services-common/blocklist-updater.js",
{});
updater.checkVersions().catch(() => {
// Before we enable this in release, we want to collect telemetry on
// failed kinto updates - see bug 1254099
BlocklistUpdater.checkVersions().catch(() => {
// Bug 1254099 - Telemetry (success or errors) will be collected during this process.
});
}
},