Bug 718280 - Part 1: Move resource type constants into MigrationUtils. r=NeilDeakin

Differential Revision: https://phabricator.services.mozilla.com/D164138
This commit is contained in:
Mike Conley
2022-12-13 17:01:24 +00:00
parent 8ef9b0adeb
commit 8a65c0aa96
6 changed files with 34 additions and 43 deletions

View File

@@ -42,13 +42,15 @@ function getL10n() {
*/ */
class MigrationUtils { class MigrationUtils {
resourceTypes = Object.freeze({ resourceTypes = Object.freeze({
COOKIES: Ci.nsIBrowserProfileMigrator.COOKIES, ALL: 0x0000,
HISTORY: Ci.nsIBrowserProfileMigrator.HISTORY, /* 0x01 used to be used for settings, but was removed. */
FORMDATA: Ci.nsIBrowserProfileMigrator.FORMDATA, COOKIES: 0x0002,
PASSWORDS: Ci.nsIBrowserProfileMigrator.PASSWORDS, HISTORY: 0x0004,
BOOKMARKS: Ci.nsIBrowserProfileMigrator.BOOKMARKS, FORMDATA: 0x0008,
OTHERDATA: Ci.nsIBrowserProfileMigrator.OTHERDATA, PASSWORDS: 0x0010,
SESSION: Ci.nsIBrowserProfileMigrator.SESSION, BOOKMARKS: 0x0020,
OTHERDATA: 0x0040,
SESSION: 0x0080,
}); });
/** /**

View File

@@ -23,7 +23,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
* A resource returned by a subclass of MigratorBase that can migrate * A resource returned by a subclass of MigratorBase that can migrate
* data to this browser. * data to this browser.
* @property {number} type * @property {number} type
* A bitfield with bits from nsIBrowserProfileMigrator flipped to indicate * A bitfield with bits from MigrationUtils.resourceTypes flipped to indicate
* what this resource represents. A resource can represent one or more types * what this resource represents. A resource can represent one or more types
* of data, for example HISTORY and FORMDATA. * of data, for example HISTORY and FORMDATA.
* @property {Function} migrate * @property {Function} migrate
@@ -76,8 +76,8 @@ export class MigratorBase {
* profiles. * profiles.
* *
* Each migration resource should provide: * Each migration resource should provide:
* - a |type| getter, returning any of the migration types (see * - a |type| getter, returning any of the migration resource types (see
* nsIBrowserProfileMigrator). * MigrationUtils.resourceTypes).
* *
* - a |migrate| method, taking a single argument, aCallback(bool success), * - a |migrate| method, taking a single argument, aCallback(bool success),
* for migrating the data for this resource. It may do its job * for migrating the data for this resource. It may do its job
@@ -88,7 +88,7 @@ export class MigratorBase {
* Note: In the case of a simple asynchronous implementation, you may find * Note: In the case of a simple asynchronous implementation, you may find
* MigrationUtils.wrapMigrateFunction handy for handling aCallback easily. * MigrationUtils.wrapMigrateFunction handy for handling aCallback easily.
* *
* For each migration type listed in nsIBrowserProfileMigrator, multiple * For each migration type listed in MigrationUtils.resourceTypes, multiple
* migration resources may be provided. This practice is useful when the * migration resources may be provided. This practice is useful when the
* data for a certain migration type is independently stored in few * data for a certain migration type is independently stored in few
* locations. For example, the mac version of Safari stores its "reading list" * locations. For example, the mac version of Safari stores its "reading list"
@@ -198,8 +198,10 @@ export class MigratorBase {
* *
* See nsIBrowserProfileMigrator. * See nsIBrowserProfileMigrator.
* *
* @see MigrationUtils
*
* @param {number} aItems * @param {number} aItems
* A bitfield with bits from nsIBrowserProfileMigrator flipped to indicate * A bitfield with bits from MigrationUtils.resourceTypes flipped to indicate
* what types of resources should be migrated. * what types of resources should be migrated.
* @param {boolean} aStartup * @param {boolean} aStartup
* True if this migration is occurring during startup. * True if this migration is occurring during startup.
@@ -212,7 +214,7 @@ export class MigratorBase {
throw new Error("migrate called for a non-existent source"); throw new Error("migrate called for a non-existent source");
} }
if (aItems != Ci.nsIBrowserProfileMigrator.ALL) { if (aItems != lazy.MigrationUtils.resourceTypes.ALL) {
resources = resources.filter(r => aItems & r.type); resources = resources.filter(r => aItems & r.type);
} }

View File

@@ -34,7 +34,7 @@ const kDataToStringMap = new Map([
var MigrationWizard = { var MigrationWizard = {
/* exported MigrationWizard */ /* exported MigrationWizard */
_source: "", // Source Profile Migrator ContractID suffix _source: "", // Source Profile Migrator ContractID suffix
_itemsFlags: kIMig.ALL, // Selected Import Data Sources (16-bit bitfield) _itemsFlags: MigrationUtils.resourceTypes.ALL, // Selected Import Data Sources (16-bit bitfield)
_selectedProfile: null, // Selected Profile name to import from _selectedProfile: null, // Selected Profile name to import from
_wiz: null, _wiz: null,
_migrator: null, _migrator: null,
@@ -265,7 +265,7 @@ var MigrationWizard = {
// Create the migrator for the selected source. // Create the migrator for the selected source.
this._migrator = this.spinResolve(MigrationUtils.getMigrator(newSource)); this._migrator = this.spinResolve(MigrationUtils.getMigrator(newSource));
this._itemsFlags = kIMig.ALL; this._itemsFlags = MigrationUtils.resourceTypes.ALL;
this._selectedProfile = null; this._selectedProfile = null;
} }
this._source = newSource; this._source = newSource;
@@ -355,7 +355,7 @@ var MigrationWizard = {
); );
for (let itemType of kDataToStringMap.keys()) { for (let itemType of kDataToStringMap.keys()) {
let itemValue = Ci.nsIBrowserProfileMigrator[itemType.toUpperCase()]; let itemValue = MigrationUtils.resourceTypes[itemType.toUpperCase()];
if (items & itemValue) { if (items & itemValue) {
let checkbox = document.createXULElement("checkbox"); let checkbox = document.createXULElement("checkbox");
checkbox.id = itemValue; checkbox.id = itemValue;
@@ -422,8 +422,8 @@ var MigrationWizard = {
if ( if (
this._source == "safari" && this._source == "safari" &&
AppConstants.isPlatformAndVersionAtLeast("macosx", "18") && AppConstants.isPlatformAndVersionAtLeast("macosx", "18") &&
(this._itemsFlags & Ci.nsIBrowserProfileMigrator.BOOKMARKS || (this._itemsFlags & MigrationUtils.resourceTypes.BOOKMARKS ||
this._itemsFlags == Ci.nsIBrowserProfileMigrator.ALL) this._itemsFlags == MigrationUtils.resourceTypes.ALL)
) { ) {
let migrator = this._migrator.wrappedJSObject; let migrator = this._migrator.wrappedJSObject;
let havePermissions = this.spinResolve(migrator.hasPermissions()); let havePermissions = this.spinResolve(migrator.hasPermissions());
@@ -505,7 +505,7 @@ var MigrationWizard = {
} }
for (let itemType of kDataToStringMap.keys()) { for (let itemType of kDataToStringMap.keys()) {
let itemValue = Ci.nsIBrowserProfileMigrator[itemType.toUpperCase()]; let itemValue = MigrationUtils.resourceTypes[itemType.toUpperCase()];
if (this._itemsFlags & itemValue) { if (this._itemsFlags & itemValue) {
var label = document.createXULElement("label"); var label = document.createXULElement("label");
label.id = itemValue + "_migrated"; label.id = itemValue + "_migrated";
@@ -567,22 +567,22 @@ var MigrationWizard = {
let type = "undefined"; let type = "undefined";
let numericType = parseInt(aData); let numericType = parseInt(aData);
switch (numericType) { switch (numericType) {
case Ci.nsIBrowserProfileMigrator.COOKIES: case MigrationUtils.resourceTypes.COOKIES:
type = "cookies"; type = "cookies";
break; break;
case Ci.nsIBrowserProfileMigrator.HISTORY: case MigrationUtils.resourceTypes.HISTORY:
type = "history"; type = "history";
break; break;
case Ci.nsIBrowserProfileMigrator.FORMDATA: case MigrationUtils.resourceTypes.FORMDATA:
type = "form data"; type = "form data";
break; break;
case Ci.nsIBrowserProfileMigrator.PASSWORDS: case MigrationUtils.resourceTypes.PASSWORDS:
type = "passwords"; type = "passwords";
break; break;
case Ci.nsIBrowserProfileMigrator.BOOKMARKS: case MigrationUtils.resourceTypes.BOOKMARKS:
type = "bookmarks"; type = "bookmarks";
break; break;
case Ci.nsIBrowserProfileMigrator.OTHERDATA: case MigrationUtils.resourceTypes.OTHERDATA:
type = "misc. data"; type = "misc. data";
break; break;
} }

View File

@@ -11,19 +11,6 @@ interface nsIProfileStartup;
[scriptable, uuid(22b56ffc-3149-43c5-b5a9-b3a6b678de93)] [scriptable, uuid(22b56ffc-3149-43c5-b5a9-b3a6b678de93)]
interface nsIBrowserProfileMigrator : nsISupports interface nsIBrowserProfileMigrator : nsISupports
{ {
/**
* profile items to migrate. use with migrate().
*/
const unsigned short ALL = 0x0000;
/* 0x01 used to be used for settings, but was removed. */
const unsigned short COOKIES = 0x0002;
const unsigned short HISTORY = 0x0004;
const unsigned short FORMDATA = 0x0008;
const unsigned short PASSWORDS = 0x0010;
const unsigned short BOOKMARKS = 0x0020;
const unsigned short OTHERDATA = 0x0040;
const unsigned short SESSION = 0x0080;
/** /**
* Copy user profile information to the current active profile. * Copy user profile information to the current active profile.
* @param aItems list of data items to migrate. see above for values. * @param aItems list of data items to migrate. see above for values.

View File

@@ -1870,7 +1870,7 @@ export var PlacesUIUtils = {
// Otherwise, wait for a successful migration: // Otherwise, wait for a successful migration:
let obs = (subject, topic, data) => { let obs = (subject, topic, data) => {
if ( if (
data == Ci.nsIBrowserProfileMigrator.BOOKMARKS && data == lazy.MigrationUtils.resourceTypes.BOOKMARKS &&
lazy.MigrationUtils.getImportedCount("bookmarks") > 0 lazy.MigrationUtils.getImportedCount("bookmarks") > 0
) { ) {
lazy.CustomizableUI.removeWidgetFromArea("import-button"); lazy.CustomizableUI.removeWidgetFromArea("import-button");

View File

@@ -80,7 +80,7 @@ add_task(async function test_bookmark_import_button_removal() {
Services.obs.notifyObservers( Services.obs.notifyObservers(
null, null,
"Migration:ItemAfterMigrate", "Migration:ItemAfterMigrate",
Ci.nsIBrowserProfileMigrator.BOOKMARKS MigrationUtils.resourceTypes.BOOKMARKS
); );
is( is(
@@ -95,7 +95,7 @@ add_task(async function test_bookmark_import_button_removal() {
Services.obs.notifyObservers( Services.obs.notifyObservers(
null, null,
"Migration:ItemAfterMigrate", "Migration:ItemAfterMigrate",
Ci.nsIBrowserProfileMigrator.BOOKMARKS MigrationUtils.resourceTypes.BOOKMARKS
); );
is(Services.prefs.prefHasUserValue(kPref), false, "Pref should be removed."); is(Services.prefs.prefHasUserValue(kPref), false, "Pref should be removed.");
@@ -159,7 +159,7 @@ add_task(async function test_bookmark_import_button_errors() {
Services.obs.notifyObservers( Services.obs.notifyObservers(
null, null,
"Migration:ItemError", "Migration:ItemError",
Ci.nsIBrowserProfileMigrator.BOOKMARKS MigrationUtils.resourceTypes.BOOKMARKS
); );
is( is(
@@ -174,7 +174,7 @@ add_task(async function test_bookmark_import_button_errors() {
Services.obs.notifyObservers( Services.obs.notifyObservers(
null, null,
"Migration:ItemError", "Migration:ItemError",
Ci.nsIBrowserProfileMigrator.BOOKMARKS MigrationUtils.resourceTypes.BOOKMARKS
); );
is(Services.prefs.prefHasUserValue(kPref), false, "Pref should be removed."); is(Services.prefs.prefHasUserValue(kPref), false, "Pref should be removed.");