mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1206085: Replacing preprocessor directives with AppConstants in Telemetry modules. r=gfritzsche
--HG-- extra : commitid : Gk4m91cFhEq extra : rebase_source : 783a87d1ab4ce31e7dd8a347b5f0b314cd970414
This commit is contained in:
parent
13a4f5584f
commit
35b0792faf
@ -23,6 +23,7 @@ Cu.import("resource://gre/modules/DeferredTask.jsm", this);
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
Cu.import("resource://gre/modules/Timer.jsm");
|
||||
Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
const Utils = TelemetryUtils;
|
||||
|
||||
@ -674,18 +675,18 @@ var Impl = {
|
||||
const isOptout = IS_UNIFIED_TELEMETRY && (!Policy.isUnifiedOptin() || this._isInOptoutSample());
|
||||
Telemetry.canRecordBase = enabled || isOptout;
|
||||
|
||||
#ifdef MOZILLA_OFFICIAL
|
||||
// Enable extended telemetry if:
|
||||
// * the telemetry preference is set and
|
||||
// * this is an official build or we are in test-mode
|
||||
// We only do the latter check for official builds so that e.g. developer builds
|
||||
// still enable Telemetry based on prefs.
|
||||
Telemetry.canRecordExtended = enabled && (Telemetry.isOfficialTelemetry || this._testMode);
|
||||
#else
|
||||
// Turn off extended telemetry recording if disabled by preferences or if base/telemetry
|
||||
// telemetry recording is off.
|
||||
Telemetry.canRecordExtended = enabled;
|
||||
#endif
|
||||
if (AppConstants.MOZILLA_OFFICIAL) {
|
||||
// Enable extended telemetry if:
|
||||
// * the telemetry preference is set and
|
||||
// * this is an official build or we are in test-mode
|
||||
// We only do the latter check for official builds so that e.g. developer builds
|
||||
// still enable Telemetry based on prefs.
|
||||
Telemetry.canRecordExtended = enabled && (Telemetry.isOfficialTelemetry || this._testMode);
|
||||
} else {
|
||||
// Turn off extended telemetry recording if disabled by preferences or if base/telemetry
|
||||
// telemetry recording is off.
|
||||
Telemetry.canRecordExtended = enabled;
|
||||
}
|
||||
|
||||
this._log.config("enableTelemetryRecording - canRecordBase:" + Telemetry.canRecordBase +
|
||||
", canRecordExtended: " + Telemetry.canRecordExtended);
|
||||
|
@ -20,16 +20,17 @@ Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
|
||||
Cu.import("resource://gre/modules/ObjectUtils.jsm");
|
||||
Cu.import("resource://gre/modules/TelemetryController.jsm", this);
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
const Utils = TelemetryUtils;
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ctypes",
|
||||
"resource://gre/modules/ctypes.jsm");
|
||||
#ifndef MOZ_WIDGET_GONK
|
||||
Cu.import("resource://gre/modules/AddonManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
|
||||
"resource://gre/modules/LightweightThemeManager.jsm");
|
||||
#endif
|
||||
if (AppConstants.platform !== "gonk") {
|
||||
Cu.import("resource://gre/modules/AddonManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
|
||||
"resource://gre/modules/LightweightThemeManager.jsm");
|
||||
}
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ProfileAge",
|
||||
"resource://gre/modules/ProfileAge.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
|
||||
@ -274,7 +275,6 @@ function getGfxAdapter(aSuffix = "") {
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
/**
|
||||
* Gets the service pack information on Windows platforms. This was copied from
|
||||
* nsUpdateService.js.
|
||||
@ -282,6 +282,12 @@ function getGfxAdapter(aSuffix = "") {
|
||||
* @return An object containing the service pack major and minor versions.
|
||||
*/
|
||||
function getServicePack() {
|
||||
const UNKNOWN_SERVICE_PACK = {major: null, minor: null};
|
||||
|
||||
if (AppConstants.platform !== "win") {
|
||||
return UNKNOWN_SERVICE_PACK;
|
||||
}
|
||||
|
||||
const BYTE = ctypes.uint8_t;
|
||||
const WORD = ctypes.uint16_t;
|
||||
const DWORD = ctypes.uint32_t;
|
||||
@ -324,15 +330,11 @@ function getServicePack() {
|
||||
minor: winVer.wServicePackMinor,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
major: null,
|
||||
minor: null,
|
||||
};
|
||||
return UNKNOWN_SERVICE_PACK;
|
||||
} finally {
|
||||
kernel32.close();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Encapsulates the asynchronous magic interfacing with the addon manager. The builder
|
||||
@ -448,12 +450,12 @@ EnvironmentAddonBuilder.prototype = {
|
||||
_updateAddons: Task.async(function* () {
|
||||
this._environment._log.trace("_updateAddons");
|
||||
let personaId = null;
|
||||
#ifndef MOZ_WIDGET_GONK
|
||||
let theme = LightweightThemeManager.currentTheme;
|
||||
if (theme) {
|
||||
personaId = theme.id;
|
||||
if (AppConstants.platform !== "gonk") {
|
||||
let theme = LightweightThemeManager.currentTheme;
|
||||
if (theme) {
|
||||
personaId = theme.id;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
let addons = {
|
||||
activeAddons: yield this._getActiveAddons(),
|
||||
@ -668,20 +670,20 @@ function EnvironmentCache() {
|
||||
// Build the remaining asynchronous parts of the environment. Don't register change listeners
|
||||
// until the initial environment has been built.
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
this._addonBuilder = {
|
||||
watchForChanges: function() {}
|
||||
}
|
||||
let p = [];
|
||||
#else
|
||||
this._addonBuilder = new EnvironmentAddonBuilder(this);
|
||||
if (AppConstants.platform === "gonk") {
|
||||
this._addonBuilder = {
|
||||
watchForChanges: function() {}
|
||||
};
|
||||
} else {
|
||||
this._addonBuilder = new EnvironmentAddonBuilder(this);
|
||||
p = [ this._addonBuilder.init() ];
|
||||
}
|
||||
|
||||
let p = [ this._addonBuilder.init() ];
|
||||
#endif
|
||||
#ifndef MOZ_WIDGET_ANDROID
|
||||
this._currentEnvironment.profile = {};
|
||||
p.push(this._updateProfile());
|
||||
#endif
|
||||
if (AppConstants.platform !== "android") {
|
||||
this._currentEnvironment.profile = {};
|
||||
p.push(this._updateProfile());
|
||||
}
|
||||
|
||||
let setup = () => {
|
||||
this._initTask = null;
|
||||
@ -972,9 +974,9 @@ EnvironmentCache.prototype = {
|
||||
* @returns null on error, true if we are the default browser, or false otherwise.
|
||||
*/
|
||||
_isDefaultBrowser: function () {
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
return true;
|
||||
#else
|
||||
if (AppConstants.platform === "gonk") {
|
||||
return true;
|
||||
}
|
||||
if (!("@mozilla.org/browser/shell-service;1" in Cc)) {
|
||||
this._log.info("_isDefaultBrowser - Could not obtain browser shell service");
|
||||
return null;
|
||||
@ -998,7 +1000,6 @@ EnvironmentCache.prototype = {
|
||||
}
|
||||
|
||||
return null;
|
||||
#endif
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1011,13 +1012,7 @@ EnvironmentCache.prototype = {
|
||||
} catch (e) {}
|
||||
|
||||
this._currentEnvironment.settings = {
|
||||
#ifndef MOZ_WIDGET_GONK
|
||||
addonCompatibilityCheckEnabled: AddonManager.checkCompatibility,
|
||||
#endif
|
||||
blocklistEnabled: Preferences.get(PREF_BLOCKLIST_ENABLED, true),
|
||||
#ifndef MOZ_WIDGET_ANDROID
|
||||
isDefaultBrowser: this._isDefaultBrowser(),
|
||||
#endif
|
||||
e10sEnabled: Services.appinfo.browserTabsRemoteAutostart,
|
||||
telemetryEnabled: Preferences.get(PREF_TELEMETRY_ENABLED, false),
|
||||
isInOptoutSample: TelemetryController.isInOptoutSample,
|
||||
@ -1030,6 +1025,16 @@ EnvironmentCache.prototype = {
|
||||
userPrefs: this._getPrefData(),
|
||||
};
|
||||
|
||||
if (AppConstants.platform !== "gonk") {
|
||||
this._currentEnvironment.settings.addonCompatibilityCheckEnabled =
|
||||
AddonManager.checkCompatibility;
|
||||
}
|
||||
|
||||
if (AppConstants.platform !== "android") {
|
||||
this._currentEnvironment.settings.isDefaultBrowser =
|
||||
this._isDefaultBrowser();
|
||||
}
|
||||
|
||||
this._updateSearchEngine();
|
||||
},
|
||||
|
||||
@ -1106,12 +1111,16 @@ EnvironmentCache.prototype = {
|
||||
return cpuData;
|
||||
},
|
||||
|
||||
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
|
||||
/**
|
||||
* Get the device information, if we are on a portable device.
|
||||
* @return Object containing the device information data.
|
||||
* @return Object containing the device information data, or null if
|
||||
* not a portable device.
|
||||
*/
|
||||
_getDeviceData: function () {
|
||||
if (["gonk", "android"].indexOf(AppConstants.platform) === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
model: getSysinfoProperty("device", null),
|
||||
manufacturer: getSysinfoProperty("manufacturer", null),
|
||||
@ -1119,30 +1128,28 @@ EnvironmentCache.prototype = {
|
||||
isTablet: getSysinfoProperty("tablet", null),
|
||||
};
|
||||
},
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Get the OS information.
|
||||
* @return Object containing the OS data.
|
||||
*/
|
||||
_getOSData: function () {
|
||||
#ifdef XP_WIN
|
||||
// Try to get service pack information.
|
||||
let servicePack = getServicePack();
|
||||
#endif
|
||||
|
||||
return {
|
||||
let data = {
|
||||
name: getSysinfoProperty("name", null),
|
||||
version: getSysinfoProperty("version", null),
|
||||
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
|
||||
kernelVersion: getSysinfoProperty("kernel_version", null),
|
||||
#elif defined(XP_WIN)
|
||||
servicePackMajor: servicePack.major,
|
||||
servicePackMinor: servicePack.minor,
|
||||
installYear: getSysinfoProperty("installYear", null),
|
||||
#endif
|
||||
locale: getSystemLocale(),
|
||||
};
|
||||
|
||||
if (["gonk", "android"].indexOf(AppConstants.platform) !== -1) {
|
||||
data.kernelVersion = getSysinfoProperty("kernel_version", null);
|
||||
} else if (AppConstants.platform === "win") {
|
||||
let servicePack = getServicePack();
|
||||
data.servicePackMajor = servicePack.major;
|
||||
data.servicePackMinor = servicePack.minor;
|
||||
data.installYear = getSysinfoProperty("installYear", null);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1182,14 +1189,14 @@ EnvironmentCache.prototype = {
|
||||
features: {},
|
||||
};
|
||||
|
||||
#if !defined(MOZ_WIDGET_GONK) && !defined(MOZ_WIDGET_ANDROID) && !defined(MOZ_WIDGET_GTK)
|
||||
let gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
|
||||
try {
|
||||
gfxData.monitors = gfxInfo.getMonitors();
|
||||
} catch (e) {
|
||||
this._log.error("nsIGfxInfo.getMonitors() caught error", e);
|
||||
if (["gonk", "android", "linux"].indexOf(AppConstants.platform) === -1) {
|
||||
let gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
|
||||
try {
|
||||
gfxData.monitors = gfxInfo.getMonitors();
|
||||
} catch (e) {
|
||||
this._log.error("nsIGfxInfo.getMonitors() caught error", e);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
try {
|
||||
let gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
|
||||
@ -1236,20 +1243,22 @@ EnvironmentCache.prototype = {
|
||||
virtualMB = Math.round(virtualMB / 1024 / 1024);
|
||||
}
|
||||
|
||||
return {
|
||||
let data = {
|
||||
memoryMB: memoryMB,
|
||||
virtualMaxMB: virtualMB,
|
||||
#ifdef XP_WIN
|
||||
isWow64: getSysinfoProperty("isWow64", null),
|
||||
#endif
|
||||
cpu: this._getCpuData(),
|
||||
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
|
||||
device: this._getDeviceData(),
|
||||
#endif
|
||||
os: this._getOSData(),
|
||||
hdd: this._getHDDData(),
|
||||
gfx: this._getGFXData(),
|
||||
};
|
||||
|
||||
if (AppConstants.platform === "win") {
|
||||
data.isWow64 = getSysinfoProperty("isWow64", null);
|
||||
} else if (["gonk", "android"].indexOf(AppConstants.platform) !== -1) {
|
||||
data.device = this._getDeviceData();
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
_onEnvironmentChange: function (what, oldEnvironment) {
|
||||
|
@ -22,6 +22,7 @@ Cu.import("resource://gre/modules/Task.jsm");
|
||||
Cu.import("resource://gre/modules/Timer.jsm");
|
||||
Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
|
||||
Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
const Utils = TelemetryUtils;
|
||||
|
||||
@ -1305,12 +1306,13 @@ var Impl = {
|
||||
|
||||
getSessionPayload: function getSessionPayload(reason, clearSubsession) {
|
||||
this._log.trace("getSessionPayload - reason: " + reason + ", clearSubsession: " + clearSubsession);
|
||||
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
|
||||
clearSubsession = false;
|
||||
const isSubsession = false;
|
||||
#else
|
||||
const isSubsession = !this._isClassicReason(reason);
|
||||
#endif
|
||||
|
||||
const isMobile = ["gonk", "android"].indexOf(AppConstants.platform) !== -1;
|
||||
const isSubsession = isMobile ? false : !this._isClassicReason(reason);
|
||||
|
||||
if (isMobile) {
|
||||
clearSubsession = false;
|
||||
}
|
||||
|
||||
let measurements =
|
||||
this.getSimpleMeasurements(reason == REASON_SAVED_SESSION, isSubsession, clearSubsession);
|
||||
@ -1415,9 +1417,9 @@ var Impl = {
|
||||
() => this._getState());
|
||||
|
||||
Services.obs.addObserver(this, "sessionstore-windows-restored", false);
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
Services.obs.addObserver(this, "application-background", false);
|
||||
#endif
|
||||
if (AppConstants.platform === "android") {
|
||||
Services.obs.addObserver(this, "application-background", false);
|
||||
}
|
||||
Services.obs.addObserver(this, "xul-window-visible", false);
|
||||
this._hasWindowRestoredObserver = true;
|
||||
this._hasXulWindowVisibleObserver = true;
|
||||
@ -1627,9 +1629,9 @@ var Impl = {
|
||||
Services.obs.removeObserver(this, "xul-window-visible");
|
||||
this._hasXulWindowVisibleObserver = false;
|
||||
}
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
Services.obs.removeObserver(this, "application-background", false);
|
||||
#endif
|
||||
if (AppConstants.platform === "android") {
|
||||
Services.obs.removeObserver(this, "application-background", false);
|
||||
}
|
||||
},
|
||||
|
||||
getPayload: function getPayload(reason, clearSubsession) {
|
||||
@ -1730,23 +1732,25 @@ var Impl = {
|
||||
}).bind(this), Ci.nsIThread.DISPATCH_NORMAL);
|
||||
break;
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
// On Android, we can get killed without warning once we are in the background,
|
||||
// but we may also submit data and/or come back into the foreground without getting
|
||||
// killed. To deal with this, we save the current session data to file when we are
|
||||
// put into the background. This handles the following post-backgrounding scenarios:
|
||||
// 1) We are killed immediately. In this case the current session data (which we
|
||||
// save to a file) will be loaded and submitted on a future run.
|
||||
// 2) We submit the data while in the background, and then are killed. In this case
|
||||
// the file that we saved will be deleted by the usual process in
|
||||
// finishPingRequest after it is submitted.
|
||||
// 3) We submit the data, and then come back into the foreground. Same as case (2).
|
||||
// 4) We do not submit the data, but come back into the foreground. In this case
|
||||
// we have the option of either deleting the file that we saved (since we will either
|
||||
// send the live data while in the foreground, or create the file again on the next
|
||||
// backgrounding), or not (in which case we will delete it on submit, or overwrite
|
||||
// it on the next backgrounding). Not deleting it is faster, so that's what we do.
|
||||
case "application-background":
|
||||
if (AppConstants.platform !== "android") {
|
||||
break;
|
||||
}
|
||||
// On Android, we can get killed without warning once we are in the background,
|
||||
// but we may also submit data and/or come back into the foreground without getting
|
||||
// killed. To deal with this, we save the current session data to file when we are
|
||||
// put into the background. This handles the following post-backgrounding scenarios:
|
||||
// 1) We are killed immediately. In this case the current session data (which we
|
||||
// save to a file) will be loaded and submitted on a future run.
|
||||
// 2) We submit the data while in the background, and then are killed. In this case
|
||||
// the file that we saved will be deleted by the usual process in
|
||||
// finishPingRequest after it is submitted.
|
||||
// 3) We submit the data, and then come back into the foreground. Same as case (2).
|
||||
// 4) We do not submit the data, but come back into the foreground. In this case
|
||||
// we have the option of either deleting the file that we saved (since we will either
|
||||
// send the live data while in the foreground, or create the file again on the next
|
||||
// backgrounding), or not (in which case we will delete it on submit, or overwrite
|
||||
// it on the next backgrounding). Not deleting it is faster, so that's what we do.
|
||||
if (Telemetry.isOfficialTelemetry) {
|
||||
let payload = this.getSessionPayload(REASON_SAVED_SESSION, false);
|
||||
let options = {
|
||||
@ -1757,7 +1761,6 @@ var Impl = {
|
||||
TelemetryController.addPendingPing(getPingType(payload), payload, options);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user