Bug 970208 - Only print debug messages when in debug mode; r=wesj

This commit is contained in:
Martyn Haigh 2014-03-05 08:13:22 -08:00
parent 1890a5332f
commit e9180388f8
2 changed files with 24 additions and 20 deletions

View File

@ -28,13 +28,15 @@ XPCOMUtils.defineLazyGetter(this, "Strings", function() {
return Services.strings.createBundle("chrome://browser/locale/webapp.properties");
});
function log(message) {
function debug(aMessage) {
// We use *dump* instead of Services.console.logStringMessage so the messages
// have the INFO level of severity instead of the ERROR level. And we don't
// append a newline character to the end of the message because *dump* spills
// into the Android native logging system, which strips newlines from messages
// and breaks messages into lines automatically at display time (i.e. logcat).
dump(message);
#ifdef MOZ_DEBUG
dump(aMessage);
#endif
}
function sendMessageToJava(aMessage) {
@ -80,7 +82,7 @@ this.WebappManager = {
} catch(ex) {
aMessage.error = ex;
aMessageManager.sendAsyncMessage("Webapps:Install:Return:KO", aMessage);
log("error downloading APK: " + ex);
debug("error downloading APK: " + ex);
return;
}
@ -92,7 +94,7 @@ this.WebappManager = {
}).bind(this)); },
_downloadApk: function(aManifestUrl) {
log("_downloadApk for " + aManifestUrl);
debug("_downloadApk for " + aManifestUrl);
let deferred = Promise.defer();
// Get the endpoint URL and convert it to an nsIURI/nsIURL object.
@ -106,7 +108,7 @@ this.WebappManager = {
};
generatorUrl.query =
[p + "=" + encodeURIComponent(params[p]) for (p in params)].join("&");
log("downloading APK from " + generatorUrl.spec);
debug("downloading APK from " + generatorUrl.spec);
let file = Cc["@mozilla.org/download-manager;1"].
getService(Ci.nsIDownloadManager).
@ -114,7 +116,7 @@ this.WebappManager = {
clone();
file.append(aManifestUrl.replace(/[^a-zA-Z0-9]/gi, "") + ".apk");
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
log("downloading APK to " + file.path);
debug("downloading APK to " + file.path);
let worker = new ChromeWorker("resource://gre/modules/WebappManagerWorker.js");
worker.onmessage = function(event) {
@ -125,7 +127,7 @@ this.WebappManager = {
if (type == "success") {
deferred.resolve(file.path);
} else { // type == "failure"
log("error downloading APK: " + message);
debug("error downloading APK: " + message);
deferred.reject(message);
}
}
@ -147,7 +149,7 @@ this.WebappManager = {
// when we trigger the native install dialog and doesn't re-init itself
// afterward (TODO: file bug about this behavior).
if ("appcache_path" in aData.app.manifest) {
log("deleting appcache_path from manifest: " + aData.app.manifest.appcache_path);
debug("deleting appcache_path from manifest: " + aData.app.manifest.appcache_path);
delete aData.app.manifest.appcache_path;
}
@ -168,7 +170,7 @@ this.WebappManager = {
},
launch: function({ manifestURL, origin }) {
log("launchWebapp: " + manifestURL);
debug("launchWebapp: " + manifestURL);
sendMessageToJava({
type: "Webapps:Open",
@ -178,7 +180,7 @@ this.WebappManager = {
},
uninstall: function(aData) {
log("uninstall: " + aData.manifestURL);
debug("uninstall: " + aData.manifestURL);
if (this._testing) {
// We don't have to do anything, as the registry does all the work.
@ -199,7 +201,7 @@ this.WebappManager = {
let mm = {
sendAsyncMessage: function (aMessageName, aData) {
// TODO hook this back to Java to report errors.
log("sendAsyncMessage " + aMessageName + ": " + JSON.stringify(aData));
debug("sendAsyncMessage " + aMessageName + ": " + JSON.stringify(aData));
}
};
@ -244,7 +246,7 @@ this.WebappManager = {
},
_autoUpdate: function(aData, aOldApp) { return Task.spawn((function*() {
log("_autoUpdate app of type " + aData.type);
debug("_autoUpdate app of type " + aData.type);
if (aData.type == "hosted") {
let oldManifest = yield DOMApplicationRegistry.getManifestFor(aData.manifestURL);
@ -257,13 +259,13 @@ this.WebappManager = {
_checkingForUpdates: false,
checkForUpdates: function(userInitiated) { return Task.spawn((function*() {
log("checkForUpdates");
debug("checkForUpdates");
// Don't start checking for updates if we're already doing so.
// TODO: Consider cancelling the old one and starting a new one anyway
// if the user requested this one.
if (this._checkingForUpdates) {
log("already checking for updates");
debug("already checking for updates");
return;
}
this._checkingForUpdates = true;
@ -466,7 +468,7 @@ this.WebappManager = {
try {
yield OS.file.remove(apk.filePath);
} catch(ex) {
log("error removing " + apk.filePath + " for cancelled update: " + ex);
debug("error removing " + apk.filePath + " for cancelled update: " + ex);
}
}
}
@ -512,14 +514,14 @@ this.WebappManager = {
for (let id in DOMApplicationRegistry.webapps) {
let app = DOMApplicationRegistry.webapps[id];
if (aData.apkPackageNames.indexOf(app.apkPackageName) > -1) {
log("attempting to uninstall " + app.name);
debug("attempting to uninstall " + app.name);
DOMApplicationRegistry.uninstall(
app.manifestURL,
function() {
log("success uninstalling " + app.name);
debug("success uninstalling " + app.name);
},
function(error) {
log("error uninstalling " + app.name + ": " + error);
debug("error uninstalling " + app.name + ": " + error);
}
);
}
@ -548,7 +550,7 @@ this.WebappManager = {
if (aPrefs.length > 0) {
let array = new TextEncoder().encode(JSON.stringify(aPrefs));
OS.File.writeAtomic(aFile.path, array, { tmpPath: aFile.path + ".tmp" }).then(null, function onError(reason) {
log("Error writing default prefs: " + reason);
debug("Error writing default prefs: " + reason);
});
}
},

View File

@ -23,7 +23,9 @@ EXTRA_JS_MODULES += [
]
if CONFIG['MOZ_ANDROID_SYNTHAPKS']:
EXTRA_JS_MODULES += [
EXTRA_PP_JS_MODULES += [
'WebappManager.jsm',
]
EXTRA_JS_MODULES += [
'WebappManagerWorker.js',
]