Bug 1136071 - Return a promise in TelemetryPing/TelemetrySession if the initialisation is already in progress. r=gfritzsche

This commit is contained in:
Alessio Placitelli 2015-02-25 23:54:34 +01:00
parent 9e190f62c8
commit 11685b342e
2 changed files with 18 additions and 12 deletions

View File

@ -276,6 +276,8 @@ let Impl = {
_clientID: null,
// A task performing delayed initialization
_delayedInitTask: null,
// The deferred promise resolved when the initialization task completes.
_delayedInitTaskDeferred: null,
_shutdownBarrier: new AsyncShutdown.Barrier("TelemetryPing: Waiting for clients."),
@ -676,7 +678,7 @@ let Impl = {
if (this._delayedInitTask) {
this._log.error("setupTelemetry - init task already running");
return this._delayedInitTask;
return this._delayedInitTaskDeferred.promise;
}
if (this._initialized && !testing) {
@ -702,7 +704,7 @@ let Impl = {
// Delay full telemetry initialization to give the browser time to
// run various late initializers. Otherwise our gathered memory
// footprint and other numbers would be too optimistic.
let deferred = Promise.defer();
this._delayedInitTaskDeferred = Promise.defer();
this._delayedInitTask = new DeferredTask(function* () {
try {
this._initialized = true;
@ -734,11 +736,12 @@ let Impl = {
}
Telemetry.asyncFetchTelemetryData(function () {});
deferred.resolve();
this._delayedInitTaskDeferred.resolve();
} catch (e) {
deferred.reject(e);
this._delayedInitTaskDeferred.reject(e);
} finally {
this._delayedInitTask = null;
this._delayedInitTaskDeferred = null;
}
}.bind(this), testing ? TELEMETRY_TEST_DELAY : TELEMETRY_DELAY);
@ -747,7 +750,7 @@ let Impl = {
() => this._getState());
this._delayedInitTask.arm();
return deferred.promise;
return this._delayedInitTaskDeferred.promise;
},
shutdown: function() {

View File

@ -458,6 +458,8 @@ let Impl = {
_dailyTimerId: null,
// A task performing delayed initialization of the chrome process
_delayedInitTask: null,
// The deferred promise resolved when the initialization task completes.
_delayedInitTaskDeferred: null,
/**
* Gets a series of simple measurements (counters). At the moment, this
@ -1051,12 +1053,12 @@ let Impl = {
this._log.trace("setupChromeProcess");
if (this._delayedInitTask) {
this._log.error("setupTelemetry - init task already running");
return this._delayedInitTask;
this._log.error("setupChromeProcess - init task already running");
return this._delayedInitTaskDeferred.promise;
}
if (this._initialized && !testing) {
this._log.error("setupTelemetry - already initialized");
this._log.error("setupChromeProcess - already initialized");
return Promise.resolve();
}
@ -1101,7 +1103,7 @@ let Impl = {
// Delay full telemetry initialization to give the browser time to
// run various late initializers. Otherwise our gathered memory
// footprint and other numbers would be too optimistic.
let deferred = Promise.defer();
this._delayedInitTaskDeferred = Promise.defer();
this._delayedInitTask = new DeferredTask(function* () {
try {
this._initialized = true;
@ -1121,16 +1123,17 @@ let Impl = {
TelemetryEnvironment.registerChangeListener(ENVIRONMENT_CHANGE_LISTENER,
() => this._onEnvironmentChange());
deferred.resolve();
this._delayedInitTaskDeferred.resolve();
} catch (e) {
deferred.reject();
this._delayedInitTaskDeferred.reject();
} finally {
this._delayedInitTask = null;
this._delayedInitTaskDeferred = null;
}
}.bind(this), testing ? TELEMETRY_TEST_DELAY : TELEMETRY_DELAY);
this._delayedInitTask.arm();
return deferred.promise;
return this._delayedInitTaskDeferred.promise;
},
/**