Bug 1236551 - Update the profile migrator to the Unified Telemetry changes. r=MattN

This commit is contained in:
Georg Fritzsche 2016-01-18 16:29:44 +01:00
Родитель a8ddd18486
Коммит 942276cd2a
1 изменённых файлов: 37 добавлений и 46 удалений

Просмотреть файл

@ -161,7 +161,7 @@ FirefoxProfileMigrator.prototype._getResourcesInternal = function(sourceProfileD
}
}
// FHR related migrations.
// Telemetry related migrations.
let times = {
name: "times", // name is used only by tests.
type: types.OTHERDATA,
@ -178,69 +178,60 @@ FirefoxProfileMigrator.prototype._getResourcesInternal = function(sourceProfileD
);
}
};
let healthReporter = {
name: "healthreporter", // name is used only by tests...
let telemetry = {
name: "telemetry", // name is used only by tests...
type: types.OTHERDATA,
migrate: aCallback => {
// the health-reporter can't have been initialized yet so it's safe to
// copy the SQL file.
let createSubDir = (name) => {
let dir = currentProfileDir.clone();
dir.append(name);
dir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
return dir;
};
// We only support the default database name - copied from healthreporter.jsm
const DEFAULT_DATABASE_NAME = "healthreport.sqlite";
let path = OS.Path.join(sourceProfileDir.path, DEFAULT_DATABASE_NAME);
let sqliteFile = FileUtils.File(path);
if (sqliteFile.exists()) {
sqliteFile.copyTo(currentProfileDir, "");
}
// In unusual cases there may be 2 additional files - a "write ahead log"
// (-wal) file and a "shared memory file" (-shm). The wal file contains
// data that will be replayed when the DB is next opened, while the shm
// file is ignored in that case - the replay happens using only the wal.
// So we *do* copy a wal if it exists, but not a shm.
// See https://www.sqlite.org/tempfiles.html for more.
// (Note also we attempt these copies even if we can't find the DB, and
// rely on FHR itself to do the right thing if it can)
path = OS.Path.join(sourceProfileDir.path, DEFAULT_DATABASE_NAME + "-wal");
let sqliteWal = FileUtils.File(path);
if (sqliteWal.exists()) {
sqliteWal.copyTo(currentProfileDir, "");
}
// If the 'healthreport' directory exists we copy everything from it.
let subdir = this._getFileObject(sourceProfileDir, "healthreport");
// If the 'datareporting' directory exists we migrate files from it.
let haveStateFile = false;
let subdir = this._getFileObject(sourceProfileDir, "datareporting");
if (subdir && subdir.isDirectory()) {
// Copy all regular files.
let dest = currentProfileDir.clone();
dest.append("healthreport");
dest.create(Components.interfaces.nsIFile.DIRECTORY_TYPE,
FileUtils.PERMS_DIRECTORY);
// Copy only specific files.
let toCopy = ["state.json", "session-state.json"];
let dest = createSubDir("datareporting");
let enumerator = subdir.directoryEntries;
while (enumerator.hasMoreElements()) {
let file = enumerator.getNext().QueryInterface(Components.interfaces.nsIFile);
if (file.isDirectory()) {
let file = enumerator.getNext().QueryInterface(Ci.nsIFile);
if (file.isDirectory() || toCopy.indexOf(file.leafName) == -1) {
continue;
}
if (file.leafName == "state.json") {
haveStateFile = true;
}
file.copyTo(dest, "");
}
}
// If the 'datareporting' directory exists we copy just state.json
subdir = this._getFileObject(sourceProfileDir, "datareporting");
if (subdir && subdir.isDirectory()) {
let stateFile = this._getFileObject(subdir, "state.json");
if (stateFile) {
let dest = currentProfileDir.clone();
dest.append("datareporting");
dest.create(Components.interfaces.nsIFile.DIRECTORY_TYPE,
FileUtils.PERMS_DIRECTORY);
stateFile.copyTo(dest, "");
if (!haveStateFile) {
// Fall back to migrating the state file that contains the client id from healthreport/.
// We first moved the client id management from the FHR implementation to the datareporting
// service.
// Consequently, we try to migrate an existing FHR state file here as a fallback.
let subdir = this._getFileObject(sourceProfileDir, "healthreport");
if (subdir && subdir.isDirectory()) {
let stateFile = this._getFileObject(subdir, "state.json");
if (stateFile) {
let dest = createSubDir("healthreport");
stateFile.copyTo(dest, "");
}
}
}
aCallback(true);
}
}
return [places, cookies, passwords, formData, dictionary, bookmarksBackups,
session, times, healthReporter].filter(r => r);
session, times, telemetry].filter(r => r);
};
Object.defineProperty(FirefoxProfileMigrator.prototype, "startupOnlyMigrator", {