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 9ce5a37174
commit 12eace4762
3 changed files with 22 additions and 25 deletions

View File

@ -334,6 +334,18 @@ this.DOMApplicationRegistry = {
}
},
getAll: function(aCallback) {
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",
@ -759,8 +757,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;
},
@ -798,12 +800,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

@ -162,7 +162,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",
@ -1073,9 +1073,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")) {
@ -1120,9 +1119,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));
@ -3717,13 +3713,6 @@ this.DOMApplicationRegistry = {
});
},
doGetAll: function(aData, aMm) {
this.getAll(function (apps) {
aData.apps = apps;
aMm.sendAsyncMessage("Webapps:GetAll:Return:OK", aData);
});
},
getAll: function(aCallback) {
debug("getAll");
let apps = [];