Skip to content

Commit

Permalink
Backed out 8 changesets (bug 1620621) for build bustages. CLOSED TREE
Browse files Browse the repository at this point in the history
Backed out changeset 14a57e32c414 (bug 1620621)
Backed out changeset 56b2b19a9bc1 (bug 1620621)
Backed out changeset 6df42b7528ec (bug 1620621)
Backed out changeset c23703684254 (bug 1620621)
Backed out changeset 206ad824e1bc (bug 1620621)
Backed out changeset e0f3e057b311 (bug 1620621)
Backed out changeset 12817823a3c9 (bug 1620621)
Backed out changeset 80dcb089ce8e (bug 1620621)
  • Loading branch information
Razvan Maries committed Apr 30, 2020
1 parent 7ebc740 commit cb804e5
Show file tree
Hide file tree
Showing 42 changed files with 9 additions and 1,861 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,6 @@ module.exports = {
"toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
"toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js",
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_mlbf.js",
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_mlbf_fetch.js",
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_mlbf_update.js",
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_regexp_split.js",
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js",
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_telemetry.js",
Expand Down
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2332,15 +2332,12 @@ pref("extensions.abuseReport.amoDetailsURL", "https://services.addons.mozilla.or

// Blocklist preferences
pref("extensions.blocklist.enabled", true);
pref("extensions.blocklist.useMLBF", false);
pref("extensions.blocklist.useMLBF.stashes", false);
// Required blocklist freshness for OneCRL OCSP bypass (default is 30 hours)
// Note that this needs to exceed the interval at which we update OneCRL data,
// configured in services.settings.poll_interval .
pref("security.onecrl.maximum_staleness_in_seconds", 108000);
pref("extensions.blocklist.detailsURL", "https://blocked.cdn.mozilla.net/");
pref("extensions.blocklist.itemURL", "https://blocked.cdn.mozilla.net/%blockID%.html");
pref("extensions.blocklist.addonItemURL", "https://addons.mozilla.org/%LOCALE%/%APP%/blocked-addon/%addonID%/%addonVersion%/");
// Controls what level the blocklist switches from warning about items to forcibly
// blocking them.
pref("extensions.blocklist.level", 2);
Expand All @@ -2349,9 +2346,6 @@ pref("services.blocklist.bucket", "blocklists");
pref("services.blocklist.addons.collection", "addons");
pref("services.blocklist.addons.checked", 0);
pref("services.blocklist.addons.signer", "remote-settings.content-signature.mozilla.org");
pref("services.blocklist.addons-mlbf.collection", "addons-bloomfilters");
pref("services.blocklist.addons-mlbf.checked", 0);
pref("services.blocklist.addons-mlbf.signer", "remote-settings.content-signature.mozilla.org");
pref("services.blocklist.plugins.collection", "plugins");
pref("services.blocklist.plugins.checked", 0);
pref("services.blocklist.plugins.signer", "remote-settings.content-signature.mozilla.org");
Expand Down
14 changes: 0 additions & 14 deletions services/common/docs/RemoteSettings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,11 @@ The provided helper will:
This will allow us to package attachments as part of a Firefox release (see `Bug 1542177 <https://bugzilla.mozilla.org/show_bug.cgi?id=1542177>`_)
and return them to calling code as ``resource://`` from within a package archive.

.. note::

By default, the ``download()`` method is prone to leaving extraneous files in the profile directory
(see `Bug 1634127 <https://bugzilla.mozilla.org/show_bug.cgi?id=1634127>`_).
Pass the ``useCache`` option to use an IndexedDB-based cache, and unlock the following features:

The ``fallbackToCache`` option allows callers to fall back to the cached file and record, if the requested record's attachment fails to download.
This enables callers to always have a valid pair of attachment and record,
provided that the attachment has been retrieved at least once.

The ``fallbackToDump`` option activates a fallback to a dump that has been
packaged with the client, when other ways to load the attachment have failed.

.. note::

A ``downloadAsBytes()`` method returning an ``ArrayBuffer`` is also available, if writing the attachment into the user profile is not necessary.



.. _services/initial-data:

Initial data
Expand Down
197 changes: 1 addition & 196 deletions services/settings/Attachments.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -44,173 +44,6 @@ class Downloader {
this._cdnURL = null;
}

/**
* @returns {Object} An object with async "get", "set" and "delete" methods.
* The keys are strings, the values may be any object that
* can be stored in IndexedDB (including Blob).
*/
get cacheImpl() {
throw new Error("This Downloader does not support caching");
}

/**
* Download attachment and return the result together with the record.
* If the requested record cannot be downloaded and fallbacks are enabled, the
* returned attachment may have a different record than the input record.
*
* @param {Object} record A Remote Settings entry with attachment.
* If omitted, the attachmentId option must be set.
* @param {Object} options Some download options.
* @param {Number} options.retries Number of times download should be retried (default: `3`)
* @param {Number} options.checkHash Check content integrity (default: `true`)
* @param {string} options.attachmentId The attachment identifier to use for
* caching and accessing the attachment.
* (default: record.id)
* @param {Boolean} options.useCache Whether to use a cache to read and store
* the attachment. (default: false)
* @param {Boolean} options.fallbackToCache Return the cached attachment when the
* input record cannot be fetched.
* (default: false)
* @param {Boolean} options.fallbackToDump Use the remote settings dump as a
* potential source of the attachment.
* (default: false)
* @throws {Downloader.DownloadError} if the file could not be fetched.
* @throws {Downloader.BadContentError} if the downloaded content integrity is not valid.
* @returns {Object} An object with two properties:
* buffer: ArrayBuffer with the file content.
* record: Record associated with the bytes.
* _source: identifies the source of the result. Used for testing.
*/
async download(record, options) {
let {
retries,
checkHash,
attachmentId = record?.id,
useCache = false,
fallbackToCache = false,
fallbackToDump = false,
} = options || {};

if (!useCache) {
// For backwards compatibility.
// WARNING: Its return type is different from what's documented.
// See downloadToDisk's documentation.
return this.downloadToDisk(record, options);
}

if (!this.cacheImpl) {
throw new Error("useCache is true but there is no cacheImpl!");
}

if (!attachmentId) {
// Check for pre-condition. This should not happen, but it is explicitly
// checked to avoid mixing up attachments, which could be dangerous.
throw new Error("download() was called without attachmentId or recordID");
}

let buffer, cachedRecord;
if (useCache) {
try {
let cached = await this.cacheImpl.get(attachmentId);
if (cached) {
cachedRecord = cached.record;
buffer = await cached.blob.arrayBuffer();
}
} catch (e) {
Cu.reportError(e);
}
}

if (buffer && record) {
const { size, hash } = cachedRecord.attachment;
if (
record.attachment.size === size &&
record.attachment.hash === hash &&
(await RemoteSettingsWorker.checkContentHash(buffer, size, hash))
) {
// Best case: File already downloaded and still up to date.
return { buffer, record: cachedRecord, _source: "cache_match" };
}
}

let errorIfAllFails;

// No cached attachment available. Check if an attachment is available in
// the dump that is packaged with the client.
let dumpInfo;
if (fallbackToDump && record) {
try {
dumpInfo = await this._readAttachmentDump(attachmentId);
// Check if there is a match. If there is no match, we will fall through
// to the next case (downloading from the network). We may still use the
// dump at the end of the function as the ultimate fallback.
if (record.attachment.hash === dumpInfo.record.attachment.hash) {
return {
buffer: await dumpInfo.readBuffer(),
record: dumpInfo.record,
_source: "dump_match",
};
}
} catch (e) {
fallbackToDump = false;
errorIfAllFails = e;
}
}

// There is no local version that matches the requested record.
// Try to download the attachment specified in record.
if (record && record.attachment) {
try {
const newBuffer = await this.downloadAsBytes(record, {
retries,
checkHash,
});
const blob = new Blob([newBuffer]);
if (useCache) {
// Caching is optional, don't wait for the cache before returning.
this.cacheImpl
.set(attachmentId, { record, blob })
.catch(e => Cu.reportError(e));
}
return { buffer: newBuffer, record, _source: "remote_match" };
} catch (e) {
// No network, corrupted content, etc.
errorIfAllFails = e;
}
}

// Unable to find an attachment that matches the record. Consider falling
// back to local versions, even if their attachment hash do not match the
// one from the requested record.

if (buffer && fallbackToCache) {
const { size, hash } = cachedRecord.attachment;
if (await RemoteSettingsWorker.checkContentHash(buffer, size, hash)) {
return { buffer, record: cachedRecord, _source: "cache_fallback" };
}
}

// Unable to find a valid attachment, fall back to the packaged dump.
if (fallbackToDump) {
try {
dumpInfo = dumpInfo || (await this._readAttachmentDump(attachmentId));
return {
buffer: await dumpInfo.readBuffer(),
record: dumpInfo.record,
_source: "dump_fallback",
};
} catch (e) {
errorIfAllFails = e;
}
}

if (errorIfAllFails) {
throw errorIfAllFails;
}

throw new Downloader.DownloadError(attachmentId);
}

/**
* Download the record attachment into the local profile directory
* and return a file:// URL that points to the local path.
Expand All @@ -224,7 +57,7 @@ class Downloader {
* @throws {Downloader.BadContentError} if the downloaded file integrity is not valid.
* @returns {String} the absolute file path to the downloaded attachment.
*/
async downloadToDisk(record, options = {}) {
async download(record, options = {}) {
const { retries = 3 } = options;
const {
attachment: { filename, size, hash },
Expand Down Expand Up @@ -328,10 +161,6 @@ class Downloader {
await this._rmDirs();
}

async deleteCached(attachmentId) {
return this.cacheImpl.delete(attachmentId);
}

async _baseAttachmentsURL() {
if (!this._cdnURL) {
const server = Services.prefs.getCharPref("services.settings.server");
Expand All @@ -358,30 +187,6 @@ class Downloader {
return resp.arrayBuffer();
}

async _readAttachmentDump(attachmentId) {
async function fetchResource(resourceUrl) {
try {
return await fetch(resourceUrl);
} catch (e) {
throw new Downloader.DownloadError(resourceUrl);
}
}
const resourceUrlPrefix =
Downloader._RESOURCE_BASE_URL + "/" + this.folders.join("/") + "/";
const recordUrl = `${resourceUrlPrefix}${attachmentId}.meta.json`;
const attachmentUrl = `${resourceUrlPrefix}${attachmentId}`;
const record = await (await fetchResource(recordUrl)).json();
return {
record,
async readBuffer() {
return (await fetchResource(attachmentUrl)).arrayBuffer();
},
};
}

// Separate variable to allow tests to override this.
static _RESOURCE_BASE_URL = "resource://app/defaults";

async _makeDirs() {
const dirPath = OS.Path.join(
OS.Constants.Path.localProfileDir,
Expand Down
44 changes: 0 additions & 44 deletions services/settings/Database.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -191,50 +191,6 @@ class Database {
}
}

async getAttachment(attachmentId) {
let entry = null;
try {
await executeIDB(
"attachments",
store => {
store.get([this.identifier, attachmentId]).onsuccess = e => {
entry = e.target.result;
};
},
{ mode: "readonly" }
);
} catch (e) {
throw new IDBHelpers.IndexedDBError(
e,
"getAttachment()",
this.identifier
);
}
return entry ? entry.attachment : null;
}

async saveAttachment(attachmentId, attachment) {
try {
await executeIDB(
"attachments",
store => {
if (attachment) {
store.put({ cid: this.identifier, attachmentId, attachment });
} else {
store.delete([this.identifier, attachmentId]);
}
},
{ desc: "saveAttachment(" + attachmentId + ") in " + this.identifier }
);
} catch (e) {
throw new IDBHelpers.IndexedDBError(
e,
"saveAttachment()",
this.identifier
);
}
}

async clear() {
try {
await this.saveLastModified(null);
Expand Down
16 changes: 0 additions & 16 deletions services/settings/RemoteSettingsClient.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,6 @@ class AttachmentDownloader extends Downloader {
this._client = client;
}

get cacheImpl() {
const cacheImpl = {
get: async attachmentId => {
return this._client.db.getAttachment(attachmentId);
},
set: async (attachmentId, attachment) => {
return this._client.db.saveAttachment(attachmentId, attachment);
},
delete: async attachmentId => {
return this._client.db.saveAttachment(attachmentId, null);
},
};
Object.defineProperty(this, "cacheImpl", { value: cacheImpl });
return cacheImpl;
}

/**
* Download attachment and report Telemetry on failure.
*
Expand Down

This file was deleted.

Empty file.

This file was deleted.

Loading

0 comments on commit cb804e5

Please sign in to comment.