Skip to content

Commit

Permalink
Bug 1811935 - Adjust visibility of the resource types available for e…
Browse files Browse the repository at this point in the history
…ach migrator / profile pair in the new migration wizard. r=Gijs

This causes the MigrationWizardChild to request the full collection of available
migrators and user profiles, and then based on which resourceTypes those migrators
and user profiles have available, changes the visibility of the checkboxes in the
selection page of the new MigrationWizard component.

Differential Revision: https://phabricator.services.mozilla.com/D167617
  • Loading branch information
mikeconley committed Jan 25, 2023
1 parent c216ddf commit 8284312
Show file tree
Hide file tree
Showing 12 changed files with 401 additions and 48 deletions.
48 changes: 48 additions & 0 deletions browser/components/migration/ChromeProfileMigrator.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export class ChromeProfileMigrator extends MigratorBase {
return "chrome";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-chrome";
}

get _chromeUserDataPathSuffix() {
return "Chrome";
}
Expand Down Expand Up @@ -615,6 +619,10 @@ export class ChromiumProfileMigrator extends ChromeProfileMigrator {
return "chromium";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-chromium";
}

_chromeUserDataPathSuffix = "Chromium";
_keychainServiceName = "Chromium Safe Storage";
_keychainAccountName = "Chromium";
Expand All @@ -629,6 +637,10 @@ export class CanaryProfileMigrator extends ChromeProfileMigrator {
return "canary";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-canary";
}

get _chromeUserDataPathSuffix() {
return "Canary";
}
Expand All @@ -650,6 +662,10 @@ export class ChromeDevMigrator extends ChromeProfileMigrator {
return "chrome-dev";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-chrome-dev";
}

_chromeUserDataPathSuffix = "Chrome Dev";
_keychainServiceName = "Chromium Safe Storage";
_keychainAccountName = "Chromium";
Expand All @@ -663,6 +679,10 @@ export class ChromeBetaMigrator extends ChromeProfileMigrator {
return "chrome-beta";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-chrome-beta";
}

_chromeUserDataPathSuffix = "Chrome Beta";
_keychainServiceName = "Chromium Safe Storage";
_keychainAccountName = "Chromium";
Expand All @@ -676,6 +696,10 @@ export class BraveProfileMigrator extends ChromeProfileMigrator {
return "brave";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-brave";
}

_chromeUserDataPathSuffix = "Brave";
_keychainServiceName = "Brave Browser Safe Storage";
_keychainAccountName = "Brave Browser";
Expand All @@ -689,6 +713,10 @@ export class ChromiumEdgeMigrator extends ChromeProfileMigrator {
return "chromium-edge";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-chromium-edge";
}

_chromeUserDataPathSuffix = "Edge";
_keychainServiceName = "Microsoft Edge Safe Storage";
_keychainAccountName = "Microsoft Edge";
Expand All @@ -702,6 +730,10 @@ export class ChromiumEdgeBetaMigrator extends ChromeProfileMigrator {
return "chromium-edge-beta";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-chromium-edge-beta";
}

_chromeUserDataPathSuffix = "Edge Beta";
_keychainServiceName = "Microsoft Edge Safe Storage";
_keychainAccountName = "Microsoft Edge";
Expand All @@ -715,6 +747,10 @@ export class Chromium360seMigrator extends ChromeProfileMigrator {
return "chromium-360se";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-chromium-360se";
}

_chromeUserDataPathSuffix = "360 SE";
_keychainServiceName = "Microsoft Edge Safe Storage";
_keychainAccountName = "Microsoft Edge";
Expand All @@ -728,6 +764,10 @@ export class OperaProfileMigrator extends ChromeProfileMigrator {
return "opera";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-opera";
}

_chromeUserDataPathSuffix = "Opera";
_keychainServiceName = "Opera Safe Storage";
_keychainAccountName = "Opera";
Expand All @@ -745,6 +785,10 @@ export class OperaGXProfileMigrator extends ChromeProfileMigrator {
return "opera-gx";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-opera-gx";
}

_chromeUserDataPathSuffix = "Opera GX";
_keychainServiceName = "Opera Safe Storage";
_keychainAccountName = "Opera";
Expand All @@ -762,6 +806,10 @@ export class VivaldiProfileMigrator extends ChromeProfileMigrator {
return "vivaldi";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-vivaldi";
}

_chromeUserDataPathSuffix = "Vivaldi";
_keychainServiceName = "Vivaldi Safe Storage";
_keychainAccountName = "Vivaldi";
Expand Down
4 changes: 4 additions & 0 deletions browser/components/migration/EdgeProfileMigrator.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ export class EdgeProfileMigrator extends MigratorBase {
return "edge";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-edge-legacy";
}

getBookmarksMigratorForTesting(dbOverride) {
return new EdgeBookmarksMigrator(dbOverride);
}
Expand Down
4 changes: 4 additions & 0 deletions browser/components/migration/FirefoxProfileMigrator.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export class FirefoxProfileMigrator extends MigratorBase {
return "firefox";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-firefox";
}

