Bug 842377 - Rename "constant only" to "pull only"; r=rnewman
authorGregory Szorc <gps@mozilla.com>
Mon, 18 Feb 2013 13:05:07 -0800
changeset 132129 7da1d0ed25d7b57d9d4b8ea8b15f53e8da566d38
parent 132128 6e0f106fd859046a1d5dbad9c5dd5df33f464e94
child 132130 69cc1bc86785012023ae4e5870f9c6da162271e5
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs842377
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 842377 - Rename "constant only" to "pull only"; r=rnewman The new name better reflects the lazy-init behavior of providers.
services/healthreport/healthreporter.jsm
services/healthreport/profile.jsm
services/healthreport/providers.jsm
services/healthreport/tests/xpcshell/test_healthreporter.js
services/metrics/dataprovider.jsm
services/metrics/modules-testing/mocks.jsm
--- a/services/healthreport/healthreporter.jsm
+++ b/services/healthreport/healthreporter.jsm
@@ -83,18 +83,18 @@ function AbstractHealthReporter(branch, 
   this._initialized = false;
   this._initializeHadError = false;
   this._initializedDeferred = Promise.defer();
   this._shutdownRequested = false;
   this._shutdownInitiated = false;
   this._shutdownComplete = false;
   this._shutdownCompleteCallback = null;
 
-  this._constantOnlyProviders = {};
-  this._constantOnlyProvidersRegistered = false;
+  this._pullOnlyProviders = {};
+  this._pullOnlyProvidersRegistered = false;
   this._lastDailyDate = null;
 
   // Yes, this will probably run concurrently with remaining constructor work.
   let hasFirstRun = this._prefs.get("service.firstRun", false);
   this._initHistogram = hasFirstRun ? TELEMETRY_INIT : TELEMETRY_INIT_FIRSTRUN;
   this._dbOpenHistogram = hasFirstRun ? TELEMETRY_DB_OPEN : TELEMETRY_DB_OPEN_FIRSTRUN;
 
   TelemetryStopwatch.start(this._initHistogram, this);
@@ -382,17 +382,17 @@ AbstractHealthReporter.prototype = Objec
   //--------------------
   // Provider Management
   //--------------------
 
   /**
    * Obtain a provider from its name.
    *
    * 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.
    */
   getProvider: function (name) {
     return this._collector.getProvider(name);
   },
 
   /**
    * Register a `Metrics.Provider` with this instance.
@@ -405,29 +405,29 @@ AbstractHealthReporter.prototype = Objec
    */
   registerProvider: function (provider) {
     return this._collector.registerProvider(provider);
   },
 
   /**
    * 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.
    *
-   * 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
    * provider has finished initializing.
    */
   registerProviderFromType: function (type) {
     let proto = type.prototype;
-    if (proto.constantOnly) {
-      this._log.info("Provider is constant-only. Deferring initialization: " +
+    if (proto.pullOnly) {
+      this._log.info("Provider is pull-only. Deferring initialization: " +
                      proto.name);
-      this._constantOnlyProviders[proto.name] = type;
+      this._pullOnlyProviders[proto.name] = type;
 
       return null;
     }
 
     let provider = this.initProviderFromType(type);
     return this.registerProvider(provider);
   },
 
@@ -501,60 +501,60 @@ AbstractHealthReporter.prototype = Objec
     let provider = new providerType();
     provider.initPreferences(this._branch + "provider.");
     provider.healthReporter = this;
 
     return provider;
   },
 
   /**
-   * Ensure that constant-only providers are registered.
+   * Ensure that pull-only providers are registered.
    */
-  ensureConstantOnlyProvidersRegistered: function () {
-    if (this._constantOnlyProvidersRegistered) {
+  ensurePullOnlyProvidersRegistered: function () {
+    if (this._pullOnlyProvidersRegistered) {
       return Promise.resolve();
     }
 
     let onFinished = function () {
-      this._constantOnlyProvidersRegistered = true;
+      this._pullOnlyProvidersRegistered = true;
 
       return Promise.resolve();
     }.bind(this);
 
-    return Task.spawn(function registerConstantProviders() {
-      for each (let providerType in this._constantOnlyProviders) {
+    return Task.spawn(function registerPullProviders() {
+      for each (let providerType in this._pullOnlyProviders) {
         try {
           let provider = this.initProviderFromType(providerType);
           yield this.registerProvider(provider);
         } catch (ex) {
-          this._log.warn("Error registering constant-only provider: " +
+          this._log.warn("Error registering pull-only provider: " +
                          CommonUtils.exceptionStr(ex));
         }
       }
     }.bind(this)).then(onFinished, onFinished);
   },
 
-  ensureConstantOnlyProvidersUnregistered: function () {
-    if (!this._constantOnlyProvidersRegistered) {
+  ensurePullOnlyProvidersUnregistered: function () {
+    if (!this._pullOnlyProvidersRegistered) {
       return Promise.resolve();
     }
 
     let onFinished = function () {
-      this._constantOnlyProvidersRegistered = false;
+      this._pullOnlyProvidersRegistered = false;
 
       return Promise.resolve();
     }.bind(this);
 
-    return Task.spawn(function unregisterConstantProviders() {
+    return Task.spawn(function unregisterPullProviders() {
       for (let provider of this._collector.providers) {
-        if (!provider.constantOnly) {
+        if (!provider.pullOnly) {
           continue;
         }
 
-        this._log.info("Shutting down constant-only provider: " +
+        this._log.info("Shutting down pull-only provider: " +
                        provider.name);
 
         try {
           yield provider.shutdown();
         } catch (ex) {
           this._log.warn("Error when shutting down provider: " +
                          CommonUtils.exceptionStr(ex));
         } finally {
@@ -613,30 +613,30 @@ AbstractHealthReporter.prototype = Objec
    * @param asObject
    *        (bool) Whether to resolve an object or JSON-encoded string of that
    *        object (the default).
    *
    * @return Promise<Object | string>
    */
   collectAndObtainJSONPayload: function (asObject=false) {
     return Task.spawn(function collectAndObtain() {
-      yield this.ensureConstantOnlyProvidersRegistered();
+      yield this.ensurePullOnlyProvidersRegistered();
 
       let payload;
       let error;
 
       try {
         yield this.collectMeasurements();
         payload = yield this.getJSONPayload(asObject);
       } catch (ex) {
         error = ex;
         this._log.warn("Error collecting and/or retrieving JSON payload: " +
                        CommonUtils.exceptionStr(ex));
       } finally {
-        yield this.ensureConstantOnlyProvidersUnregistered();
+        yield this.ensurePullOnlyProvidersUnregistered();
 
         if (error) {
           throw error;
         }
       }
 
       // We hold off throwing to ensure that behavior between finally
       // and generators and throwing is sane.
@@ -1039,26 +1039,26 @@ HealthReporter.prototype = Object.freeze
 
   /**
    * Called to initiate a data upload.
    *
    * The passed argument is a `DataSubmissionRequest` from policy.jsm.
    */
   requestDataUpload: function (request) {
     return Task.spawn(function doUpload() {
-      yield this.ensureConstantOnlyProvidersRegistered();
+      yield this.ensurePullOnlyProvidersRegistered();
       try {
         yield this.collectMeasurements();
         try {
           yield this._uploadData(request);
         } catch (ex) {
           this._onSubmitDataRequestFailure(ex);
         }
       } finally {
-        yield this.ensureConstantOnlyProvidersUnregistered();
+        yield this.ensurePullOnlyProvidersUnregistered();
       }
     }.bind(this));
   },
 
   /**
    * Request that server data be deleted.
    *
    * If deletion is scheduled to occur immediately, a promise will be returned
--- a/services/healthreport/profile.jsm
+++ b/services/healthreport/profile.jsm
@@ -209,17 +209,17 @@ function ProfileMetadataProvider() {
 }
 ProfileMetadataProvider.prototype = {
   __proto__: Metrics.Provider.prototype,
 
   name: "org.mozilla.profile",
 
   measurementTypes: [ProfileMetadataMeasurement],
 
-  constantOnly: true,
+  pullOnly: true,
 
   getProfileCreationDays: function () {
     let accessor = new ProfileCreationTimeAccessor(null, this._log);
 
     return accessor.created
                    .then(truncate);
   },
 
--- a/services/healthreport/providers.jsm
+++ b/services/healthreport/providers.jsm
@@ -121,17 +121,17 @@ this.AppInfoProvider = function AppInfoP
 }
 AppInfoProvider.prototype = Object.freeze({
   __proto__: Metrics.Provider.prototype,
 
   name: "org.mozilla.appInfo",
 
   measurementTypes: [AppInfoMeasurement, AppVersionMeasurement],
 
-  constantOnly: true,
+  pullOnly: true,
 
   appInfoFields: {
     // From nsIXULAppInfo.
     vendor: "vendor",
     name: "name",
     id: "ID",
     version: "version",
     appBuildID: "appBuildID",
@@ -298,17 +298,17 @@ this.SysInfoProvider = function SysInfoP
 
 SysInfoProvider.prototype = Object.freeze({
   __proto__: Metrics.Provider.prototype,
 
   name: "org.mozilla.sysinfo",
 
   measurementTypes: [SysInfoMeasurement],
 
-  constantOnly: true,
+  pullOnly: true,
 
   sysInfoFields: {
     cpucount: "cpuCount",
     memsize: "memoryMB",
     manufacturer: "manufacturer",
     device: "device",
     hardware: "hardware",
     name: "name",
@@ -481,17 +481,17 @@ this.SessionsProvider = function () {
 
 SessionsProvider.prototype = Object.freeze({
   __proto__: Metrics.Provider.prototype,
 
   name: "org.mozilla.appSessions",
 
   measurementTypes: [CurrentSessionMeasurement, PreviousSessionsMeasurement],
 
-  constantOnly: true,
+  pullOnly: true,
 
   collectConstantData: function () {
     let previous = this.getMeasurement("previous", 3);
 
     return this.storage.enqueueTransaction(this._recordAndPruneSessions.bind(this));
   },
 
   _recordAndPruneSessions: function () {
@@ -752,17 +752,17 @@ this.CrashesProvider = function () {
 
 CrashesProvider.prototype = Object.freeze({
   __proto__: Metrics.Provider.prototype,
 
   name: "org.mozilla.crashes",
 
   measurementTypes: [DailyCrashesMeasurement],
 
-  constantOnly: true,
+  pullOnly: true,
 
   collectConstantData: function () {
     return Task.spawn(this._populateCrashCounts.bind(this));
   },
 
   _populateCrashCounts: function () {
     let now = new Date();
     let service = new CrashDirectoryService();
--- a/services/healthreport/tests/xpcshell/test_healthreporter.js
+++ b/services/healthreport/tests/xpcshell/test_healthreporter.js
@@ -166,19 +166,18 @@ add_task(function test_register_provider
   let reporter = yield getReporter("category_manager");
   do_check_eq(reporter._collector._providers.size, 0);
   yield reporter.registerProvidersFromCategoryManager(category);
   do_check_eq(reporter._collector._providers.size, 1);
 
   reporter._shutdown();
 });
 
-// Constant only providers are only initialized at constant collect
-// time.
-add_task(function test_constant_only_providers() {
+// Pull-only providers are only initialized at collect time.
+add_task(function test_pull_only_providers() {
   const category = "healthreporter-constant-only";
 
   let cm = Cc["@mozilla.org/categorymanager;1"]
              .getService(Ci.nsICategoryManager);
   cm.addCategoryEntry(category, "DummyProvider",
                       "resource://testing-common/services/metrics/mocks.jsm",
                       false, true);
   cm.addCategoryEntry(category, "DummyConstantProvider",
@@ -189,19 +188,19 @@ add_task(function test_constant_only_pro
   do_check_eq(reporter._collector._providers.size, 0);
   yield reporter.registerProvidersFromCategoryManager(category);
   do_check_eq(reporter._collector._providers.size, 1);
   do_check_true(reporter._storage.hasProvider("DummyProvider"));
   do_check_false(reporter._storage.hasProvider("DummyConstantProvider"));
   do_check_neq(reporter.getProvider("DummyProvider"), null);
   do_check_null(reporter.getProvider("DummyConstantProvider"));
 
-  yield reporter.ensureConstantOnlyProvidersRegistered();
+  yield reporter.ensurePullOnlyProvidersRegistered();
   yield reporter.collectMeasurements();
-  yield reporter.ensureConstantOnlyProvidersUnregistered();
+  yield reporter.ensurePullOnlyProvidersUnregistered();
 
   do_check_eq(reporter._collector._providers.size, 1);
   do_check_true(reporter._storage.hasProvider("DummyConstantProvider"));
 
   let mID = reporter._storage.measurementID("DummyConstantProvider", "DummyMeasurement", 1);
   let values = yield reporter._storage.getMeasurementValues(mID);
   do_check_true(values.singular.size > 0);
 
--- a/services/metrics/dataprovider.jsm
+++ b/services/metrics/dataprovider.jsm
@@ -387,28 +387,30 @@ this.Provider = function () {
   this._log = Log4Moz.repository.getLogger("Services.Metrics.Provider." + this.name);
 
   this.measurements = null;
   this.storage = null;
 }
 
 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
-   * `collectConstantData` is called and the provider may be torn down after
-   * this function has finished.
+   * If this is true, the provider pulls data from other sources. By contrast,
+   * "push-based" providers subscribe to foreign sources and record/react to
+   * external events as they happen.
    *
-   * This is an optimization so provider instances aren't dead weight while the
-   * application is running.
+   * Pull-only providers likely aren't instantiated until a data collection
+   * 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.
    *
    * If the measurement is not found, an Error is thrown.
    */
   getMeasurement: function (name, version) {
     if (!Number.isInteger(version)) {
--- a/services/metrics/modules-testing/mocks.jsm
+++ b/services/metrics/modules-testing/mocks.jsm
@@ -98,11 +98,11 @@ DummyProvider.prototype = {
 
 this.DummyConstantProvider = function () {
   DummyProvider.call(this, "DummyConstantProvider");
 }
 
 DummyConstantProvider.prototype = {
   __proto__: DummyProvider.prototype,
 
-  constantOnly: true,
+  pullOnly: true,
 };