Bug 833943, part 3: implement migrator changes, r=MattN, sr=gavin

--HG--
extra : rebase_source : d94c1d1c84f9b996d92317a26cbd227c0cb97a44
This commit is contained in:
Gijs Kruitbosch 2013-06-28 17:45:05 -04:00
parent cdf20dbf0e
commit c1af8dd7ed
5 changed files with 55 additions and 11 deletions

View File

@ -9,7 +9,7 @@ interface nsIArray;
interface nsIProfileStartup;
[scriptable, uuid(44993E0E-74E8-4BEC-9D66-AD8156E0A274)]
interface nsIBrowserProfileMigrator : nsISupports
interface nsIBrowserProfileMigrator : nsISupports
{
/**
* profile items to migrate. use with migrate().
@ -22,6 +22,7 @@ interface nsIBrowserProfileMigrator : nsISupports
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.

View File

@ -15,13 +15,26 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource:///modules/MigrationUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
"resource://gre/modules/PlacesBackups.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "SessionMigration",
"resource:///modules/sessionstore/SessionMigration.jsm");
function FirefoxProfileMigrator() { }
FirefoxProfileMigrator.prototype = Object.create(MigratorPrototype);
FirefoxProfileMigrator.prototype._getFileObject = function(dir, fileName) {
let file = dir.clone();
file.append(fileName);
// File resources are monolithic. We don't make partial copies since
// they are not expected to work alone. Return null to avoid trying to
// copy non-existing files.
return file.exists() ? file : null;
}
FirefoxProfileMigrator.prototype.getResources = function() {
// Only allow migrating from the default (selected) profile since this will
// be the only one returned by the toolkit profile service after bug 214675.
@ -48,14 +61,9 @@ FirefoxProfileMigrator.prototype.getResources = function() {
let getFileResource = function(aMigrationType, aFileNames) {
let files = [];
for (let fileName of aFileNames) {
let file = sourceProfileDir.clone();
file.append(fileName);
// File resources are monolithic. We don't make partial copies since
// they are not expected to work alone.
if (!file.exists())
let file = this._getFileObject(sourceProfileDir, fileName);
if (!file)
return null;
files.push(file);
}
return {
@ -67,7 +75,7 @@ FirefoxProfileMigrator.prototype.getResources = function() {
aCallback(true);
}
};
};
}.bind(this);
let types = MigrationUtils.resourceTypes;
let places = getFileResource(types.HISTORY, ["places.sqlite"]);
@ -79,8 +87,39 @@ FirefoxProfileMigrator.prototype.getResources = function() {
[PlacesBackups.profileRelativeFolderPath]);
let dictionary = getFileResource(types.OTHERDATA, ["persdict.dat"]);
let sessionFile = this._getFileObject(sourceProfileDir, "sessionstore.js");
let session;
if (sessionFile) {
session = {
type: types.SESSION,
migrate: function(aCallback) {
let newSessionFile = currentProfileDir.clone();
newSessionFile.append("sessionstore.js");
let migrationPromise = SessionMigration.migrate(sessionFile.path, newSessionFile.path);
migrationPromise.then(function() {
let buildID = Services.appinfo.platformBuildID;
let mstone = Services.appinfo.platformVersion;
// Force the browser to one-off resume the session that we give it:
Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
// Reset the homepage_override prefs so that the browser doesn't override our
// session with the "what's new" page:
Services.prefs.setCharPref("browser.startup.homepage_override.mstone", mstone);
Services.prefs.setCharPref("browser.startup.homepage_override.buildID", buildID);
// It's too early in startup for the pref service to have a profile directory,
// so we have to manually tell it where to save the prefs file.
let newPrefsFile = currentProfileDir.clone();
newPrefsFile.append("prefs.js");
Services.prefs.savePrefFile(newPrefsFile);
aCallback(true);
}, function() {
aCallback(false);
});
}
}
}
return [r for each (r in [places, cookies, passwords, formData,
dictionary, bookmarksBackups]) if (r)];
dictionary, bookmarksBackups, session]) if (r)];
}
Object.defineProperty(FirefoxProfileMigrator.prototype, "startupOnlyMigrator", {

View File

@ -332,7 +332,8 @@ this.MigrationUtils = Object.freeze({
FORMDATA: Ci.nsIBrowserProfileMigrator.FORMDATA,
PASSWORDS: Ci.nsIBrowserProfileMigrator.PASSWORDS,
BOOKMARKS: Ci.nsIBrowserProfileMigrator.BOOKMARKS,
OTHERDATA: Ci.nsIBrowserProfileMigrator.OTHERDATA
OTHERDATA: Ci.nsIBrowserProfileMigrator.OTHERDATA,
SESSION: Ci.nsIBrowserProfileMigrator.SESSION,
},
/**

View File

@ -49,3 +49,5 @@ importedSafariReadingList=Reading List (From Safari)
64_safari=Other Data
64_chrome=Other Data
64_firefox_other=Other Data
128_firefox=Windows and Tabs

View File

@ -58,6 +58,7 @@ function getMigratedData() {
// From migration.properties
const MIGRATED_TYPES = [
128,// Windows/Tabs
4, // History and Bookmarks
16, // Passwords
8, // Form History