--- a/toolkit/components/telemetry/TelemetryStorage.jsm
+++ b/toolkit/components/telemetry/TelemetryStorage.jsm
@@ -414,19 +414,23 @@ this.TelemetryStorage = {
},
/**
* Loads a ping file.
* @param {String} aFilePath The path of the ping file.
* @return {Promise<Object>} A promise resolved with the ping content or rejected if the
* ping contains invalid data.
*/
- loadPingFile: Task.async(function* (aFilePath) {
+ // loadPingFile: Task.async(function* (aFilePath) {
+ // return TelemetryStorageImpl.loadPingFile(aFilePath);
+ // }),
+
+ loadPingFile: async function(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() {
return TelemetryStorageImpl.removeFHRDatabase();
@@ -600,93 +604,93 @@ var TelemetryStorageImpl = {
return this._logger;
},
/**
* Shutdown & block on any outstanding async activity in this module.
*
* @return {Promise} Promise that is resolved when shutdown is complete.
*/
- shutdown: Task.async(function*() {
+ shutdown: async function() {
this._shutdown = true;
// If the following tasks are still running, block on them. They will bail out as soon
// as possible.
- yield this._abortedSessionSerializer.flushTasks().catch(ex => {
+ await this._abortedSessionSerializer.flushTasks().catch(ex => {
this._log.error("shutdown - failed to flush aborted-session writes", ex);
});
- yield this._deletionPingSerializer.flushTasks().catch(ex => {
+ await this._deletionPingSerializer.flushTasks().catch(ex => {
this._log.error("shutdown - failed to flush deletion ping writes", ex);
});
if (this._cleanArchiveTask) {
- yield this._cleanArchiveTask.catch(ex => {
+ await this._cleanArchiveTask.catch(ex => {
this._log.error("shutdown - the archive cleaning task failed", ex);
});
}
if (this._enforcePendingPingsQuotaTask) {
- yield this._enforcePendingPingsQuotaTask.catch(ex => {
+ await this._enforcePendingPingsQuotaTask.catch(ex => {
this._log.error("shutdown - the pending pings quota task failed", ex);
});
}
if (this._removePendingPingsTask) {
- yield this._removePendingPingsTask.catch(ex => {
+ await this._removePendingPingsTask.catch(ex => {
this._log.error("shutdown - the pending pings removal task failed", ex);
});
}
// Wait on pending pings still being saved. While OS.File should have shutdown
// blockers in place, we a) have seen weird errors being reported that might
// indicate a bad shutdown path and b) might have completion handlers hanging
// off the save operations that don't expect to be late in shutdown.
- yield this.promisePendingPingSaves();
- }),
+ await this.promisePendingPingSaves();
+ },
/**
* Save an archived ping to disk.
*
* @param {object} ping The ping data to archive.
* @return {promise} Promise that is resolved when the ping is successfully archived.
*/
saveArchivedPing(ping) {
let promise = this._saveArchivedPingTask(ping);
this._activelyArchiving.add(promise);
promise.then((r) => { this._activelyArchiving.delete(promise); },
(e) => { this._activelyArchiving.delete(promise); });
return promise;
},
- _saveArchivedPingTask: Task.async(function*(ping) {
+ _saveArchivedPingTask: async function(ping) {
const creationDate = new Date(ping.creationDate);
if (this._archivedPings.has(ping.id)) {
const data = this._archivedPings.get(ping.id);
if (data.timestampCreated > creationDate.getTime()) {
this._log.error("saveArchivedPing - trying to overwrite newer ping with the same id");
return Promise.reject(new Error("trying to overwrite newer ping with the same id"));
}
this._log.warn("saveArchivedPing - overwriting older ping with the same id");
}
// Get the archived ping path and append the lz4 suffix to it (so we have 'jsonlz4').
const filePath = getArchivedPingPath(ping.id, creationDate, ping.type) + "lz4";
- yield OS.File.makeDir(OS.Path.dirname(filePath), { ignoreExisting: true,
+ await OS.File.makeDir(OS.Path.dirname(filePath), { ignoreExisting: true,
from: OS.Constants.Path.profileDir });
- yield this.savePingToFile(ping, filePath, /* overwrite*/ true, /* compressed*/ true);
+ await this.savePingToFile(ping, filePath, /* overwrite*/ true, /* compressed*/ true);
this._archivedPings.set(ping.id, {
timestampCreated: creationDate.getTime(),
type: internString(ping.type),
});
Telemetry.getHistogramById("TELEMETRY_ARCHIVE_SESSION_PING_COUNT").add();
return undefined;
- }),
+ },
/**
* Load an archived ping from disk.
*
* @param {string} id The pings id.
* @return {promise<object>} Promise that is resolved with the ping data.
*/
loadArchivedPing: Task.async(function*(id) {
@@ -729,81 +733,81 @@ var TelemetryStorageImpl = {
/**
* Saves session data to disk.
*/
saveSessionData(sessionData) {
return this._stateSaveSerializer.enqueueTask(() => this._saveSessionData(sessionData));
},
- _saveSessionData: Task.async(function* (sessionData) {
+ _saveSessionData: async function(sessionData) {
let dataDir = OS.Path.join(OS.Constants.Path.profileDir, DATAREPORTING_DIR);
- yield OS.File.makeDir(dataDir);
+ await OS.File.makeDir(dataDir);
let filePath = OS.Path.join(gDataReportingDir, SESSION_STATE_FILE_NAME);
try {
- yield CommonUtils.writeJSON(sessionData, filePath);
+ await CommonUtils.writeJSON(sessionData, filePath);
} catch (e) {
this._log.error("_saveSessionData - Failed to write session data to " + filePath, e);
Telemetry.getHistogramById("TELEMETRY_SESSIONDATA_FAILED_SAVE").add(1);
}
- }),
+ },
/**
* Loads session data from the session data file.
* @return {Promise<Object>} A promise resolved with an object on success,
* with null otherwise.
*/
loadSessionData() {
return this._stateSaveSerializer.enqueueTask(() => this._loadSessionData());
},
- _loadSessionData: Task.async(function* () {
+ _loadSessionData: async function () {
const dataFile = OS.Path.join(OS.Constants.Path.profileDir, DATAREPORTING_DIR,
SESSION_STATE_FILE_NAME);
let content;
try {
- content = yield OS.File.read(dataFile, { encoding: "utf-8" });
+ content = await OS.File.read(dataFile, { encoding: "utf-8" });
} catch (ex) {
this._log.info("_loadSessionData - can not load session data file", ex);
Telemetry.getHistogramById("TELEMETRY_SESSIONDATA_FAILED_LOAD").add(1);
return null;
}
let data;
try {
data = JSON.parse(content);
} catch (ex) {
this._log.error("_loadSessionData - failed to parse session data", ex);
Telemetry.getHistogramById("TELEMETRY_SESSIONDATA_FAILED_PARSE").add(1);
return null;
}
return data;
- }),
+ },
/**
* Remove an archived ping from disk.
*
* @param {string} id The pings id.
* @param {number} timestampCreated The pings creation timestamp.
* @param {string} type The pings type.
* @return {promise<object>} Promise that is resolved when the pings is removed.
*/
- _removeArchivedPing: Task.async(function*(id, timestampCreated, type) {
+ _removeArchivedPing: async function(id, timestampCreated, type) {
this._log.trace("_removeArchivedPing - id: " + id + ", timestampCreated: " + timestampCreated + ", type: " + type);
const path = getArchivedPingPath(id, new Date(timestampCreated), type);
const pathCompressed = path + "lz4";
this._log.trace("_removeArchivedPing - removing ping from: " + path);
- yield OS.File.remove(path, {ignoreAbsent: true});
- yield OS.File.remove(pathCompressed, {ignoreAbsent: true});
+ await OS.File.remove(path, {ignoreAbsent: true});
+ await OS.File.remove(pathCompressed, {ignoreAbsent: true});
// Remove the ping from the cache.
this._archivedPings.delete(id);
- }),
+ },
/**
* Clean the pings archive by removing old pings.
*
* @return {Promise} Resolved when the cleanup task completes.
*/
runCleanPingArchiveTask() {
// If there's an archive cleaning task already running, return it.