Bug 1598223 - Replace netChange WEE with networkStatus API. r=mixedpuppy,maxxcrawford

Differential Revision: https://phabricator.services.mozilla.com/D54625

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nihanth Subramanya 2019-11-28 19:13:02 +00:00
Родитель a25e8fd518
Коммит 47813a6a87
5 изменённых файлов: 31 добавлений и 130 удалений

Просмотреть файл

@ -100,7 +100,7 @@ const stateManager = {
},
async rememberDoorhangerShown() {
// This will be shown on startup and netChange events until a user clicks
// This will be shown on startup and network changes until a user clicks
// to confirm/disable DoH or presses the esc key (confirming)
log("Remembering that doorhanger has been shown");
await rollout.setSetting(DOH_DOORHANGER_SHOWN_PREF, true);
@ -228,26 +228,6 @@ const rollout = {
await stateManager.rememberDoorhangerShown();
},
async netChangeListener() {
// Possible race condition between multiple notifications?
let curTime = new Date().getTime() / 1000;
let timePassed = curTime - this.lastNetworkChangeTime;
log("Time passed since last network change:", timePassed);
if (timePassed < 30) {
return;
}
this.lastNetworkChangeTime = curTime;
// Run heuristics to determine if DoH should be disabled
let decision = await rollout.heuristics("netChange");
if (decision === "disable_doh") {
await stateManager.setState("disabled");
} else {
await stateManager.setState("enabled");
}
},
async heuristics(evaluateReason) {
// Run heuristics defined in heuristics.js and experiments/heuristics/api.js
let results = await runHeuristics();
@ -478,25 +458,41 @@ const rollout = {
}
// Listen for network change events to run heuristics again
browser.experiments.netChange.onConnectionChanged.addListener(async () => {
browser.networkStatus.onConnectionChanged.addListener(async () => {
log("onConnectionChanged");
// Only run the heuristics if user hasn't explicitly enabled/disabled DoH
let shouldRunHeuristics = await stateManager.shouldRunHeuristics();
let shouldShowDoorhanger = await stateManager.shouldShowDoorhanger();
if (!shouldRunHeuristics) {
let linkInfo = await browser.networkStatus.getLinkInfo();
if (linkInfo.status !== "up") {
log("Link down.");
if (rollout.networkSettledTimeout) {
log("Canceling queued heuristics run.");
clearTimeout(rollout.networkSettledTimeout);
rollout.networkSettledTimeout = null;
}
return;
}
const netChangeDecision = await rollout.heuristics("netChange");
log("Queing a heuristics run in 60s, will cancel if network fluctuates.");
rollout.networkSettledTimeout = setTimeout(async () => {
log("No network fluctuation for 60 seconds, running heuristics.");
// Only run the heuristics if user hasn't explicitly enabled/disabled DoH
let shouldRunHeuristics = await stateManager.shouldRunHeuristics();
let shouldShowDoorhanger = await stateManager.shouldShowDoorhanger();
if (netChangeDecision === "disable_doh") {
await stateManager.setState("disabled");
} else if (shouldShowDoorhanger) {
await stateManager.showDoorHangerAndEnableDoH();
} else {
await stateManager.setState("enabled");
}
if (!shouldRunHeuristics) {
return;
}
const netChangeDecision = await rollout.heuristics("netChange");
if (netChangeDecision === "disable_doh") {
await stateManager.setState("disabled");
} else if (shouldShowDoorhanger) {
await stateManager.showDoorHangerAndEnableDoH();
} else {
await stateManager.setState("enabled");
}
}, 60000);
});
},

Просмотреть файл

@ -1,64 +0,0 @@
/* 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";
/* global Cc, Ci, ExtensionAPI, ExtensionCommon */
ChromeUtils.import("resource://gre/modules/Services.jsm", this);
const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm");
let gNetworkLinkService = Cc[
"@mozilla.org/network/network-link-service;1"
].getService(Ci.nsINetworkLinkService);
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let netChangeWaiting = false;
this.netChange = class netChange extends ExtensionAPI {
getAPI(context) {
return {
experiments: {
netChange: {
onConnectionChanged: new ExtensionCommon.EventManager({
context,
name: "netChange.onConnectionChanged",
register: fire => {
let observer = async (subject, topic, data) => {
if (netChangeWaiting) {
return;
}
if (data === "changed" || data === "up") {
// Trigger the netChangeWaiting switch, initiating 5sec timeout
netChangeWaiting = true;
await sleep(60000);
if (
gNetworkLinkService.linkStatusKnown &&
gNetworkLinkService.isLinkUp
) {
fire.async(data);
}
// Reset the netChangeWaiting switch
netChangeWaiting = false;
}
};
Services.obs.addObserver(observer, "network:link-status-changed");
return () => {
Services.obs.removeObserver(
observer,
"network:link-status-changed"
);
};
},
}).api(),
},
},
};
}
};

Просмотреть файл

@ -1,19 +0,0 @@
[
{
"namespace": "experiments.netChange",
"events": [
{
"name": "onConnectionChanged",
"type": "function",
"description": "Fired when the user has changed networks",
"parameters": [
{
"type": "boolean",
"name": "connectivity",
"description": "True if we have network connectivity, false otherwise"
}
]
}
]
}
]

Просмотреть файл

@ -16,6 +16,7 @@
"permissions": [
"captivePortal",
"dns",
"networkStatus",
"storage"
],
@ -40,14 +41,6 @@
"paths": [["experiments", "heuristics"]]
}
},
"netChange": {
"schema": "experiments/netChange/schema.json",
"parent": {
"scopes": ["addon_parent"],
"script": "experiments/netChange/api.js",
"paths": [["experiments", "netChange"]]
}
},
"doorhanger": {
"schema": "experiments/doorhanger/schema.json",
"parent": {

Просмотреть файл

@ -24,11 +24,6 @@ FINAL_TARGET_FILES.features['doh-rollout@mozilla.org']["experiments"]["heuristic
'experiments/heuristics/schema.json'
]
FINAL_TARGET_FILES.features['doh-rollout@mozilla.org']["experiments"]["netChange"] += [
'experiments/netChange/api.js',
'experiments/netChange/schema.json'
]
FINAL_TARGET_FILES.features['doh-rollout@mozilla.org']["experiments"]["preferences"] += [
'experiments/preferences/api.js',
'experiments/preferences/schema.json'