[Pkg-mozext-commits] [requestpolicy] 167/280: add `untilLevel` to startup() and shutdown()
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:30:18 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 8b15f9f93d6b43014e33bfcf8ebde899cd1bb6f4
Author: Martin Kimmerle <dev at 256k.de>
Date: Tue Jan 20 18:32:54 2015 +0100
add `untilLevel` to startup() and shutdown()
This eliminates `callShutdownFunctions()`
---
src/content/lib/environment.jsm | 74 +++++++++++++++++++++-----------
src/content/main/environment-manager.jsm | 17 +++-----
src/content/ui/frame.js | 3 +-
3 files changed, 56 insertions(+), 38 deletions(-)
diff --git a/src/content/lib/environment.jsm b/src/content/lib/environment.jsm
index 4685330..b6a28f1 100644
--- a/src/content/lib/environment.jsm
+++ b/src/content/lib/environment.jsm
@@ -30,9 +30,10 @@ let EXPORTED_SYMBOLS = ["Environment"];
let globalScope = this;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+//Cu.import("resource://gre/modules/devtools/Console.jsm");
Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
-//Cu.import("resource://gre/modules/devtools/Console.jsm");
+
ScriptLoader.defineLazyModuleGetters({
"lib/manager-for-event-listeners": ["ManagerForEventListeners"],
"main/environment-manager": ["EnvironmentManager"],
@@ -148,7 +149,15 @@ function generateLevelObjects() {
LEVELS.BACKEND,
LEVELS.ESSENTIAL
];
- function iterateLevels(aSequence, aFn) {
+
+ function lastValue(aArray) {
+ return aArray[aArray.length - 1];
+ }
+
+ Environment.lastStartupLevel = lastValue(startupSequence);
+ Environment.lastShutdownLevel = lastValue(shutdownSequence);
+
+ function iterateLevels(aSequence, aFn, aUntilLevel=lastValue(aSequence)) {
for (let i = 0, len = aSequence.length; i < len; ++i) {
// Note: It's necessary to use for(;;) instead of for(..of..)
// because the order/sequence must be exactly the same as in the
@@ -157,6 +166,11 @@ function generateLevelObjects() {
let level = aSequence[i];
aFn(level);
+
+ if (level === aUntilLevel) {
+ // Stop after aUntilLevel
+ break;
+ }
}
};
@@ -230,56 +244,66 @@ Environment.prototype.addShutdownFunction = function(aLevel, f) {
};
function processLevel(aLevelObj, fnArgsToApply) {
- aLevelObj.levelState = LEVEL_STATES.PROCESSING;
- callFunctions(aLevelObj.functions, fnArgsToApply);
- aLevelObj.levelState = LEVEL_STATES.FINISHED_PROCESSING;
+ if (aLevelObj.levelState === LEVEL_STATES.NOT_ENTERED) {
+ aLevelObj.levelState = LEVEL_STATES.PROCESSING;
+ callFunctions(aLevelObj.functions, fnArgsToApply);
+ aLevelObj.levelState = LEVEL_STATES.FINISHED_PROCESSING;
+ }
}
- // not used for now
- //Environment.prototype.callStartupFunctions = function(aLevel, fnArgsToApply) {
- // let self = this;
- // processLevel(self.startupLevels[aLevel], fnArgsToApply);
- //};
- Environment.prototype.callShutdownFunctions = function(aLevel, fnArgsToApply) {
- let self = this;
- processLevel(self.shutdownLevels[aLevel], fnArgsToApply);
- };
+ let {lastStartupLevel, lastShutdownLevel} = Environment;
-
-
-
- Environment.prototype.startup = function(fnArgsToApply) {
+ /**
+ * @param {Array} fnArgsToApply
+ * @param {integer=} untilLevel - The level after which the startup
+ * processing is stopped.
+ */
+ Environment.prototype.startup = function(fnArgsToApply,
+ untilLevel=lastStartupLevel) {
let self = this;
if (self.envState == ENV_STATES.NOT_STARTED) {
//console.log('[RPC] starting up Environment "'+self.name+'"...');
self.envState = ENV_STATES.STARTING_UP;
+ }
+ if (self.envState === ENV_STATES.STARTING_UP) {
Environment.iterateStartupLevels(function (level) {
let levelObj = self.startupLevels[level];
processLevel(levelObj, fnArgsToApply);
- });
+ }, untilLevel);
- self.envState = ENV_STATES.STARTUP_DONE;
+ if (untilLevel === lastStartupLevel) {
+ self.envState = ENV_STATES.STARTUP_DONE;
+ }
}
};
- Environment.prototype.shutdown = function(fnArgsToApply) {
+ /**
+ * @param {Array} fnArgsToApply
+ * @param {integer=} untilLevel - The level after which the shutdown
+ * processing is stopped.
+ */
+ Environment.prototype.shutdown = function(fnArgsToApply,
+ untilLevel=lastShutdownLevel) {
let self = this;
if (self.envState === ENV_STATES.STARTUP_DONE) {
//console.log('[RPC] shutting down Environment "'+self.name+'"...');
self.envState = ENV_STATES.SHUTTING_DOWN;
+ }
- EnvironmentManager.unregisterEnvironment(self);
-
+ if (self.envState === ENV_STATES.SHUTTING_DOWN) {
Environment.iterateShutdownLevels(function (level) {
let levelObj = self.shutdownLevels[level];
processLevel(levelObj, fnArgsToApply);
- });
+ }, untilLevel);
- self.envState = ENV_STATES.SHUT_DOWN;
+ if (untilLevel === lastShutdownLevel) {
+ EnvironmentManager.unregisterEnvironment(self);
+ self.envState = ENV_STATES.SHUT_DOWN;
+ }
}
};
})(Environment);
diff --git a/src/content/main/environment-manager.jsm b/src/content/main/environment-manager.jsm
index 7e4cbe6..8512bf0 100644
--- a/src/content/main/environment-manager.jsm
+++ b/src/content/main/environment-manager.jsm
@@ -53,6 +53,10 @@ let EnvironmentManager = (function(self) {
//console.debug("[RPC] creating new EnvironmentManager (" + procString + ")");
+ // this function is set by a framescript
+ self.asyncUnloadEnvMan = function() {};
+
+
self.environments = new Set();
self.registerEnvironment = function(aEnv) {
@@ -60,6 +64,7 @@ let EnvironmentManager = (function(self) {
};
self.unregisterEnvironment = function(aEnv) {
self.environments.delete(aEnv);
+ self.asyncUnloadEnvMan();
};
@@ -95,24 +100,14 @@ let EnvironmentManager = (function(self) {
Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
let {Environment} = ScriptLoader.importModule("lib/environment");
- let sequence = Environment.shutdownSequence;
- // prepare shutdown
- self.environments.forEach(function(env) {
- env.envState = Environment.SHUTTING_DOWN;
- });
// shut down
Environment.iterateShutdownLevels(function (level) {
//console.debug("[RPC] reaching level "+level+" ...");
self.environments.forEach(function(env) {
- env.callShutdownFunctions(level, fnArgsToApply);
+ env.shutdown(fnArgsToApply, level);
});
});
- // finishing tasks
- self.environments.forEach(function(env) {
- env.envState = Environment.SHUT_DOWN;
- self.unregisterEnvironment(env);
- });
// final tasks
//console.debug("[RPC] reaching level 0 ...");
diff --git a/src/content/ui/frame.js b/src/content/ui/frame.js
index 213bea6..a60c30f 100644
--- a/src/content/ui/frame.js
+++ b/src/content/ui/frame.js
@@ -163,8 +163,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Components.interfaces.nsIEventTarget.DISPATCH_NORMAL);
}
if (EnvironmentManager.isMainProcess === false) {
- FrameScriptEnv.addShutdownFunction(Environment.LEVELS.ESSENTIAL,
- unloadEnvMan);
+ Environment.asyncUnloadEnvMan = unloadEnvMan;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list