mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 05:08:36 +02:00
This is a rollup of all the patches that have landed on the cedar project branch:891252fdd0Bug 1492475 - Part 1: Migrate most, if not all nsSearchService consumers to use async APIs. r=florian79b2eb2367Bug 1492475 - Part 2: Move nsIBrowserSearchService.idl to toolkit/components/search/nsISearchService.idl and update references. r=floriana947d3cdf0Bug 1492475 - Part 3: The search service init() method should simply return a Promise. r=florianc1e172dfacBug 1492475 - Part 4: Remove the synchronous initialization flow. r=floriancd41189eacBug 1492475 - Part 5: Since async initialization of the search service now is implicit behavior, remove the distinctive verbiage used internally. r=florian2ae7189dfaBug 1492475 - Part 6: Update the cache build task to work with an actual Promise and re-initialize only once at the same time - all to fix race conditions here. r=florianc8ee92973fBug 1492475 - Part 7: Make the region fetch not block the init flow, to ensure it's as fast as possible. r=florianc44e674e16Bug 1492475 - Part 8: Introduce an init flag, which can only be used privately, that allows to explicitly skip waiting for the region check process to complete. r=florian6c79eaf1d3Bug 1492475 - Part 9: Update unit tests to stop using 'currentEngine', in favor of 'defaultEngine'. r=Standard821b3aa17eeBug 1492475 - Part 10: Update unit tests to be fully aware of the new, async signatures of the search service API and remove sync init flow tests. r=mkaply,floriance5ba69019Bug 1492475 - Part 11: Repair incorrect usage of the `identifier` property of nsISearchEngine instances. r=florianfd177a7994Bug 1518543 - Fix up the Android (Fennec) nsISearchService shim to work with the new asynchronous API. r=florian3653d8ee22Bug 1523708 - Change the search service interaction in the show-heartbeat action to use the new async API. r=florian Differential Revision: https://phabricator.services.mozilla.com/D18355 --HG-- rename : netwerk/base/nsIBrowserSearchService.idl => toolkit/components/search/nsISearchService.idl extra : moz-landing-system : lando
164 lines
5.3 KiB
JavaScript
164 lines
5.3 KiB
JavaScript
/* 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/. */
|
|
|
|
"use strict";
|
|
|
|
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "ShellService", "resource:///modules/ShellService.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "TelemetryArchive", "resource://gre/modules/TelemetryArchive.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "TelemetryEnvironment", "resource://gre/modules/TelemetryEnvironment.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "UpdateUtils", "resource://gre/modules/UpdateUtils.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "AppConstants", "resource://gre/modules/AppConstants.jsm");
|
|
|
|
var EXPORTED_SYMBOLS = ["ClientEnvironmentBase"];
|
|
|
|
|
|
/**
|
|
* Create an object that provides general information about the client application.
|
|
*
|
|
* Components like Normandy RecipeRunner use this as part of the context for filter expressions,
|
|
* so avoid adding non-getter functions as attributes, as filter expressions
|
|
* cannot execute functions.
|
|
*
|
|
* Also note that, because filter expressions implicitly resolve promises, you
|
|
* can add getter functions that return promises for async data.
|
|
*/
|
|
class ClientEnvironmentBase {
|
|
static get distribution() {
|
|
return Services.prefs.getCharPref("distribution.id", "default");
|
|
}
|
|
|
|
static get telemetry() {
|
|
return (async () => {
|
|
const pings = await TelemetryArchive.promiseArchivedPingList();
|
|
|
|
// get most recent ping per type
|
|
const mostRecentPings = {};
|
|
for (const ping of pings) {
|
|
if (ping.type in mostRecentPings) {
|
|
if (mostRecentPings[ping.type].timestampCreated < ping.timestampCreated) {
|
|
mostRecentPings[ping.type] = ping;
|
|
}
|
|
} else {
|
|
mostRecentPings[ping.type] = ping;
|
|
}
|
|
}
|
|
|
|
const telemetry = {};
|
|
for (const key in mostRecentPings) {
|
|
const ping = mostRecentPings[key];
|
|
telemetry[ping.type] = await TelemetryArchive.promiseArchivedPingById(ping.id);
|
|
}
|
|
return telemetry;
|
|
})();
|
|
}
|
|
|
|
static get version() {
|
|
return AppConstants.MOZ_APP_VERSION_DISPLAY;
|
|
}
|
|
|
|
static get channel() {
|
|
return UpdateUtils.getUpdateChannel(false);
|
|
}
|
|
|
|
static get isDefaultBrowser() {
|
|
return ShellService.isDefaultBrowser();
|
|
}
|
|
|
|
static get searchEngine() {
|
|
return (async () => {
|
|
await TelemetryEnvironment.onInitialized();
|
|
return TelemetryEnvironment.currentEnvironment.settings.defaultSearchEngine;
|
|
})();
|
|
}
|
|
|
|
static get syncSetup() {
|
|
return Services.prefs.prefHasUserValue("services.sync.username");
|
|
}
|
|
|
|
static get syncDesktopDevices() {
|
|
return Services.prefs.getIntPref("services.sync.clients.devices.desktop", 0);
|
|
}
|
|
|
|
static get syncMobileDevices() {
|
|
return Services.prefs.getIntPref("services.sync.clients.devices.mobile", 0);
|
|
}
|
|
|
|
static get syncTotalDevices() {
|
|
return this.syncDesktopDevices + this.syncMobileDevices;
|
|
}
|
|
|
|
static get addons() {
|
|
return (async () => {
|
|
const addons = await AddonManager.getAllAddons();
|
|
return addons.reduce((acc, addon) => {
|
|
const { id, isActive, name, type, version, installDate: installDateN } = addon;
|
|
const installDate = new Date(installDateN);
|
|
acc[id] = { id, isActive, name, type, version, installDate };
|
|
return acc;
|
|
}, {});
|
|
})();
|
|
}
|
|
|
|
static get plugins() {
|
|
return (async () => {
|
|
const plugins = await AddonManager.getAddonsByTypes(["plugin"]);
|
|
return plugins.reduce((acc, plugin) => {
|
|
const { name, description, version } = plugin;
|
|
acc[name] = { name, description, version };
|
|
return acc;
|
|
}, {});
|
|
})();
|
|
}
|
|
|
|
static get locale() {
|
|
return Services.locale.appLocaleAsLangTag;
|
|
}
|
|
|
|
static get doNotTrack() {
|
|
return Services.prefs.getBoolPref("privacy.donottrackheader.enabled", false);
|
|
}
|
|
|
|
static get os() {
|
|
function coerceToNumber(version) {
|
|
const parts = version.split(".");
|
|
return parseFloat(parts.slice(0, 2).join("."));
|
|
}
|
|
|
|
return (async () => {
|
|
await TelemetryEnvironment.onInitialized();
|
|
|
|
const { system } = TelemetryEnvironment.currentEnvironment;
|
|
const rv = {
|
|
isWindows: AppConstants.platform === "win",
|
|
isMac: AppConstants.platform === "macosx",
|
|
isLinux: AppConstants.platform === "linux",
|
|
windowsVersion: null,
|
|
windowsBuildNumber: null,
|
|
macVersion: null,
|
|
darwinVersion: null,
|
|
};
|
|
|
|
if (rv.isWindows) {
|
|
rv.windowsVersion = coerceToNumber(system.os.version);
|
|
rv.windowsBuildNumber = system.os.windowsBuildNumber;
|
|
} else if (rv.isMac) {
|
|
rv.darwinVersion = coerceToNumber(system.os.version);
|
|
// Versions of OSX with Darwin < 5 don't follow this pattern
|
|
if (rv.darwinVersion >= 5) {
|
|
// OSX 10.1 used Darwin 5, OSX 10.2 used Darwin 6, and so on.
|
|
const intPart = Math.floor(rv.darwinVersion);
|
|
rv.macVersion = 10 + 0.1 * (intPart - 4);
|
|
}
|
|
}
|
|
|
|
// Version information on linux is a lot harder and a lot less useful, so
|
|
// don't do anything about it here.
|
|
|
|
return rv;
|
|
})();
|
|
}
|
|
}
|