Bug 842377 - Rename "constant only" to "pull only"; r=rnewman

The new name better reflects the lazy-init behavior of providers.
This commit is contained in:
Gregory Szorc 2013-02-18 13:05:07 -08:00
parent e3718a0e0f
commit 54e53bc513
6 changed files with 45 additions and 44 deletions

View File

@ -88,8 +88,8 @@ function AbstractHealthReporter(branch, policy, sessionRecorder) {
this._shutdownComplete = false; this._shutdownComplete = false;
this._shutdownCompleteCallback = null; this._shutdownCompleteCallback = null;
this._constantOnlyProviders = {}; this._pullOnlyProviders = {};
this._constantOnlyProvidersRegistered = false; this._pullOnlyProvidersRegistered = false;
this._lastDailyDate = null; this._lastDailyDate = null;
// Yes, this will probably run concurrently with remaining constructor work. // Yes, this will probably run concurrently with remaining constructor work.
@ -387,7 +387,7 @@ AbstractHealthReporter.prototype = Object.freeze({
* Obtain a provider from its name. * Obtain a provider from its name.
* *
* This will only return providers that are currently initialized. If * This will only return providers that are currently initialized. If
* a provider is lazy initialized (like constant-only providers) this * a provider is lazy initialized (like pull-only providers) this
* will likely not return anything. * will likely not return anything.
*/ */
getProvider: function (name) { getProvider: function (name) {
@ -410,19 +410,19 @@ AbstractHealthReporter.prototype = Object.freeze({
/** /**
* Registers a provider from its constructor function. * Registers a provider from its constructor function.
* *
* If the provider is constant-only, it will be stashed away and * If the provider is pull-only, it will be stashed away and
* initialized later. Null will be returned. * initialized later. Null will be returned.
* *
* If it is not constant-only, it will be initialized immediately and a * If it is not pull-only, it will be initialized immediately and a
* promise will be returned. The promise will be resolved when the * promise will be returned. The promise will be resolved when the
* provider has finished initializing. * provider has finished initializing.
*/ */
registerProviderFromType: function (type) { registerProviderFromType: function (type) {
let proto = type.prototype; let proto = type.prototype;
if (proto.constantOnly) { if (proto.pullOnly) {
this._log.info("Provider is constant-only. Deferring initialization: " + this._log.info("Provider is pull-only. Deferring initialization: " +
proto.name); proto.name);
this._constantOnlyProviders[proto.name] = type; this._pullOnlyProviders[proto.name] = type;
return null; return null;
} }
@ -506,50 +506,50 @@ AbstractHealthReporter.prototype = Object.freeze({
}, },
/** /**
* Ensure that constant-only providers are registered. * Ensure that pull-only providers are registered.
*/ */
ensureConstantOnlyProvidersRegistered: function () { ensurePullOnlyProvidersRegistered: function () {
if (this._constantOnlyProvidersRegistered) { if (this._pullOnlyProvidersRegistered) {
return Promise.resolve(); return Promise.resolve();
} }
let onFinished = function () { let onFinished = function () {
this._constantOnlyProvidersRegistered = true; this._pullOnlyProvidersRegistered = true;
return Promise.resolve(); return Promise.resolve();
}.bind(this); }.bind(this);
return Task.spawn(function registerConstantProviders() { return Task.spawn(function registerPullProviders() {
for each (let providerType in this._constantOnlyProviders) { for each (let providerType in this._pullOnlyProviders) {
try { try {
let provider = this.initProviderFromType(providerType); let provider = this.initProviderFromType(providerType);
yield this.registerProvider(provider); yield this.registerProvider(provider);
} catch (ex) { } catch (ex) {
this._log.warn("Error registering constant-only provider: " + this._log.warn("Error registering pull-only provider: " +
CommonUtils.exceptionStr(ex)); CommonUtils.exceptionStr(ex));
} }
} }
}.bind(this)).then(onFinished, onFinished); }.bind(this)).then(onFinished, onFinished);
}, },
ensureConstantOnlyProvidersUnregistered: function () { ensurePullOnlyProvidersUnregistered: function () {
if (!this._constantOnlyProvidersRegistered) { if (!this._pullOnlyProvidersRegistered) {
return Promise.resolve(); return Promise.resolve();
} }
let onFinished = function () { let onFinished = function () {
this._constantOnlyProvidersRegistered = false; this._pullOnlyProvidersRegistered = false;
return Promise.resolve(); return Promise.resolve();
}.bind(this); }.bind(this);
return Task.spawn(function unregisterConstantProviders() { return Task.spawn(function unregisterPullProviders() {
for (let provider of this._collector.providers) { for (let provider of this._collector.providers) {
if (!provider.constantOnly) { if (!provider.pullOnly) {
continue; continue;
} }
this._log.info("Shutting down constant-only provider: " + this._log.info("Shutting down pull-only provider: " +
provider.name); provider.name);
try { try {
@ -618,7 +618,7 @@ AbstractHealthReporter.prototype = Object.freeze({
*/ */
collectAndObtainJSONPayload: function (asObject=false) { collectAndObtainJSONPayload: function (asObject=false) {
return Task.spawn(function collectAndObtain() { return Task.spawn(function collectAndObtain() {
yield this.ensureConstantOnlyProvidersRegistered(); yield this.ensurePullOnlyProvidersRegistered();
let payload; let payload;
let error; let error;
@ -631,7 +631,7 @@ AbstractHealthReporter.prototype = Object.freeze({
this._log.warn("Error collecting and/or retrieving JSON payload: " + this._log.warn("Error collecting and/or retrieving JSON payload: " +
CommonUtils.exceptionStr(ex)); CommonUtils.exceptionStr(ex));
} finally { } finally {
yield this.ensureConstantOnlyProvidersUnregistered(); yield this.ensurePullOnlyProvidersUnregistered();
if (error) { if (error) {
throw error; throw error;
@ -1044,7 +1044,7 @@ HealthReporter.prototype = Object.freeze({
*/ */
requestDataUpload: function (request) { requestDataUpload: function (request) {
return Task.spawn(function doUpload() { return Task.spawn(function doUpload() {
yield this.ensureConstantOnlyProvidersRegistered(); yield this.ensurePullOnlyProvidersRegistered();
try { try {
yield this.collectMeasurements(); yield this.collectMeasurements();
try { try {
@ -1053,7 +1053,7 @@ HealthReporter.prototype = Object.freeze({
this._onSubmitDataRequestFailure(ex); this._onSubmitDataRequestFailure(ex);
} }
} finally { } finally {
yield this.ensureConstantOnlyProvidersUnregistered(); yield this.ensurePullOnlyProvidersUnregistered();
} }
}.bind(this)); }.bind(this));
}, },

View File

@ -214,7 +214,7 @@ ProfileMetadataProvider.prototype = {
measurementTypes: [ProfileMetadataMeasurement], measurementTypes: [ProfileMetadataMeasurement],
constantOnly: true, pullOnly: true,
getProfileCreationDays: function () { getProfileCreationDays: function () {
let accessor = new ProfileCreationTimeAccessor(null, this._log); let accessor = new ProfileCreationTimeAccessor(null, this._log);

View File

@ -126,7 +126,7 @@ AppInfoProvider.prototype = Object.freeze({
measurementTypes: [AppInfoMeasurement, AppVersionMeasurement], measurementTypes: [AppInfoMeasurement, AppVersionMeasurement],
constantOnly: true, pullOnly: true,
appInfoFields: { appInfoFields: {
// From nsIXULAppInfo. // From nsIXULAppInfo.
@ -303,7 +303,7 @@ SysInfoProvider.prototype = Object.freeze({
measurementTypes: [SysInfoMeasurement], measurementTypes: [SysInfoMeasurement],
constantOnly: true, pullOnly: true,
sysInfoFields: { sysInfoFields: {
cpucount: "cpuCount", cpucount: "cpuCount",
@ -486,7 +486,7 @@ SessionsProvider.prototype = Object.freeze({
measurementTypes: [CurrentSessionMeasurement, PreviousSessionsMeasurement], measurementTypes: [CurrentSessionMeasurement, PreviousSessionsMeasurement],
constantOnly: true, pullOnly: true,
collectConstantData: function () { collectConstantData: function () {
let previous = this.getMeasurement("previous", 3); let previous = this.getMeasurement("previous", 3);
@ -757,7 +757,7 @@ CrashesProvider.prototype = Object.freeze({
measurementTypes: [DailyCrashesMeasurement], measurementTypes: [DailyCrashesMeasurement],
constantOnly: true, pullOnly: true,
collectConstantData: function () { collectConstantData: function () {
return Task.spawn(this._populateCrashCounts.bind(this)); return Task.spawn(this._populateCrashCounts.bind(this));

View File

@ -171,9 +171,8 @@ add_task(function test_register_providers_from_category_manager() {
reporter._shutdown(); reporter._shutdown();
}); });
// Constant only providers are only initialized at constant collect // Pull-only providers are only initialized at collect time.
// time. add_task(function test_pull_only_providers() {
add_task(function test_constant_only_providers() {
const category = "healthreporter-constant-only"; const category = "healthreporter-constant-only";
let cm = Cc["@mozilla.org/categorymanager;1"] let cm = Cc["@mozilla.org/categorymanager;1"]
@ -194,9 +193,9 @@ add_task(function test_constant_only_providers() {
do_check_neq(reporter.getProvider("DummyProvider"), null); do_check_neq(reporter.getProvider("DummyProvider"), null);
do_check_null(reporter.getProvider("DummyConstantProvider")); do_check_null(reporter.getProvider("DummyConstantProvider"));
yield reporter.ensureConstantOnlyProvidersRegistered(); yield reporter.ensurePullOnlyProvidersRegistered();
yield reporter.collectMeasurements(); yield reporter.collectMeasurements();
yield reporter.ensureConstantOnlyProvidersUnregistered(); yield reporter.ensurePullOnlyProvidersUnregistered();
do_check_eq(reporter._collector._providers.size, 1); do_check_eq(reporter._collector._providers.size, 1);
do_check_true(reporter._storage.hasProvider("DummyConstantProvider")); do_check_true(reporter._storage.hasProvider("DummyConstantProvider"));

View File

@ -392,18 +392,20 @@ this.Provider = function () {
Provider.prototype = Object.freeze({ Provider.prototype = Object.freeze({
/** /**
* Whether the provider provides only constant data. * Whether the provider only pulls data from other sources.
* *
* If this is true, the provider likely isn't instantiated until * If this is true, the provider pulls data from other sources. By contrast,
* `collectConstantData` is called and the provider may be torn down after * "push-based" providers subscribe to foreign sources and record/react to
* this function has finished. * external events as they happen.
* *
* This is an optimization so provider instances aren't dead weight while the * Pull-only providers likely aren't instantiated until a data collection
* application is running. * is performed. Thus, implementations cannot rely on a provider instance
* always being alive. This is an optimization so provider instances aren't
* dead weight while the application is running.
* *
* This must be set on the prototype for the optimization to be realized. * This must be set on the prototype to have an effect.
*/ */
constantOnly: false, pullOnly: false,
/** /**
* Obtain a `Measurement` from its name and version. * Obtain a `Measurement` from its name and version.

View File

@ -103,6 +103,6 @@ this.DummyConstantProvider = function () {
DummyConstantProvider.prototype = { DummyConstantProvider.prototype = {
__proto__: DummyProvider.prototype, __proto__: DummyProvider.prototype,
constantOnly: true, pullOnly: true,
}; };