From 4fc3418733d4c0d8e3041ca5900755cc2fa4140f Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Thu, 20 Apr 2017 10:35:04 +0200 Subject: [PATCH] Bug 1357116 - Load the blocklist updater module lazily r=florian,mgoodwin Importing the blocklist-updater module on each notification in nsBlocklistService could cause us to periodically jank the browser UI. This patch now lazy loads as many dependencies as possible. MozReview-Commit-ID: HBGjSJi5PwE --HG-- extra : rebase_source : 4a7c18fe64b810f54d52eee07883d67837b297d3 --- services/common/blocklist-clients.js | 28 ++++++++++++------- services/common/blocklist-updater.js | 19 +++++++------ .../mozapps/extensions/nsBlocklistService.js | 18 +++++++----- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/services/common/blocklist-clients.js b/services/common/blocklist-clients.js index 91efa1b0e2c4..a2e1188d92be 100644 --- a/services/common/blocklist-clients.js +++ b/services/common/blocklist-clients.js @@ -17,12 +17,16 @@ Cu.import("resource://gre/modules/XPCOMUtils.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, "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"; @@ -95,10 +99,7 @@ class BlocklistClient { this.bucketName = bucketName; this.signerName = signerName; - this._kinto = new Kinto({ - bucket: bucketName, - adapter: FirefoxAdapter, - }); + this._kinto = null; } get identifier() { @@ -183,6 +184,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; diff --git a/services/common/blocklist-updater.js b/services/common/blocklist-updater.js index 6c674f7d9545..78c72d777433 100644 --- a/services/common/blocklist-updater.js +++ b/services/common/blocklist-updater.js @@ -6,9 +6,9 @@ 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.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"; @@ -18,13 +18,16 @@ 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; } diff --git a/toolkit/mozapps/extensions/nsBlocklistService.js b/toolkit/mozapps/extensions/nsBlocklistService.js index 8103c4ae9b93..df4c5684e12c 100644 --- a/toolkit/mozapps/extensions/nsBlocklistService.js +++ b/toolkit/mozapps/extensions/nsBlocklistService.js @@ -32,6 +32,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "OS", XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest", "resource://gre/modules/ServiceRequest.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"; const KEY_APPDIR = "XCurProcD"; @@ -599,14 +606,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. }); } },