Bug 1236551 - Update the profile migrator to the Unified Telemetry changes. r=MattN
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Mon, 18 Jan 2016 16:29:44 +0100
changeset 317695 c08fefe2594fed6384557541dde10fdea36888ac
parent 317694 c2139fedfe55c5e36d173268eea3aba55467b12f
child 317696 7f066e9a778b6c0b627204d24b046ccd9ab9e613
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1236551
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1236551 - Update the profile migrator to the Unified Telemetry changes. r=MattN
browser/components/migration/FirefoxProfileMigrator.js
--- a/browser/components/migration/FirefoxProfileMigrator.js
+++ b/browser/components/migration/FirefoxProfileMigrator.js
@@ -156,96 +156,87 @@ FirefoxProfileMigrator.prototype._getRes
           aCallback(true);
         }, function() {
           aCallback(false);
         });
       }
     }
   }
 
-  // FHR related migrations.
+  // Telemetry related migrations.
   let times = {
     name: "times", // name is used only by tests.
     type: types.OTHERDATA,
     migrate: aCallback => {
       let file = this._getFileObject(sourceProfileDir, "times.json");
       if (file) {
         file.copyTo(currentProfileDir, "");
       }
       // And record the fact a migration (ie, a reset) happened.
       let timesAccessor = new ProfileAge(currentProfileDir.path);
       timesAccessor.recordProfileReset().then(
         () => aCallback(true),
         () => aCallback(false)
       );
     }
   };
-  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 'datareporting' directory exists we migrate files from it.
+      let haveStateFile = false;
+      let subdir = this._getFileObject(sourceProfileDir, "datareporting");
+      if (subdir && subdir.isDirectory()) {
+        // Copy only specific files.
+        let toCopy = ["state.json", "session-state.json"];
 
-      // If the 'healthreport' directory exists we copy everything from it.
-      let subdir = this._getFileObject(sourceProfileDir, "healthreport");
-      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);
+        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", {
   get: () => true
 });
 
 
 FirefoxProfileMigrator.prototype.classDescription = "Firefox Profile Migrator";