Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Refactor 'Telemetry enabled' checking code to clarify the expected bo…
Browse files Browse the repository at this point in the history
…olean result
  • Loading branch information
jaredhirsch committed Jan 24, 2018
1 parent 90fbe9a commit c8b1747
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion addon/bootstrap.js
Expand Up @@ -211,7 +211,7 @@ function handleMessage(msg, sender, sendReply) {
return;
}

if (msg.funcName === "getTelemetryPref") {
if (msg.funcName === "isTelemetryEnabled") {
let telemetryEnabled = getBoolPref(TELEMETRY_ENABLED_PREF);
sendReply({type: "success", value: telemetryEnabled});
} else if (msg.funcName === "isUploadDisabled") {
Expand Down
16 changes: 8 additions & 8 deletions addon/webextension/background/analytics.js
Expand Up @@ -6,7 +6,7 @@ this.analytics = (function() {
let exports = {};

let telemetryPrefKnown = false;
let telemetryPref;
let telemetryEnabled;

const EVENT_BATCH_DURATION = 1000; // ms for setTimeout
let pendingEvents = [];
Expand Down Expand Up @@ -79,7 +79,7 @@ this.analytics = (function() {
log.warn("sendEvent called before we were able to refresh");
return Promise.resolve();
}
if (!telemetryPref) {
if (!telemetryEnabled) {
log.info(`Cancelled sendEvent ${eventCategory}/${action}/${label || 'none'} ${JSON.stringify(options)}`);
return Promise.resolve();
}
Expand Down Expand Up @@ -129,24 +129,24 @@ this.analytics = (function() {
};

exports.refreshTelemetryPref = function() {
return communication.sendToBootstrap("getTelemetryPref").then((result) => {
return communication.sendToBootstrap("isTelemetryEnabled").then((result) => {
telemetryPrefKnown = true;
if (result === communication.NO_BOOTSTRAP) {
telemetryPref = true;
telemetryEnabled = true;
} else {
telemetryPref = result;
telemetryEnabled = result;
}
}, (error) => {
// If there's an error reading the pref, we should assume that we shouldn't send data
telemetryPrefKnown = true;
telemetryPref = false;
telemetryEnabled = false;
throw error;
});
};

exports.getTelemetryPrefSync = function() {
exports.isTelemetryEnabled = function() {
catcher.watchPromise(exports.refreshTelemetryPref());
return !!telemetryPref;
return telemetryEnabled;
};

let timingData = new Map();
Expand Down
2 changes: 1 addition & 1 deletion addon/webextension/background/senderror.js
Expand Up @@ -88,7 +88,7 @@ this.senderror = (function() {
};

exports.reportError = function(e) {
if (!analytics.getTelemetryPrefSync()) {
if (!analytics.isTelemetryEnabled()) {
log.error("Telemetry disabled. Not sending critical error:", e);
return;
}
Expand Down

0 comments on commit c8b1747

Please sign in to comment.