Bug 1402064 Refactor compatibility overrides r=kmag

Compatibility override data was previously stored in an object attached
to each AddonInternal instance and awkwardly copied around in various
places.  In the new AMO API, compatibility overrides come from a different
API endpoint -- lay the groundwork for maintaining that data separately
inside AddonRepository by creating a new internal API for fetching
compatibility override data.  Note there is some code related to staged
installs of non-restartless addons that refers to the old
compatabilityOverrides property, that code should ideally get removed
soon but for now it is unreachable.

MozReview-Commit-ID: EUZhPsTc2q

--HG--
extra : rebase_source : 23268c991e68a087e0882783156fb668301a52ef
This commit is contained in:
Andrew Swan 2018-02-05 20:28:49 -08:00
Родитель c95780c281
Коммит 45a6d26761
5 изменённых файлов: 64 добавлений и 31 удалений

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

@ -405,6 +405,40 @@ var AddonRepository = {
return (this.metadataAge() > threshold); return (this.metadataAge() > threshold);
}, },
/**
* Get any compatibility override information for the given add-on id.
*
* @param aId
* The id of the add-on to fetch compatibiltiy override data for.
* @returns Promise
* A Promise which resolves with the compatibility override
* data for the given add-on, if any is available.
*/
async getCompatibilityOverrides(aId) {
let addon = await new Promise(resolve => this.getCachedAddonByID(aId, resolve));
return addon ? addon.compatibilityOverrides : null;
},
/**
* Synchronously get any compatibility override information for
* the given add-on id.
*
* @param aId
* The id of the add-on to fetch compatibiltiy override data for.
* @returns object
* Compatibility override data for the given add-on, if any is
* available. Note that this method does not do any I/O so if
* the database has not been read and cacheAddons() has not been
* called for the given id, this may return null even when there
* is a compatibility override for the addon.
*/
getCompatibilityOverridesSync(aId) {
if (this._addons == null || !this._addons.has(aId)) {
return null;
}
return this._addons.get(aId).compatibilityOverrides;
},
/** /**
* Asynchronously get a cached add-on by id. The add-on (or null if the * Asynchronously get a cached add-on by id. The add-on (or null if the
* add-on is not found) is passed to the specified callback. If caching is * add-on is not found) is passed to the specified callback. If caching is

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

@ -1632,9 +1632,6 @@ class AddonInstall {
this.addon._repositoryAddon = repoAddon; this.addon._repositoryAddon = repoAddon;
this.name = this.name || this.addon._repositoryAddon.name; this.name = this.name || this.addon._repositoryAddon.name;
this.addon.compatibilityOverrides = repoAddon ?
repoAddon.compatibilityOverrides :
null;
this.addon.appDisabled = !isUsableAddon(this.addon); this.addon.appDisabled = !isUsableAddon(this.addon);
return undefined; return undefined;
} }
@ -2726,7 +2723,7 @@ UpdateChecker.prototype = {
* @param updates * @param updates
* The list of update details for the add-on * The list of update details for the add-on
*/ */
onUpdateCheckComplete(aUpdates) { async onUpdateCheckComplete(aUpdates) {
XPIProvider.done(this.addon._updateCheck); XPIProvider.done(this.addon._updateCheck);
this.addon._updateCheck = null; this.addon._updateCheck = null;
let AUC = AddonUpdateChecker; let AUC = AddonUpdateChecker;
@ -2784,8 +2781,8 @@ UpdateChecker.prototype = {
} }
let compatOverrides = AddonManager.strictCompatibility ? let compatOverrides = AddonManager.strictCompatibility ?
null : null :
this.addon.compatibilityOverrides; await AddonRepository.getCompatibilityOverrides(this.addon.id);
let update = AUC.getNewestCompatibleUpdate(aUpdates, let update = AUC.getNewestCompatibleUpdate(aUpdates,
this.appVersion, this.appVersion,

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

@ -3938,7 +3938,6 @@ var XPIProvider = {
if (aRepoAddon) { if (aRepoAddon) {
logger.debug("updateAddonRepositoryData got info for " + addon.id); logger.debug("updateAddonRepositoryData got info for " + addon.id);
addon._repositoryAddon = aRepoAddon; addon._repositoryAddon = aRepoAddon;
addon.compatibilityOverrides = aRepoAddon.compatibilityOverrides;
this.updateAddonDisabledState(addon); this.updateAddonDisabledState(addon);
} }
@ -4999,13 +4998,13 @@ AddonInternal.prototype = {
// The repository can specify compatibility overrides. // The repository can specify compatibility overrides.
// Note: For now, only blacklisting is supported by overrides. // Note: For now, only blacklisting is supported by overrides.
if (this._repositoryAddon && let overrides = AddonRepository.getCompatibilityOverridesSync(this.id);
this._repositoryAddon.compatibilityOverrides) { if (overrides) {
let overrides = this._repositoryAddon.compatibilityOverrides;
let override = AddonRepository.findMatchingCompatOverride(this.version, let override = AddonRepository.findMatchingCompatOverride(this.version,
overrides); overrides);
if (override && override.type == "incompatible") if (override) {
return false; return false;
}
} }
// Extremely old extensions should not be compatible by default. // Extremely old extensions should not be compatible by default.
@ -5746,7 +5745,7 @@ function defineAddonWrapperProperty(name, getter) {
["id", "syncGUID", "version", "isCompatible", "isPlatformCompatible", ["id", "syncGUID", "version", "isCompatible", "isPlatformCompatible",
"providesUpdatesSecurely", "blocklistState", "blocklistURL", "appDisabled", "providesUpdatesSecurely", "blocklistState", "blocklistURL", "appDisabled",
"softDisabled", "skinnable", "size", "foreignInstall", "hasBinaryComponents", "softDisabled", "skinnable", "size", "foreignInstall", "hasBinaryComponents",
"strictCompatibility", "compatibilityOverrides", "updateURL", "dependencies", "strictCompatibility", "updateURL", "dependencies",
"getDataDirectory", "multiprocessCompatible", "signedState", "mpcOptedOut", "getDataDirectory", "multiprocessCompatible", "signedState", "mpcOptedOut",
"isCorrectlySigned"].forEach(function(aProp) { "isCorrectlySigned"].forEach(function(aProp) {
defineAddonWrapperProperty(aProp, function() { defineAddonWrapperProperty(aProp, function() {

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

@ -78,9 +78,6 @@ function getRepositoryAddon(aAddon, aCallback) {
} }
function completeAddon(aRepositoryAddon) { function completeAddon(aRepositoryAddon) {
aAddon._repositoryAddon = aRepositoryAddon; aAddon._repositoryAddon = aRepositoryAddon;
aAddon.compatibilityOverrides = aRepositoryAddon ?
aRepositoryAddon.compatibilityOverrides :
null;
aCallback(aAddon); aCallback(aAddon);
} }
AddonRepository.getCachedAddonByID(aAddon.id, completeAddon); AddonRepository.getCachedAddonByID(aAddon.id, completeAddon);

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

@ -187,58 +187,64 @@ function check_compat_status(aCallback) {
function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]) { function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]) {
Assert.notEqual(a1, null); Assert.notEqual(a1, null);
Assert.equal(a1.compatibilityOverrides, null); Assert.equal(AddonRepository.getCompatibilityOverridesSync(a1.id), null);
Assert.ok(a1.isCompatible); Assert.ok(a1.isCompatible);
Assert.ok(!a1.appDisabled); Assert.ok(!a1.appDisabled);
Assert.notEqual(a2, null); Assert.notEqual(a2, null);
Assert.equal(a2.compatibilityOverrides, null); Assert.equal(AddonRepository.getCompatibilityOverridesSync(a2.id), null);
Assert.ok(a2.isCompatible); Assert.ok(a2.isCompatible);
Assert.ok(!a2.appDisabled); Assert.ok(!a2.appDisabled);
Assert.notEqual(a3, null); Assert.notEqual(a3, null);
Assert.notEqual(a3.compatibilityOverrides, null); let overrides = AddonRepository.getCompatibilityOverridesSync(a3.id);
Assert.equal(a3.compatibilityOverrides.length, 1); Assert.notEqual(overrides, null);
Assert.equal(overrides.length, 1);
Assert.ok(!a3.isCompatible); Assert.ok(!a3.isCompatible);
Assert.ok(a3.appDisabled); Assert.ok(a3.appDisabled);
Assert.notEqual(a4, null); Assert.notEqual(a4, null);
Assert.notEqual(a4.compatibilityOverrides, null); overrides = AddonRepository.getCompatibilityOverridesSync(a4.id);
Assert.equal(a4.compatibilityOverrides.length, 1); Assert.notEqual(overrides, null);
Assert.equal(overrides.length, 1);
Assert.ok(!a4.isCompatible); Assert.ok(!a4.isCompatible);
Assert.ok(a4.appDisabled); Assert.ok(a4.appDisabled);
Assert.notEqual(a5, null); Assert.notEqual(a5, null);
Assert.equal(a5.compatibilityOverrides, null); Assert.equal(AddonRepository.getCompatibilityOverridesSync(a5.id), null);
Assert.ok(a5.isCompatible); Assert.ok(a5.isCompatible);
Assert.ok(!a5.appDisabled); Assert.ok(!a5.appDisabled);
Assert.notEqual(a6, null); Assert.notEqual(a6, null);
Assert.notEqual(a6.compatibilityOverrides, null); overrides = AddonRepository.getCompatibilityOverridesSync(a6.id);
Assert.equal(a6.compatibilityOverrides.length, 1); Assert.notEqual(overrides, null);
Assert.equal(overrides.length, 1);
Assert.ok(a6.isCompatible); Assert.ok(a6.isCompatible);
Assert.ok(!a6.appDisabled); Assert.ok(!a6.appDisabled);
Assert.notEqual(a7, null); Assert.notEqual(a7, null);
Assert.notEqual(a7.compatibilityOverrides, null); overrides = AddonRepository.getCompatibilityOverridesSync(a7.id);
Assert.equal(a7.compatibilityOverrides.length, 1); Assert.notEqual(overrides, null);
Assert.equal(overrides.length, 1);
Assert.ok(a7.isCompatible); Assert.ok(a7.isCompatible);
Assert.ok(!a7.appDisabled); Assert.ok(!a7.appDisabled);
Assert.notEqual(a8, null); Assert.notEqual(a8, null);
Assert.notEqual(a8.compatibilityOverrides, null); overrides = AddonRepository.getCompatibilityOverridesSync(a8.id);
Assert.equal(a8.compatibilityOverrides.length, 3); Assert.notEqual(overrides, null);
Assert.equal(overrides.length, 3);
Assert.ok(!a8.isCompatible); Assert.ok(!a8.isCompatible);
Assert.ok(a8.appDisabled); Assert.ok(a8.appDisabled);
Assert.notEqual(a9, null); Assert.notEqual(a9, null);
Assert.notEqual(a9.compatibilityOverrides, null); overrides = AddonRepository.getCompatibilityOverridesSync(a9.id);
Assert.equal(a9.compatibilityOverrides.length, 1); Assert.notEqual(overrides, null);
Assert.equal(overrides.length, 1);
Assert.ok(!a9.isCompatible); Assert.ok(!a9.isCompatible);
Assert.ok(a9.appDisabled); Assert.ok(a9.appDisabled);
Assert.notEqual(a10, null); Assert.notEqual(a10, null);
Assert.equal(a10.compatibilityOverrides, null); Assert.equal(AddonRepository.getCompatibilityOverridesSync(a10.id), null);
Assert.ok(a10.isCompatible); Assert.ok(a10.isCompatible);
Assert.ok(!a10.appDisabled); Assert.ok(!a10.appDisabled);