Bug 972076 - Make mozApps.mgmt.getAll faster r=ferjm

This commit is contained in:
Fabrice Desré 2014-07-07 11:01:30 -07:00
parent f483f4380c
commit 9feaa11f12
4 changed files with 25 additions and 40 deletions

View File

@ -335,6 +335,19 @@ this.DOMApplicationRegistry = {
}
},
getAll: function(aCallback) {
debug("getAll()\n");
if (!aCallback || typeof aCallback !== "function") {
return;
}
let res = [];
for (let id in this.webapps) {
res.push(this.webapps[id]);
}
aCallback(res);
},
/**
* nsIAppsService API
*/

View File

@ -699,9 +699,7 @@ WebappsApplication.prototype = {
* mozIDOMApplicationMgmt object
*/
function WebappsApplicationMgmt(aWindow) {
this.initDOMRequestHelper(aWindow, ["Webapps:GetAll:Return:OK",
"Webapps:GetAll:Return:KO",
"Webapps:Uninstall:Return:OK",
this.initDOMRequestHelper(aWindow, ["Webapps:Uninstall:Return:OK",
"Webapps:Uninstall:Broadcast:Return:OK",
"Webapps:Uninstall:Return:KO",
"Webapps:Install:Return:OK",
@ -758,8 +756,12 @@ WebappsApplicationMgmt.prototype = {
getAll: function() {
let request = this.createRequest();
cpmm.sendAsyncMessage("Webapps:GetAll", { oid: this._id,
requestID: this.getRequestId(request) });
let window = this._window;
DOMApplicationRegistry.getAll((aApps) => {
Services.DOMRequest.fireSuccessAsync(request,
convertAppsArray(aApps, window));
});
return request;
},
@ -797,12 +799,6 @@ WebappsApplicationMgmt.prototype = {
return;
}
switch (aMessage.name) {
case "Webapps:GetAll:Return:OK":
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
break;
case "Webapps:GetAll:Return:KO":
Services.DOMRequest.fireError(req, "DENIED");
break;
case "Webapps:GetNotInstalled:Return:OK":
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
break;

View File

@ -167,7 +167,7 @@ this.DOMApplicationRegistry = {
this.messages = ["Webapps:Install", "Webapps:Uninstall",
"Webapps:GetSelf", "Webapps:CheckInstalled",
"Webapps:GetInstalled", "Webapps:GetNotInstalled",
"Webapps:Launch", "Webapps:GetAll",
"Webapps:Launch",
"Webapps:InstallPackage",
"Webapps:GetList", "Webapps:RegisterForMessages",
"Webapps:UnregisterForMessages",
@ -1106,9 +1106,8 @@ this.DOMApplicationRegistry = {
Services.prefs.setBoolPref("dom.mozApps.used", true);
// We need to check permissions for calls coming from mozApps.mgmt.
// These are: getAll(), getNotInstalled(), applyDownload() and uninstall().
if (["Webapps:GetAll",
"Webapps:GetNotInstalled",
// These are: getNotInstalled(), applyDownload() and uninstall().
if (["Webapps:GetNotInstalled",
"Webapps:ApplyDownload",
"Webapps:Uninstall"].indexOf(aMessage.name) != -1) {
if (!aMessage.target.assertPermission("webapps-manage")) {
@ -1193,9 +1192,6 @@ this.DOMApplicationRegistry = {
case "Webapps:GetNotInstalled":
this.getNotInstalled(msg, mm);
break;
case "Webapps:GetAll":
this.doGetAll(msg, mm);
break;
case "Webapps:InstallPackage": {
#ifdef MOZ_WIDGET_ANDROID
Services.obs.notifyObservers(mm, "webapps-runtime-install-package", JSON.stringify(msg));
@ -3710,7 +3706,7 @@ this.DOMApplicationRegistry = {
this._saveApps().then(() => {
this.broadcastMessage("Webapps:Uninstall:Broadcast:Return:OK", appClone);
// Catch exception on callback call to ensure notifying observers after
this.broadcastMessage("Webapps:RemoveApp", { id: id });
try {
if (aOnSuccess) {
aOnSuccess();
@ -3719,7 +3715,6 @@ this.DOMApplicationRegistry = {
Cu.reportError("DOMApplicationRegistry: Exception on app uninstall: " +
ex + "\n" + ex.stack);
}
this.broadcastMessage("Webapps:RemoveApp", { id: id });
});
},
@ -3816,17 +3811,6 @@ this.DOMApplicationRegistry = {
});
},
doGetAll: function(aData, aMm) {
// We can't do this until the registry is ready.
debug("doGetAll");
this.registryReady.then(() => {
this.getAll(function (apps) {
aData.apps = apps;
aMm.sendAsyncMessage("Webapps:GetAll:Return:OK", aData);
});
});
},
getAll: function(aCallback) {
debug("getAll");
let apps = [];

View File

@ -140,10 +140,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=826058
request.onsuccess = continueTest;
yield undefined;
// Check the uninstalled app.
checkAppState(app, false, 3, continueTest);
yield undefined;
// Install the cached app.
setAppVersion(3, continueTest);
yield undefined;
@ -186,11 +182,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=826058
request.onerror = mozAppsError;
request.onsuccess = continueTest;
yield undefined;
ok(true, "Uninstalled app");
// Check the uninstalled app.
checkAppState(app, false, 3, continueTest);
yield undefined;
info("Uninstalled app");
}
function setAppVersion(version, cb) {