Bug 692712 - Pre-filter recommended add-ons JSON instead of filtering at startup [r=wjohnston]

This commit is contained in:
Mark Finkle 2011-10-07 22:13:45 -04:00
Родитель ce5be44164
Коммит 1185080155
3 изменённых файлов: 42 добавлений и 28 удалений

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

@ -130,7 +130,6 @@
let Ci = Components.interfaces, Cc = Components.classes, Cu = Components.utils;
let gChromeWin = null;
Cu.import("resource://gre/modules/AddonManager.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
function openLink(aElement) {
@ -321,7 +320,7 @@
return file;
},
_loadAddons: function(aAddons, aAddonCount, aTotalResults) {
_loadAddons: function(aAddons) {
let list = document.getElementById("newAddons");
let loading = document.getElementById("loadingAddons");
@ -376,23 +375,11 @@
_readFile(file, function(aContent) {
let json = JSON.parse(aContent);
if (!json || json.addons.length == 0) {
self._loadAddons([], 0, 0);
self._loadAddons([]);
return;
}
// Ignore addons already installed
let addonsCache = json.addons;
AddonManager.getAllAddons(function(aAddons) {
let addons = addonsCache.filter(function(addon) {
for (let i =0; i < aAddons.length; i++)
if (addon.id == aAddons[i].id)
return false;
return true;
});
self._loadAddons(addons, addons.length, json.totalResults);
});
self._loadAddons(json.addons);
});
} else {
setTimeout(function() {

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

@ -949,7 +949,6 @@ function AddonInstallListener() {
}
AddonInstallListener.prototype = {
onInstallEnded: function(aInstall, aAddon) {
let needsRestart = false;
let mode = "";
@ -961,6 +960,8 @@ AddonInstallListener.prototype = {
mode = "normal";
}
this._clearRecommendedCache();
// if we already have a mode, then we need to show a restart notification
// otherwise, we are likely a bootstrapped addon
if (needsRestart)
@ -1101,4 +1102,12 @@ AddonInstallListener.prototype = {
ExtensionsView.showAlert(strings.GetStringFromName(stringName), !aNeedsRestart);
},
_clearRecommendedCache: function xpidm_clearRecommendedCache() {
let dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
let file = dirService.get("ProfD", Ci.nsILocalFile);
file.append("recommended-addons.json");
if (file.exists())
file.remove(false);
}
};

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

@ -186,19 +186,37 @@ var RecommendedSearchResults = {
},
searchSucceeded: function(aAddons, aAddonCount, aTotalResults) {
let json = {
addons: aAddons,
addonCount: aAddonCount,
totalResults: aTotalResults
};
let self = this;
// Avoid any NSS costs. Convert https to http.
json.addons.forEach(function(aAddon){
aAddon.iconURL = aAddon.iconURL.replace(/^https/, "http");
// Filter addons already installed
AddonManager.getAllAddons(function(aAllAddons) {
let addons = aAddons.filter(function(addon) {
for (let i = 0; i < aAllAddons.length; i++)
if (addon.id == aAllAddons[i].id)
return false;
return true;
});
let json = {
addons: []
};
// Avoid any NSS costs. Convert https to http.
addons.forEach(function(aAddon){
json.addons.push({
id: aAddon.id,
name: aAddon.name,
version: aAddon.version,
description: aAddon.description,
averageRating: aAddon.averageRating,
iconURL: aAddon.iconURL.replace(/^https/, "http")
})
});
let file = self._getFile();
self._writeFile(file, JSON.stringify(json));
});
let file = this._getFile();
this._writeFile(file, JSON.stringify(json));
},
searchFailed: function searchFailed() { },