Bug 1821187 - Add infrastructure for file migrators in the new Migration Wizard. r=fluent-reviewers,kpatenio,flod

This also includes our first file migrator, which imports passwords from CSV/TSV files.

Differential Revision: https://phabricator.services.mozilla.com/D173033
This commit is contained in:
Mike Conley
2023-04-13 01:28:38 +00:00
parent c6ccd89613
commit cd18f710fc
20 changed files with 1167 additions and 37 deletions

View File

@@ -17,6 +17,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
});
var gMigrators = null;
var gFileMigrators = null;
var gProfileStartup = null;
var gL10n = null;
var gPreviousDefaultBrowserKey = "";
@@ -107,6 +108,12 @@ const MIGRATOR_MODULES = Object.freeze({
},
});
const FILE_MIGRATOR_MODULES = Object.freeze({
PasswordFileMigrator: {
moduleURI: "resource:///modules/FileMigrators.sys.mjs",
},
});
/**
* The singleton MigrationUtils service. This service is the primary mechanism
* by which migrations from other browsers to this browser occur. The singleton
@@ -301,6 +308,26 @@ class MigrationUtils {
return gMigrators;
}
get #fileMigrators() {
if (!gFileMigrators) {
gFileMigrators = new Map();
for (let [symbol, { moduleURI }] of Object.entries(
FILE_MIGRATOR_MODULES
)) {
let { [symbol]: migratorClass } = ChromeUtils.importESModule(moduleURI);
if (gFileMigrators.has(migratorClass.key)) {
console.error(
"A pre-existing file migrator exists with key " +
`${migratorClass.key}. Not registering.`
);
continue;
}
gFileMigrators.set(migratorClass.key, new migratorClass());
}
}
return gFileMigrators;
}
forceExitSpinResolve() {
gForceExitSpinResolve = true;
}
@@ -367,6 +394,15 @@ class MigrationUtils {
}
}
getFileMigrator(aKey) {
let migrator = this.#fileMigrators.get(aKey);
if (!migrator) {
console.error(`Could not find a file migrator class for key ${aKey}`);
return null;
}
return migrator;
}
/**
* Returns true if a migrator is registered with key aKey. No check is made
* to determine if a profile exists that the migrator can migrate from.
@@ -958,6 +994,10 @@ class MigrationUtils {
return [...this.#migrators.keys()];
}
get availableFileMigrators() {
return [...this.#fileMigrators.values()];
}
/**
* Enum for the entrypoint that is being used to start migration.
* Callers can use the MIGRATION_ENTRYPOINTS getter to use these.