mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-05 15:59:45 +00:00
Bug 721165 - Extract repeated code for retrieving CHANNEL information from Blocklist and Telemetry to a javascript module r=gavin
This commit is contained in:
parent
340e310a98
commit
2267136e3c
@ -82,6 +82,8 @@ XPCOMUtils.defineLazyServiceGetter(this, "Telemetry",
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "idleService",
|
||||
"@mozilla.org/widget/idleservice;1",
|
||||
"nsIIdleService");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "UpdateChannel",
|
||||
"resource://gre/modules/UpdateChannel.jsm");
|
||||
|
||||
function generateUUID() {
|
||||
let str = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID().toString();
|
||||
@ -143,42 +145,6 @@ function getSimpleMeasurements() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the update channel from defaults only. We do this to ensure that
|
||||
* the channel is tightly coupled with the application and does not apply
|
||||
* to other installations of the application that may use the same profile.
|
||||
*/
|
||||
function getUpdateChannel() {
|
||||
var channel = "default";
|
||||
var prefName;
|
||||
var prefValue;
|
||||
|
||||
var defaults = Services.prefs.getDefaultBranch(null);
|
||||
try {
|
||||
channel = defaults.getCharPref("app.update.channel");
|
||||
} catch (e) {
|
||||
// use default when pref not found
|
||||
}
|
||||
|
||||
try {
|
||||
var partners = Services.prefs.getChildList("app.partner.");
|
||||
if (partners.length) {
|
||||
channel += "-cck";
|
||||
partners.sort();
|
||||
|
||||
for each (prefName in partners) {
|
||||
prefValue = Services.prefs.getCharPref(prefName);
|
||||
channel += "-" + prefValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
Cu.reportError(e);
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read current process I/O counters.
|
||||
*/
|
||||
@ -359,7 +325,7 @@ TelemetryPing.prototype = {
|
||||
appVersion: ai.version,
|
||||
appName: ai.name,
|
||||
appBuildID: ai.appBuildID,
|
||||
appUpdateChannel: getUpdateChannel(),
|
||||
appUpdateChannel: UpdateChannel.get(),
|
||||
platformBuildID: ai.platformBuildID,
|
||||
locale: getLocale()
|
||||
};
|
||||
|
@ -20,11 +20,12 @@ const Cu = Components.utils;
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const PREF_APP_UPDATE_CHANNEL = "app.update.channel";
|
||||
const PREF_PARTNER_BRANCH = "app.partner.";
|
||||
const PREF_APP_DISTRIBUTION = "distribution.id";
|
||||
const PREF_APP_DISTRIBUTION_VERSION = "distribution.version";
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "UpdateChannel",
|
||||
"resource://gre/modules/UpdateChannel.jsm");
|
||||
|
||||
function nsURLFormatterService() {
|
||||
XPCOMUtils.defineLazyGetter(this, "appInfo", function UFS_appInfo() {
|
||||
return Cc["@mozilla.org/xre/app-info;1"].
|
||||
@ -62,29 +63,6 @@ function nsURLFormatterService() {
|
||||
return encodeURIComponent(OSVersion);
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "updateChannel", function UFS_updateChannel() {
|
||||
// Read the update channel from defaults only. We do this to ensure that
|
||||
// the channel is tightly coupled with the application and does not apply
|
||||
// to other instances of the application that may use the same profile.
|
||||
let channel = "default";
|
||||
let defaults = Services.prefs.getDefaultBranch(null);
|
||||
try {
|
||||
channel = defaults.getCharPref(PREF_APP_UPDATE_CHANNEL);
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
let partners = Services.prefs.getChildList(PREF_PARTNER_BRANCH).sort();
|
||||
if (partners.length) {
|
||||
channel += "-cck";
|
||||
partners.forEach(function (prefName) {
|
||||
channel += "-" + Services.prefs.getCharPref(prefName);
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
return channel;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "distribution", function UFS_distribution() {
|
||||
let distribution = { id: "default", version: "default" };
|
||||
|
||||
@ -120,7 +98,7 @@ nsURLFormatterService.prototype = {
|
||||
XPCOMABI: function() this.ABI,
|
||||
BUILD_TARGET: function() this.appInfo.OS + "_" + this.ABI,
|
||||
OS_VERSION: function() this.OSVersion,
|
||||
CHANNEL: function() this.updateChannel,
|
||||
CHANNEL: function() UpdateChannel.get(),
|
||||
DISTRIBUTION: function() this.distribution.id,
|
||||
DISTRIBUTION_VERSION: function() this.distribution.version
|
||||
},
|
||||
|
@ -67,6 +67,7 @@ EXTRA_JS_MODULES = \
|
||||
PrivateBrowsingUtils.jsm \
|
||||
PropertyListUtils.jsm \
|
||||
Task.jsm \
|
||||
UpdateChannel.jsm \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_PP_JS_MODULES = \
|
||||
|
40
toolkit/content/UpdateChannel.jsm
Normal file
40
toolkit/content/UpdateChannel.jsm
Normal file
@ -0,0 +1,40 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const EXPORTED_SYMBOLS = ["UpdateChannel"];
|
||||
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
let UpdateChannel = {
|
||||
/**
|
||||
* Read the update channel from defaults only. We do this to ensure that
|
||||
* the channel is tightly coupled with the application and does not apply
|
||||
* to other instances of the application that may use the same profile.
|
||||
*/
|
||||
get: function UpdateChannel_get() {
|
||||
let channel = "default";
|
||||
let defaults = Services.prefs.getDefaultBranch(null);
|
||||
try {
|
||||
channel = defaults.getCharPref("app.update.channel");
|
||||
} catch (e) {
|
||||
// use default when pref not found
|
||||
}
|
||||
|
||||
try {
|
||||
let partners = Services.prefs.getChildList("app.partner.").sort();
|
||||
if (partners.length) {
|
||||
channel += "-cck";
|
||||
partners.forEach(function (prefName) {
|
||||
channel += "-" + Services.prefs.getCharPref(prefName);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
Cu.reportError(e);
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
};
|
@ -16,6 +16,8 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
||||
"resource://gre/modules/FileUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "UpdateChannel",
|
||||
"resource://gre/modules/UpdateChannel.jsm");
|
||||
|
||||
const TOOLKIT_ID = "toolkit@mozilla.org"
|
||||
const KEY_PROFILEDIR = "ProfD";
|
||||
@ -31,10 +33,8 @@ const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal";
|
||||
const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
|
||||
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
||||
const PREF_GENERAL_USERAGENT_LOCALE = "general.useragent.locale";
|
||||
const PREF_PARTNER_BRANCH = "app.partner.";
|
||||
const PREF_APP_DISTRIBUTION = "distribution.id";
|
||||
const PREF_APP_DISTRIBUTION_VERSION = "distribution.version";
|
||||
const PREF_APP_UPDATE_CHANNEL = "app.update.channel";
|
||||
const PREF_EM_LOGGING_ENABLED = "extensions.logging.enabled";
|
||||
const XMLURI_BLOCKLIST = "http://www.mozilla.org/2006/addons-blocklist";
|
||||
const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml"
|
||||
@ -225,42 +225,6 @@ function getLocale() {
|
||||
return gPref.getCharPref(PREF_GENERAL_USERAGENT_LOCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the update channel from defaults only. We do this to ensure that
|
||||
* the channel is tightly coupled with the application and does not apply
|
||||
* to other installations of the application that may use the same profile.
|
||||
*/
|
||||
function getUpdateChannel() {
|
||||
var channel = "default";
|
||||
var prefName;
|
||||
var prefValue;
|
||||
|
||||
var defaults = gPref.getDefaultBranch(null);
|
||||
try {
|
||||
channel = defaults.getCharPref(PREF_APP_UPDATE_CHANNEL);
|
||||
} catch (e) {
|
||||
// use default when pref not found
|
||||
}
|
||||
|
||||
try {
|
||||
var partners = gPref.getChildList(PREF_PARTNER_BRANCH);
|
||||
if (partners.length) {
|
||||
channel += "-cck";
|
||||
partners.sort();
|
||||
|
||||
for each (prefName in partners) {
|
||||
prefValue = gPref.getCharPref(prefName);
|
||||
channel += "-" + prefValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
Components.utils.reportError(e);
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
/* Get the distribution pref values, from defaults only */
|
||||
function getDistributionPrefValue(aPrefName) {
|
||||
var prefValue = "default";
|
||||
@ -461,7 +425,7 @@ Blocklist.prototype = {
|
||||
dsURI = dsURI.replace(/%BUILD_TARGET%/g, gApp.OS + "_" + gABI);
|
||||
dsURI = dsURI.replace(/%OS_VERSION%/g, gOSVersion);
|
||||
dsURI = dsURI.replace(/%LOCALE%/g, getLocale());
|
||||
dsURI = dsURI.replace(/%CHANNEL%/g, getUpdateChannel());
|
||||
dsURI = dsURI.replace(/%CHANNEL%/g, UpdateChannel.get());
|
||||
dsURI = dsURI.replace(/%PLATFORM_VERSION%/g, gApp.platformVersion);
|
||||
dsURI = dsURI.replace(/%DISTRIBUTION%/g,
|
||||
getDistributionPrefValue(PREF_APP_DISTRIBUTION));
|
||||
|
@ -30,7 +30,6 @@ const PREF_APP_UPDATE_CERT_CHECKATTRS = "app.update.cert.checkAttributes";
|
||||
const PREF_APP_UPDATE_CERT_ERRORS = "app.update.cert.errors";
|
||||
const PREF_APP_UPDATE_CERT_MAXERRORS = "app.update.cert.maxErrors";
|
||||
const PREF_APP_UPDATE_CERT_REQUIREBUILTIN = "app.update.cert.requireBuiltIn";
|
||||
const PREF_APP_UPDATE_CHANNEL = "app.update.channel";
|
||||
const PREF_APP_UPDATE_ENABLED = "app.update.enabled";
|
||||
const PREF_APP_UPDATE_IDLETIME = "app.update.idletime";
|
||||
const PREF_APP_UPDATE_INCOMPATIBLE_MODE = "app.update.incompatible.mode";
|
||||
@ -50,7 +49,6 @@ const PREF_APP_UPDATE_SERVICE_ENABLED = "app.update.service.enabled";
|
||||
const PREF_APP_UPDATE_SERVICE_ERRORS = "app.update.service.errors";
|
||||
const PREF_APP_UPDATE_SERVICE_MAX_ERRORS = "app.update.service.maxErrors";
|
||||
|
||||
const PREF_PARTNER_BRANCH = "app.partner.";
|
||||
const PREF_APP_DISTRIBUTION = "distribution.id";
|
||||
const PREF_APP_DISTRIBUTION_VERSION = "distribution.version";
|
||||
|
||||
@ -160,6 +158,9 @@ const DEFAULT_SERVICE_MAX_ERRORS = 10;
|
||||
|
||||
var gLocale = null;
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "UpdateChannel",
|
||||
"resource://gre/modules/UpdateChannel.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gLogEnabled", function aus_gLogEnabled() {
|
||||
return getPref("getBoolPref", PREF_APP_UPDATE_LOG, false);
|
||||
});
|
||||
@ -873,44 +874,6 @@ function getLocale() {
|
||||
return gLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the update channel from defaults only. We do this to ensure that
|
||||
* the channel is tightly coupled with the application and does not apply
|
||||
* to other instances of the application that may use the same profile.
|
||||
*/
|
||||
function getUpdateChannel() {
|
||||
// Preprocess the channel name that is defined when building to allow updating
|
||||
// even when the preference file that defines the channel name doesn't exist.
|
||||
var channel = "@MOZ_UPDATE_CHANNEL@";
|
||||
var prefName;
|
||||
var prefValue;
|
||||
|
||||
try {
|
||||
channel = Services.prefs.getDefaultBranch(null).
|
||||
getCharPref(PREF_APP_UPDATE_CHANNEL);
|
||||
} catch (e) {
|
||||
// Use the channel name from above that was preprocessed when building.
|
||||
}
|
||||
|
||||
try {
|
||||
var partners = Services.prefs.getChildList(PREF_PARTNER_BRANCH);
|
||||
if (partners.length) {
|
||||
channel += "-cck";
|
||||
partners.sort();
|
||||
|
||||
for each (prefName in partners) {
|
||||
prefValue = Services.prefs.getCharPref(prefName);
|
||||
channel += "-" + prefValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
Components.utils.reportError(e);
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
/* Get the distribution pref values, from defaults only */
|
||||
function getDistributionPrefValue(aPrefName) {
|
||||
var prefValue = "default";
|
||||
@ -2450,7 +2413,7 @@ UpdateManager.prototype = {
|
||||
*/
|
||||
get activeUpdate() {
|
||||
if (this._activeUpdate &&
|
||||
this._activeUpdate.channel != getUpdateChannel()) {
|
||||
this._activeUpdate.channel != UpdateChannel.get()) {
|
||||
// User switched channels, clear out any old active updates and remove
|
||||
// partial downloads
|
||||
this._activeUpdate = null;
|
||||
@ -2661,7 +2624,7 @@ Checker.prototype = {
|
||||
url = url.replace(/%OS_VERSION%/g, gOSVersion);
|
||||
if (/%LOCALE%/.test(url))
|
||||
url = url.replace(/%LOCALE%/g, getLocale());
|
||||
url = url.replace(/%CHANNEL%/g, getUpdateChannel());
|
||||
url = url.replace(/%CHANNEL%/g, UpdateChannel.get());
|
||||
url = url.replace(/%PLATFORM_VERSION%/g, Services.appinfo.platformVersion);
|
||||
url = url.replace(/%DISTRIBUTION%/g,
|
||||
getDistributionPrefValue(PREF_APP_DISTRIBUTION));
|
||||
@ -2754,7 +2717,7 @@ Checker.prototype = {
|
||||
continue;
|
||||
}
|
||||
update.serviceURL = this.getUpdateURL(this._forced);
|
||||
update.channel = getUpdateChannel();
|
||||
update.channel = UpdateChannel.get();
|
||||
updates.push(update);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user