Bug 1236588 - Remove the storage DB for HealthReport from user profiles. r=gfritzsche

This commit is contained in:
Alessio Placitelli 2016-01-12 08:50:00 +01:00
parent f03b1753ac
commit 5b7c505b88
3 changed files with 99 additions and 0 deletions

View File

@ -746,6 +746,11 @@ var Impl = {
// task to complete, but TelemetryStorage blocks on it during shutdown. // task to complete, but TelemetryStorage blocks on it during shutdown.
TelemetryStorage.runCleanPingArchiveTask(); TelemetryStorage.runCleanPingArchiveTask();
// Now that FHR/healthreporter is gone, make sure to remove FHR's DB from
// the profile directory. This is a temporary measure that we should drop
// in the future.
TelemetryStorage.removeFHRDatabase();
this._delayedInitTaskDeferred.resolve(); this._delayedInitTaskDeferred.resolve();
} catch (e) { } catch (e) {
this._delayedInitTaskDeferred.reject(e); this._delayedInitTaskDeferred.reject(e);

View File

@ -20,6 +20,7 @@ Cu.import("resource://gre/modules/osfile.jsm", this);
Cu.import("resource://gre/modules/Task.jsm", this); Cu.import("resource://gre/modules/Task.jsm", this);
Cu.import("resource://gre/modules/TelemetryUtils.jsm", this); Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
Cu.import("resource://gre/modules/Promise.jsm", this); Cu.import("resource://gre/modules/Promise.jsm", this);
Cu.import("resource://gre/modules/Preferences.jsm", this);
const LOGGER_NAME = "Toolkit.Telemetry"; const LOGGER_NAME = "Toolkit.Telemetry";
const LOGGER_PREFIX = "TelemetryStorage::"; const LOGGER_PREFIX = "TelemetryStorage::";
@ -413,6 +414,15 @@ this.TelemetryStorage = {
return TelemetryStorageImpl.loadPingFile(aFilePath); return TelemetryStorageImpl.loadPingFile(aFilePath);
}), }),
/**
* Remove FHR database files. This is temporary and will be dropped in
* the future.
* @return {Promise} Resolved when the database files are deleted.
*/
removeFHRDatabase: function() {
return TelemetryStorageImpl.removeFHRDatabase();
},
/** /**
* Only used in tests, builds an archived ping path from the ping metadata. * Only used in tests, builds an archived ping path from the ping metadata.
* @param {String} aPingId The ping id. * @param {String} aPingId The ping id.
@ -1718,6 +1728,42 @@ var TelemetryStorageImpl = {
return true; return true;
}, },
/**
* Remove FHR database files. This is temporary and will be dropped in
* the future.
* @return {Promise} Resolved when the database files are deleted.
*/
removeFHRDatabase: Task.async(function*() {
this._log.trace("removeFHRDatabase");
// Let's try to remove the FHR DB with the default filename first.
const FHR_DB_DEFAULT_FILENAME = "healthreport.sqlite";
// Even if it's uncommon, there may be 2 additional files: - a "write ahead log"
// (-wal) file and a "shared memory file" (-shm). We need to remove them as well.
let FILES_TO_REMOVE = [
OS.Path.join(OS.Constants.Path.profileDir, FHR_DB_DEFAULT_FILENAME),
OS.Path.join(OS.Constants.Path.profileDir, FHR_DB_DEFAULT_FILENAME + "-wal"),
OS.Path.join(OS.Constants.Path.profileDir, FHR_DB_DEFAULT_FILENAME + "-shm"),
];
// FHR could have used either the default DB file name or a custom one
// through this preference.
const FHR_DB_CUSTOM_FILENAME =
Preferences.get("datareporting.healthreport.dbName", undefined);
if (FHR_DB_CUSTOM_FILENAME) {
FILES_TO_REMOVE.push(
OS.Path.join(OS.Constants.Path.profileDir, FHR_DB_CUSTOM_FILENAME),
OS.Path.join(OS.Constants.Path.profileDir, FHR_DB_CUSTOM_FILENAME + "-wal"),
OS.Path.join(OS.Constants.Path.profileDir, FHR_DB_CUSTOM_FILENAME + "-shm"));
}
for (let f of FILES_TO_REMOVE) {
yield OS.File.remove(f, {ignoreAbsent: true})
.catch(e => this._log.error("removeFHRDatabase - failed to remove " + f, e));
}
}),
}; };
///// Utility functions ///// Utility functions

View File

@ -460,6 +460,54 @@ add_task(function* test_telemetryEnabledUnexpectedValue(){
"False must disable Telemetry recording."); "False must disable Telemetry recording.");
}); });
add_task(function* test_telemetryCleanFHRDatabase(){
const FHR_DBNAME_PREF = "datareporting.healthreport.dbName";
const CUSTOM_DB_NAME = "unlikely.to.be.used.sqlite";
const DEFAULT_DB_NAME = "healthreport.sqlite";
// Check that we're able to remove a FHR DB with a custom name.
const CUSTOM_DB_PATHS = [
OS.Path.join(OS.Constants.Path.profileDir, CUSTOM_DB_NAME),
OS.Path.join(OS.Constants.Path.profileDir, CUSTOM_DB_NAME + "-wal"),
OS.Path.join(OS.Constants.Path.profileDir, CUSTOM_DB_NAME + "-shm"),
];
Preferences.set(FHR_DBNAME_PREF, CUSTOM_DB_NAME);
// Write fake DB files to the profile directory.
for (let dbFilePath of CUSTOM_DB_PATHS) {
yield OS.File.writeAtomic(dbFilePath, "some data");
}
// Trigger the cleanup and check that the files were removed.
yield TelemetryStorage.removeFHRDatabase();
for (let dbFilePath of CUSTOM_DB_PATHS) {
Assert.ok(!(yield OS.File.exists(dbFilePath)), "The DB must not be on the disk anymore: " + dbFilePath);
}
// We should not break anything if there's no DB file.
yield TelemetryStorage.removeFHRDatabase();
// Check that we're able to remove a FHR DB with the default name.
Preferences.reset(FHR_DBNAME_PREF);
const DEFAULT_DB_PATHS = [
OS.Path.join(OS.Constants.Path.profileDir, DEFAULT_DB_NAME),
OS.Path.join(OS.Constants.Path.profileDir, DEFAULT_DB_NAME + "-wal"),
OS.Path.join(OS.Constants.Path.profileDir, DEFAULT_DB_NAME + "-shm"),
];
// Write fake DB files to the profile directory.
for (let dbFilePath of DEFAULT_DB_PATHS) {
yield OS.File.writeAtomic(dbFilePath, "some data");
}
// Trigger the cleanup and check that the files were removed.
yield TelemetryStorage.removeFHRDatabase();
for (let dbFilePath of DEFAULT_DB_PATHS) {
Assert.ok(!(yield OS.File.exists(dbFilePath)), "The DB must not be on the disk anymore: " + dbFilePath);
}
});
add_task(function* stopServer(){ add_task(function* stopServer(){
yield PingServer.stop(); yield PingServer.stop();
do_test_finished(); do_test_finished();