Bug 1432212 - Lazily load log service in Marionette. r?maja_zf
We do not have to load the log service in Marionette until we
actually use it. This patch uses a lazy loader for the Log.jsm
module and a lazy getter for initialising the Marionette log repository.
This means we can get rid of MarionetteComponent#setupLogger.
The repository's log level is set at the same point in time as before.
MozReview-Commit-ID: K5PGqBB6JEO
--- a/testing/marionette/components/marionette.js
+++ b/testing/marionette/components/marionette.js
@@ -1,25 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const {interfaces: Ci, utils: Cu, classes: Cc} = Components;
-Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(
this, "env", "@mozilla.org/process/environment;1", "nsIEnvironment");
-
+XPCOMUtils.defineLazyModuleGetter(this, "Log",
+ "resource://gre/modules/Log.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");
+XPCOMUtils.defineLazyGetter(this, "log", () => {
+ let log = Log.repository.getLogger("Marionette");
+ log.addAppender(new Log.DumpAppender());
+ return log;
+});
const MARIONETTE_CONTRACT_ID = "@mozilla.org/remote/marionette;1";
const MARIONETTE_CID = Components.ID("{786a1369-dca5-4adc-8486-33d23c88010a}");
const PREF_PORT = "marionette.port";
const PREF_PORT_FALLBACK = "marionette.defaultPrefs.port";
const PREF_LOG_LEVEL = "marionette.log.level";
const PREF_LOG_LEVEL_FALLBACK = "marionette.logging";
@@ -151,21 +156,21 @@ function MarionetteComponent() {
// holds reference to ChromeWindow
// used to run GFX sanity tests on Windows
this.gfxWindow = null;
// indicates that all pending window checks have been completed
// and that we are ready to start the Marionette server
this.finalUIStartup = false;
- this.logger = this.setupLogger(prefs.logLevel);
+ log.level = prefs.logLevel;
this.enabled = env.exists(ENV_ENABLED);
if (this.enabled) {
- this.logger.info(`Enabled via ${ENV_ENABLED}`);
+ log.info(`Enabled via ${ENV_ENABLED}`);
}
}
MarionetteComponent.prototype = {
classDescription: "Marionette component",
classID: MARIONETTE_CID,
contractID: MARIONETTE_CONTRACT_ID,
QueryInterface: XPCOMUtils.generateQI([
@@ -179,22 +184,22 @@ MarionetteComponent.prototype = {
],
helpInfo: " --marionette Enable remote control server.\n",
};
// Handle -marionette flag
MarionetteComponent.prototype.handle = function(cmdLine) {
if (!this.enabled && cmdLine.handleFlag("marionette", false)) {
this.enabled = true;
- this.logger.info("Enabled via --marionette");
+ log.debug("Enabled via flag");
}
};
MarionetteComponent.prototype.observe = function(subject, topic) {
- this.logger.debug(`Received observer notification "${topic}"`);
+ log.debug(`Received observer notification ${topic}`);
switch (topic) {
case "profile-after-change":
Services.obs.addObserver(this, "command-line-startup");
Services.obs.addObserver(this, "sessionstore-windows-restored");
prefs.readFromEnvironment(ENV_PRESERVE_PREFS);
break;
@@ -257,28 +262,21 @@ MarionetteComponent.prototype.observe =
case "xpcom-shutdown":
Services.obs.removeObserver(this, "xpcom-shutdown");
this.uninit();
break;
}
};
-MarionetteComponent.prototype.setupLogger = function(level) {
- let logger = Log.repository.getLogger("Marionette");
- logger.level = level;
- logger.addAppender(new Log.DumpAppender());
- return logger;
-};
-
MarionetteComponent.prototype.suppressSafeModeDialog = function(win) {
win.addEventListener("load", () => {
if (win.document.getElementById("safeModeDialog")) {
// accept the dialog to start in safe-mode
- this.logger.debug("Safe Mode detected. Going to suspress the dialog now.");
+ log.debug("Safe mode detected, supressing dialog");
win.setTimeout(() => {
win.document.documentElement.getButton("accept").click();
});
}
}, {once: true});
};
MarionetteComponent.prototype.init = function() {
@@ -293,17 +291,17 @@ MarionetteComponent.prototype.init = fun
if ("@mozilla.org/test/startuprecorder;1" in Cc)
promise = Cc["@mozilla.org/test/startuprecorder;1"].getService().wrappedJSObject.done;
promise.then(() => {
let s;
try {
Cu.import("chrome://marionette/content/server.js");
s = new server.TCPListener(prefs.port);
s.start();
- this.logger.info(`Listening on port ${s.port}`);
+ log.info(`Listening on port ${s.port}`);
} finally {
if (s) {
this.server = s;
this.running = true;
}
}
});
});