diff --git a/README.md b/README.md
index 7655521..14fca65 100644
--- a/README.md
+++ b/README.md
@@ -16,15 +16,6 @@ prototype for collecting these errors to aid in Firefox development.
## Preferences
- -
-
- extensions.shield-study-js-errors@shield.mozilla.org.logLevel
-
-
- -
- Log level for extension logging. Defaults to Warnings and above. Set to 0
- for verbose logging.
-
-
extensions.shield-study-js-errors@shield.mozilla.org.testing
@@ -40,6 +31,24 @@ prototype for collecting these errors to aid in Firefox development.
Interval (in milliseconds) at which to submit collected error hashes to
telemetry.
+ -
+
+ extensions.shield-study-js-errors@shield.mozilla.org.expirationDate
+
+
+ -
+ Date.parse-compatible string specifying the datetime that the experiment
+ should expire and automatically uninstall itself. Defaults to January 1st,
+ 2018.
+
+ -
+
+ extensions.shield-study-js-errors@shield.mozilla.org.expirationIntervalMs
+
+
+ -
+ Interval (in milliseconds) at which to check whether the study has expired or not. Defaults to once per day.
+
## Development
diff --git a/extension/bootstrap.js b/extension/bootstrap.js
index 6649106..900f47f 100644
--- a/extension/bootstrap.js
+++ b/extension/bootstrap.js
@@ -3,25 +3,60 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const {utils: Cu} = Components;
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Timer.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
XPCOMUtils.defineLazyModuleGetter(
this, "ErrorLogging", "resource://shield-study-js-errors/ErrorLogging.jsm");
XPCOMUtils.defineLazyModuleGetter(
this, "ErrorReporting", "resource://shield-study-js-errors/ErrorReporting.jsm");
+let expirationInterval = null;
+
+/**
+ * Uninstall the add-on if it is past the built-in expiration date.
+ */
+async function checkExpiration() {
+ const expirationDate = new Date(
+ Services.prefs.getCharPref(
+ "extensions.shield-study-js-errors@shield.mozilla.org.expirationDate",
+ "2018-01-01T00:00:00.000Z",
+ ),
+ );
+ if (new Date() > expirationDate) {
+ const addon = await AddonManager.getAddonByID("shield-study-js-errors@shield.mozilla.org");
+ if (addon) {
+ addon.uninstall();
+ }
+ }
+}
+
this.install = function() {};
this.startup = function() {
ErrorReporting.startup();
ErrorLogging.startup();
ErrorLogging.addListener(ErrorReporting.reportError.bind(ErrorReporting));
+
+ // Check expiration on startup, and again once per-day if necessary.
+ const expirationDelay = Services.prefs.getIntPref(
+ "extensions.shield-study-js-errors@shield.mozilla.org.expirationIntervalMs",
+ 1000 * 60 * 60 * 24, // 1 day
+ );
+ expirationInterval = setInterval(checkExpiration, expirationDelay);
+ checkExpiration();
};
this.shutdown = function() {
ErrorLogging.shutdown();
ErrorReporting.shutdown();
+ if (expirationInterval) {
+ clearInterval(expirationInterval);
+ }
+
Cu.unload("resource://shield-study-js-errors/ErrorLogging.jsm");
Cu.unload("resource://shield-study-js-errors/ErrorReporting.jsm");
};