_getAllProfiles() {
let allProfiles = new Map();
let profileService = Cc[
Expand Down
4 changes: 4 additions & 0 deletions browser/components/migration/IEProfileMigrator.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ export class IEProfileMigrator extends MigratorBase {
return "ie";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-ie";
}

getResources() {
let resources = [
MSMigrationUtils.getBookmarksMigrator(),
Expand Down
130 changes: 115 additions & 15 deletions browser/components/migration/MigrationWizardParent.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

import { MigrationUtils } from "resource:///modules/MigrationUtils.sys.mjs";
import { E10SUtils } from "resource://gre/modules/E10SUtils.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";

const lazy = {};

XPCOMUtils.defineLazyGetter(lazy, "gFluentStrings", function() {
return new Localization([
"branding/brand.ftl",
"locales-preview/migrationWizard.ftl",
]);
});

/**
* This class is responsible for communicating with MigrationUtils to do the
Expand Down Expand Up @@ -35,26 +45,116 @@ export class MigrationWizardParent extends JSWindowActorParent {
}

if (message.name == "GetAvailableMigrators") {
let availableMigrators = new Map();
let availableMigrators = [];
for (const key of MigrationUtils.availableMigratorKeys) {
try {
let migratorPromise = MigrationUtils.getMigrator(key).catch(
console.error
availableMigrators.push(this.#getMigratorAndProfiles(key));
}
// Wait for all getMigrator calls to resolve in parallel
let results = await Promise.all(availableMigrators);
// Each migrator might give us a single MigratorProfileInstance,
// or an Array of them, so we flatten them out and filter out
// any that ended up going wrong and returning null from the
// #getMigratorAndProfiles call.
return results.flat().filter(result => result);
}
return null;
}

/**
* @typedef {object} MigratorProfileInstance
* An object that describes a single user profile (or the default
* user profile) for a particular migrator.
* @property {string} key
* The unique identification key for a migrator.
* @property {string} displayName
* The display name for the migrator that will be shown to the user
* in the wizard.
* @property {string[]} resourceTypes
* An array of strings, where each string represents a resource type
* that can be imported for this migrator and profile. The strings
* should be one of the key values of
* MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.
*
* Example: ["HISTORY", "FORMDATA", "PASSWORDS", "BOOKMARKS"]
* @property {object|null} profile
* A description of the user profile that the migrator can import.
* @property {string} profile.id
* A unique ID for the user profile.
* @property {string} profile.name
* The display name for the user profile.
*/

/**
* Asynchronously fetches a migrator for a particular key, and then
* also gets any user profiles that exist on for that migrator. Resolves
* to null if something goes wrong getting information about the migrator
* or any of the user profiles.
*
* @param {string} key
* The unique identification key for a migrator.
* @returns {Promise<MigratorProfileInstance[]|null>}
*/
async #getMigratorAndProfiles(key) {
try {
let migrator = await MigrationUtils.getMigrator(key);
if (!migrator) {
return null;
}

let sourceProfiles = await migrator.getSourceProfiles();
if (Array.isArray(sourceProfiles)) {
if (!sourceProfiles.length) {
return null;
}

let result = [];
for (let profile of sourceProfiles) {
result.push(
await this.#serializeMigratorAndProfile(migrator, profile)
);
if (migratorPromise) {
availableMigrators.set(key, migratorPromise);
}
} catch (e) {
console.error(`Could not get migrator with key ${key}`);
}
return result;
}
// Wait for all getMigrator calls to resolve in parallel
await Promise.all(availableMigrators.values());
// ...and then filter out any that resolved to null.
return Array.from(availableMigrators.keys()).filter(key => {
return availableMigrators.get(key);
});
return this.#serializeMigratorAndProfile(migrator, sourceProfiles);
} catch (e) {
console.error(`Could not get migrator with key ${key}`, e);
}
return null;
}

/**
* Asynchronously fetches information about what resource types can be
* migrated for a particular migrator and user profile, and then packages
* the migrator, user profile data, and resource type data into an object
* that can be sent down to the MigrationWizardChild.
*
* @param {MigratorBase} migrator
* A migrator subclass of MigratorBase.
* @param {object|null} profileObj
* The user profile object representing the profile to get information
* about. This object is usually gotten by calling getSourceProfiles on
* the migrator.
* @returns {Promise<MigratorProfileInstance>}
*/
async #serializeMigratorAndProfile(migrator, profileObj) {
let profileMigrationData = await migrator.getMigrateData(profileObj);
let availableResourceTypes = [];

for (let resourceType in MigrationUtils.resourceTypes) {
if (profileMigrationData & MigrationUtils.resourceTypes[resourceType]) {
availableResourceTypes.push(resourceType);
}
}

return {
key: migrator.constructor.key,
displayName: await lazy.gFluentStrings.formatValues([
{
id: migrator.constructor.displayNameL10nID,
},
]),
resourceTypes: availableResourceTypes,
profile: profileObj,
};
}
}
14 changes: 12 additions & 2 deletions browser/components/migration/MigratorBase.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ export class MigratorBase {
* migrator, for example "firefox", "chrome", "opera-gx". This key is what
* is used as an identifier when calling MigrationUtils.getMigrator.
*
* @type {boolean}
* @type {string}
*/
static get key() {
throw new Error("MigratorBase must be overridden.");
throw new Error("MigratorBase.key must be overridden.");
}

/**
* This must be overridden to return a Fluent string ID mapping to the display
* name for this migrator. These strings should be defined in migrationWizard.ftl.
*
* @type {string}
*/
static get displayNameL10nID() {
throw new Error("MigratorBase.displayNameL10nID must be overridden.");
}

/**
Expand Down
4 changes: 4 additions & 0 deletions browser/components/migration/SafariProfileMigrator.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ export class SafariProfileMigrator extends MigratorBase {
return "safari";
}

static get displayNameL10nID() {
return "migration-wizard-migrator-display-name-safari";
}

getResources() {
let profileDir = FileUtils.getDir("ULibDir", ["Safari"], false);
if (!profileDir.exists()) {
Expand Down
Loading

0 comments on commit 8284312

Please sign in to comment.