Commit 88355d1b authored by Daniel Varga's avatar Daniel Varga
Browse files

Backed out changeset 78d142f0f2f6 (bug 1615087) for linting failure at...

Backed out changeset 78d142f0f2f6 (bug 1615087) for linting failure at /builds/worker/checkouts/gecko/browser/components/urlbar/tests/browser/interventions_update/head.j

CLOSED TREE
parent bcf6a959
Loading
Loading
Loading
Loading
+966 −0

File changed.

Preview size limit exceeded, changes collapsed.

+98 −6
Original line number Diff line number Diff line
@@ -252,6 +252,8 @@ var gLogfileWritePromise;
// at once. Computers with many users (ex: a school computer), should not end
// up with dozens of BITS jobs.
var gBITSInUseByAnotherUser = false;
// The start time in milliseconds of the update check.
var gCheckStartMs;

XPCOMUtils.defineLazyGetter(this, "gLogEnabled", function aus_gLogEnabled() {
  return (
@@ -2197,8 +2199,18 @@ UpdateService.prototype = {
        // be resumed the next time the application starts. Downloads using
        // Windows BITS are not stopped since they don't require Firefox to be
        // running to perform the download.
        if (this._downloader && !this._downloader.usingBits) {
        if (this._downloader) {
          if (!this._downloader.usingBits) {
            this.stopDownload();
          } else {
            this._downloader.cleanup();
            // The BITS downloader isn't stopped on exit so the
            // active-update.xml needs to be saved for the values sent to
            // telemetry to be saved to disk.
            Cc["@mozilla.org/updates/update-manager;1"]
              .getService(Ci.nsIUpdateManager)
              .saveUpdates();
          }
        }
        // Prevent leaking the downloader (bug 454964)
        this._downloader = null;
@@ -2433,6 +2445,14 @@ UpdateService.prototype = {
      update.errorCode = parseInt(parts[1]);
    }

    if (
      update.state == STATE_SUCCEEDED ||
      update.patchCount == 1 ||
      (update.selectedPatch && update.selectedPatch.type == "complete")
    ) {
      AUSTLMY.pingUpdatePhases(update, true);
    }

    if (status != STATE_SUCCEEDED) {
      // Rotate the update logs so the update log isn't removed. By passing
      // false the patch directory won't be removed.
@@ -3689,6 +3709,9 @@ UpdateManager.prototype = {
      return;
    }

    let patch = update.selectedPatch.QueryInterface(Ci.nsIWritablePropertyBag);
    patch.setProperty("stageFinished", Math.ceil(Date.now() / 1000));

    var status = readStatusFile(getUpdatesDir());
    pingStateAndStatusCodes(update, false, status);
    var parts = status.split(":");
@@ -3716,6 +3739,20 @@ UpdateManager.prototype = {
      writeStatusFile(getUpdatesDir(), (update.state = STATE_APPLIED_SERVICE));
    }

    if (update.state == STATE_FAILED) {
      AUSTLMY.pingUpdatePhases(update, false);
    }

    if (
      update.state == STATE_APPLIED ||
      update.state == STATE_APPLIED_SERVICE ||
      update.state == STATE_PENDING ||
      update.state == STATE_PENDING_SERVICE ||
      update.state == STATE_PENDING_ELEVATE
    ) {
      patch.setProperty("applyStart", Math.floor(Date.now() / 1000));
    }

    // Now that the active update's properties have been updated write the
    // active-update.xml to disk. Since there have been no changes to the update
    // history the updates.xml will not be written to disk.
@@ -3895,6 +3932,7 @@ Checker.prototype = {
      throw Cr.NS_ERROR_NULL_POINTER;
    }

    gCheckStartMs = Date.now();
    let UpdateServiceInstance = UpdateServiceFactory.createInstance();
    // |force| can override |canCheckForUpdates| since |force| indicates a
    // manual update check. But nothing should override enterprise policies.
@@ -4207,6 +4245,17 @@ Downloader.prototype = {
   */
  _bitsActiveNotifications: false,

  /**
   * The start time of the first download attempt in milliseconds for telemetry.
   */
  _startDownloadMs: null,

  /**
   * The name of the downloader being used to download the update. This is used
   * when setting property names on the update patch for telemetry.
   */
  _downloaderName: null,

  /**
   * Cancels the active download.
   *
@@ -4484,12 +4533,20 @@ Downloader.prototype = {
      AUSTLMY.pingDownloadCode(undefined, AUSTLMY.DWNLD_ERR_NO_UPDATE_PATCH);
      return readStatusFile(updateDir);
    }
    // The update and the patch implement nsIWritablePropertyBag. Expose that
    // interface immediately after a patch is assigned so that
    // this.(_patch|_update).(get|set)Property can always safely be called.
    // QI the update and the patch to nsIWritablePropertyBag so it isn't
    // necessary later in the download code.
    this._update.QueryInterface(Ci.nsIWritablePropertyBag);
    if (gCheckStartMs && !this._update.getProperty("checkInterval")) {
      let interval = Math.max(
        Math.ceil((Date.now() - gCheckStartMs) / 1000),
        1
      );
      this._update.setProperty("checkInterval", interval);
    }
    // this._patch implements nsIWritablePropertyBag. Expose that interface
    // immediately after a patch is assigned so that this._patch.getProperty
    // and this._patch.setProperty can always safely be called.
    this._patch.QueryInterface(Ci.nsIWritablePropertyBag);

    this.isCompleteUpdate = this._patch.type == "complete";

    let canUseBits = false;
@@ -4503,6 +4560,14 @@ Downloader.prototype = {
      canUseBits = this._canUseBits(this._patch);
    }

    this._downloaderName = canUseBits ? "bits" : "internal";
    if (!this._patch.getProperty(this._downloaderName + "DownloadStart")) {
      this._patch.setProperty(
        this._downloaderName + "DownloadStart",
        Math.floor(Date.now() / 1000)
      );
    }

    if (!canUseBits) {
      let patchFile = getUpdatesDir().clone();
      patchFile.append(FILE_UPDATE_MAR);
@@ -4821,6 +4886,19 @@ Downloader.prototype = {
          .saveUpdates();
      }
    }
    // Only record the download bytes per second when there isn't already a
    // value for the bytes per second so downloads that are already in progess
    // don't have their records overwritten. When the Update Agent is
    // implemented this should be reworked so that telemetry receives the bytes
    // and seconds it took to complete for the entire update download instead of
    // just the sample that is currently recorded. Note: this._patch has already
    // been QI'd to nsIWritablePropertyBag.
    if (
      !this._patch.getProperty("internalBytes") &&
      !this._patch.getProperty("bitsBytes")
    ) {
      this._startDownloadMs = Date.now();
    }

    // Make shallow copy in case listeners remove themselves when called.
    let listeners = this._listeners.concat();
@@ -4848,6 +4926,11 @@ Downloader.prototype = {
    maxProgress
  ) {
    LOG("Downloader:onProgress - progress: " + progress + "/" + maxProgress);
    if (this._startDownloadMs) {
      let seconds = Math.round((Date.now() - this._startDownloadMs) / 1000);
      this._patch.setProperty(this._downloaderName + "Seconds", seconds);
      this._patch.setProperty(this._downloaderName + "Bytes", progress);
    }

    if (progress > this._patch.size) {
      LOG(
@@ -5004,6 +5087,10 @@ Downloader.prototype = {
        "retryTimeout: " +
        retryTimeout
    );
    this._patch.setProperty(
      this._downloaderName + "DownloadFinished",
      Math.floor(Date.now() / 1000)
    );
    if (Components.isSuccessCode(status)) {
      if (this._verifyDownload()) {
        if (shouldUseService()) {
@@ -5235,6 +5322,7 @@ Downloader.prototype = {
          10
        );

        AUSTLMY.pingUpdatePhases(this._update, false);
        if (downloadAttempts > maxAttempts) {
          LOG(
            "Downloader:onStopRequest - notifying observers of error. " +
@@ -5282,6 +5370,7 @@ Downloader.prototype = {
            this._update.name
        );
        gUpdateFileWriteInfo = { phase: "stage", failure: false };
        this._patch.setProperty("stageStart", Math.floor(Date.now() / 1000));
        // Stage the update
        try {
          Cc["@mozilla.org/updates/update-processor;1"]
@@ -5297,6 +5386,9 @@ Downloader.prototype = {
            shouldShowPrompt = true;
          }
        }
      } else {
        this._patch.setProperty("applyStart", Math.floor(Date.now() / 1000));
        um.saveUpdates();
      }
    }

+132 −0
Original line number Diff line number Diff line
@@ -14,6 +14,14 @@ const { BitsError, BitsUnknownError } = ChromeUtils.import(
);
ChromeUtils.import("resource://gre/modules/Services.jsm", this);

// It is possible for the update.session telemetry to be set more than once
// which must be prevented since they are scalars and setting them more than
// once could lead to values set in the first ping not being present in the
// next ping which would make the values incomprehensible in relation to the
// other values. This isn't needed for update.startup since this will only be
// set once during startup.
var gUpdatePhasesSetForSession = false;

var AUSTLMY = {
  // Telemetry for the application update background update check occurs when
  // the background update timer fires after the update interval which is
@@ -450,6 +458,130 @@ var AUSTLMY = {
    }
  },

  /**
   * Submit the update phase telemetry. These are scalars and must only be
   * submitted once per sesssion. The update.startup is only submitted once
   * once per session due to it only being submitted during startup and only the
   * first call to pingUpdatePhases for update.session will be submitted.
   *
   * @param  aUpdate
   *         The update object which contains the values to submit to telemetry.
   * @param  aIsStartup
   *         If true the telemetry will be set under update.startup and if false
   *         the telemetry will be set under update.session. When false
   *         subsequent calls will return early and not submit telemetry.
   */
  pingUpdatePhases: function UT_pingUpdatePhases(aUpdate, aIsStartup) {
    if (!aIsStartup && !Cu.isInAutomation) {
      if (gUpdatePhasesSetForSession) {
        return;
      }
      gUpdatePhasesSetForSession = true;
    }
    let basePrefix = aIsStartup ? "update.startup." : "update.session.";
    // None of the calls to getProperty should fail.
    try {
      let update = aUpdate.QueryInterface(Ci.nsIWritablePropertyBag);
      let scalarSet = Services.telemetry.scalarSet;

      // Though it is possible that the previous app version that was updated
      // from could change the record is for the app version that initiated the
      // update.
      scalarSet(basePrefix + "from_app_version", aUpdate.previousAppVersion);

      // The check interval only happens once even if the partial patch fails
      // to apply on restart and the complete patch is downloaded.
      scalarSet(
        basePrefix + "intervals.check",
        update.getProperty("checkInterval")
      );

      for (let i = 0; i < aUpdate.patchCount; ++i) {
        let patch = aUpdate
          .getPatchAt(i)
          .QueryInterface(Ci.nsIWritablePropertyBag);
        let type = patch.type;

        scalarSet(basePrefix + "mar_" + type + "_size_bytes", patch.size);

        let prefix = basePrefix + "intervals.";
        let internalDownloadStart = patch.getProperty("internalDownloadStart");
        let internalDownloadFinished = patch.getProperty(
          "internalDownloadFinished"
        );
        if (
          internalDownloadStart !== null &&
          internalDownloadFinished !== null
        ) {
          scalarSet(
            prefix + "download_internal_" + type,
            Math.max(internalDownloadFinished - internalDownloadStart, 1)
          );
        }

        let bitsDownloadStart = patch.getProperty("bitsDownloadStart");
        let bitsDownloadFinished = patch.getProperty("bitsDownloadFinished");
        if (bitsDownloadStart !== null && bitsDownloadFinished !== null) {
          scalarSet(
            prefix + "download_bits_" + type,
            Math.max(bitsDownloadFinished - bitsDownloadStart, 1)
          );
        }

        let stageStart = patch.getProperty("stageStart");
        let stageFinished = patch.getProperty("stageFinished");
        if (stageStart !== null && stageFinished !== null) {
          scalarSet(
            prefix + "stage_" + type,
            Math.max(stageFinished - stageStart, 1)
          );
        }

        // Both the partial and the complete patch are recorded for the apply
        // interval because it is possible for a partial patch to fail when it
        // is applied during a restart and then to try the complete patch.
        let applyStart = patch.getProperty("applyStart");
        if (applyStart !== null) {
          let applyFinished = Math.ceil(Date.now() / 1000);
          scalarSet(
            prefix + "apply_" + type,
            Math.max(applyFinished - applyStart, 1)
          );
        }

        prefix = basePrefix + "downloads.";
        let internalBytes = patch.getProperty("internalBytes");
        if (internalBytes !== null) {
          scalarSet(
            prefix + "internal_" + type + "_bytes",
            Math.max(internalBytes, 1)
          );
        }
        let internalSeconds = patch.getProperty("internalSeconds");
        if (internalSeconds !== null) {
          scalarSet(
            prefix + "internal_" + type + "_seconds",
            Math.max(internalSeconds, 1)
          );
        }

        let bitsBytes = patch.getProperty("bitsBytes");
        if (bitsBytes !== null) {
          scalarSet(prefix + "bits_" + type + "_bytes", Math.max(bitsBytes, 1));
        }
        let bitsSeconds = patch.getProperty("bitsSeconds");
        if (bitsSeconds !== null) {
          scalarSet(
            prefix + "bits_" + type + "_seconds",
            Math.max(bitsSeconds, 1)
          );
        }
      }
    } catch (e) {
      Cu.reportError(e);
    }
  },

  /**
   * Submit a telemetry ping for a boolean type histogram that indicates if the
   * service is installed and a telemetry ping for a boolean type histogram that
+16 −0
Original line number Diff line number Diff line
@@ -69,6 +69,22 @@ prefs =
[browser_doorhanger_sp_patch_partialApplyFailure_completeBadSize.js]
[browser_doorhanger_bc_downloaded_disableBITS.js]

# Telemetry Application Update Tests
[browser_telemetry_completeBadSize.js]
[browser_telemetry_partialBadSize_completeBadSize.js]
[browser_telemetry_complete_stageFailure.js]
[browser_telemetry_partial_stageFailure_complete_stageFailure.js]
[browser_telemetry_complete_applyFailure.js]
[browser_telemetry_partial_applyFailure_complete_applyFailure.js]
[browser_telemetry_partial_applyFailure_complete_stageFailure.js]
[browser_telemetry_partial_applyFailure_complete_applied.js]
[browser_telemetry_partial_applyFailure_complete_staged_applied.js]
[browser_telemetry_partialBadSize_complete_staged_applied.js]
[browser_telemetry_complete_applied.js]
[browser_telemetry_partial_applied.js]
[browser_telemetry_partial_staged_applied.js]
[browser_telemetry_complete_staged_applied.js]

# Telemetry Update Ping Tests
[browser_telemetry_updatePing_downloaded_ready.js]
[browser_telemetry_updatePing_staged_ready.js]
+17 −0
Original line number Diff line number Diff line
@@ -87,6 +87,23 @@ reason = test must be able to prevent file deletion.
[browser_doorhanger_sp_patch_partialApplyFailure_complete_staging.js]
[browser_doorhanger_sp_patch_partialApplyFailure_completeBadSize.js]

# Telemetry Application Update Tests
[browser_telemetry_completeBadSize.js]
[browser_telemetry_partialBadSize_completeBadSize.js]
[browser_telemetry_complete_stageFailure.js]
[browser_telemetry_partial_stageFailure_complete_stageFailure.js]
[browser_telemetry_complete_applyFailure.js]
[browser_telemetry_partial_applyFailure_complete_applyFailure.js]
[browser_telemetry_partial_applyFailure_complete_stageFailure.js]
[browser_telemetry_partial_applyFailure_complete_applied.js]
[browser_telemetry_partial_applyFailure_complete_staged_applied.js]
[browser_telemetry_partialBadSize_complete_staged_applied.js]
[browser_telemetry_complete_applied.js]
[browser_telemetry_partial_applied.js]
[browser_telemetry_partial_staged_applied.js]
[browser_telemetry_complete_staged_applied.js]


# Elevation Dialog Tests
[browser_elevationDialog.js]

Loading