  // a pre-existing times.json with data from a different profile, because
    // then the client ID wouldn't match the times.json data anymore.
    //
    // The rule that we're following for backups and recoveries is that the
    // recovered profile always inherits the client ID (and therefore the
    // times.json) from the profile that _initiated recovery_.
    //
    // This means we want to copy the times.json file from the profile that's
    // currently in use to the destProfilePath.
    await BackupResource.copyFiles(PathUtils.profileDir, destProfilePath, [
      "times.json",
    ]);

    // We also want to write the recoveredFromBackup timestamp now.
    let profileAge = await lazy.ProfileAge(destProfilePath);
    await profileAge.recordRecoveredFromBackup();

    // The activity-stream-snippets data will need to be written during the
    // postRecovery phase, so we'll stash the path to the JSON file in the
    // post recovery entry.
    let snippetsBackupFile = PathUtils.join(
      recoveryPath,
      "activity-stream-snippets.json"
    );
    return { snippetsBackupFile };
  }

  async postRecovery(postRecoveryEntry) {
    let { snippetsBackupFile } = postRecoveryEntry;

    // If for some reason, the activity-stream-snippets data file has been
    // removed already, there's nothing to do.
    if (!IOUtils.exists(snippetsBackupFile)) {
      return;
    }

    let snippetsData = await IOUtils.readJSON(snippetsBackupFile);
    let storage = new lazy.ASRouterStorage({
      storeNames: [SNIPPETS_TABLE_NAME],
    });
    let snippetsTable = await storage.getDbTable(SNIPPETS_TABLE_NAME);
    for (let key in snippetsData) {
      let value = snippetsData[key];
      await snippetsTable.set(key, value);
    }
  }

  async measure(profilePath = PathUtils.profileDir) {
    let fullSize = 0;

    for (let filePath of FILES_FOR_BACKUP) {
      let resourcePath = PathUtils.join(profilePath, filePath);
      let resourceSize = await BackupResource.getFileSize(resourcePath);
      if (Number.isInteger(resourceSize)) {
        fullSize += resourceSize;
      }
    }

    let chromeIndexedDBDirPath = PathUtils.join(
      profilePath,
      "storage",
      "permanent",
      "chrome"
    );
    let chromeIndexedDBDirSize = await BackupResource.getDirectorySize(
      chromeIndexedDBDirPath
    );
    if (Number.isInteger(chromeIndexedDBDirSize)) {
      fullSize += chromeIndexedDBDirSize;
    }

    Glean.browserBackup.miscDataSize.set(fullSize);
  }
}
PK