mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1234502 - Remove FHR SyncProvider. r=gps
This commit is contained in:
parent
a69e8b30b8
commit
d796b64d22
@ -23,7 +23,3 @@ contract @mozilla.org/network/protocol/about;1?what=sync-log {d28f8a0b-95da-48f4
|
||||
# Register resource aliases
|
||||
# (Note, for tests these are also set up in addResourceAlias)
|
||||
resource services-sync resource://gre/modules/services-sync/
|
||||
|
||||
#ifdef MOZ_SERVICES_HEALTHREPORT
|
||||
category healthreport-js-provider-default SyncProvider resource://services-sync/healthreport.jsm
|
||||
#endif
|
||||
|
@ -1,194 +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";
|
||||
|
||||
this.EXPORTED_SYMBOLS = [
|
||||
"SyncProvider",
|
||||
];
|
||||
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Metrics.jsm", this);
|
||||
Cu.import("resource://gre/modules/Promise.jsm", this);
|
||||
Cu.import("resource://gre/modules/Services.jsm", this);
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
|
||||
|
||||
const DAILY_LAST_NUMERIC_FIELD = {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC};
|
||||
const DAILY_LAST_TEXT_FIELD = {type: Metrics.Storage.FIELD_DAILY_LAST_TEXT};
|
||||
const DAILY_COUNTER_FIELD = {type: Metrics.Storage.FIELD_DAILY_COUNTER};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Weave",
|
||||
"resource://services-sync/main.js");
|
||||
|
||||
function SyncMeasurement1() {
|
||||
Metrics.Measurement.call(this);
|
||||
}
|
||||
|
||||
SyncMeasurement1.prototype = Object.freeze({
|
||||
__proto__: Metrics.Measurement.prototype,
|
||||
|
||||
name: "sync",
|
||||
version: 1,
|
||||
|
||||
fields: {
|
||||
enabled: DAILY_LAST_NUMERIC_FIELD,
|
||||
preferredProtocol: DAILY_LAST_TEXT_FIELD,
|
||||
activeProtocol: DAILY_LAST_TEXT_FIELD,
|
||||
syncStart: DAILY_COUNTER_FIELD,
|
||||
syncSuccess: DAILY_COUNTER_FIELD,
|
||||
syncError: DAILY_COUNTER_FIELD,
|
||||
},
|
||||
});
|
||||
|
||||
function SyncDevicesMeasurement1() {
|
||||
Metrics.Measurement.call(this);
|
||||
}
|
||||
|
||||
SyncDevicesMeasurement1.prototype = Object.freeze({
|
||||
__proto__: Metrics.Measurement.prototype,
|
||||
|
||||
name: "devices",
|
||||
version: 1,
|
||||
|
||||
fields: {},
|
||||
|
||||
shouldIncludeField: function (name) {
|
||||
return true;
|
||||
},
|
||||
|
||||
fieldType: function (name) {
|
||||
return Metrics.Storage.FIELD_DAILY_COUNTER;
|
||||
},
|
||||
});
|
||||
|
||||
this.SyncProvider = function () {
|
||||
Metrics.Provider.call(this);
|
||||
};
|
||||
SyncProvider.prototype = Object.freeze({
|
||||
__proto__: Metrics.Provider.prototype,
|
||||
|
||||
name: "org.mozilla.sync",
|
||||
|
||||
measurementTypes: [
|
||||
SyncDevicesMeasurement1,
|
||||
SyncMeasurement1,
|
||||
],
|
||||
|
||||
_OBSERVERS: [
|
||||
"weave:service:sync:start",
|
||||
"weave:service:sync:finish",
|
||||
"weave:service:sync:error",
|
||||
],
|
||||
|
||||
postInit: function () {
|
||||
for (let o of this._OBSERVERS) {
|
||||
Services.obs.addObserver(this, o, false);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
onShutdown: function () {
|
||||
for (let o of this._OBSERVERS) {
|
||||
Services.obs.removeObserver(this, o);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
observe: function (subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "weave:service:sync:start":
|
||||
case "weave:service:sync:finish":
|
||||
case "weave:service:sync:error":
|
||||
return this._observeSync(subject, topic, data);
|
||||
}
|
||||
Cu.reportError("unexpected topic in sync healthreport provider: " + topic);
|
||||
},
|
||||
|
||||
_observeSync: function (subject, topic, data) {
|
||||
let field;
|
||||
switch (topic) {
|
||||
case "weave:service:sync:start":
|
||||
field = "syncStart";
|
||||
break;
|
||||
|
||||
case "weave:service:sync:finish":
|
||||
field = "syncSuccess";
|
||||
break;
|
||||
|
||||
case "weave:service:sync:error":
|
||||
field = "syncError";
|
||||
break;
|
||||
|
||||
default:
|
||||
Cu.reportError("unexpected sync topic in sync healthreport provider: " + topic);
|
||||
return;
|
||||
}
|
||||
|
||||
let m = this.getMeasurement(SyncMeasurement1.prototype.name,
|
||||
SyncMeasurement1.prototype.version);
|
||||
return this.enqueueStorageOperation(function recordSyncEvent() {
|
||||
return m.incrementDailyCounter(field);
|
||||
});
|
||||
},
|
||||
|
||||
collectDailyData: function () {
|
||||
return this.storage.enqueueTransaction(this._populateDailyData.bind(this));
|
||||
},
|
||||
|
||||
_populateDailyData: function* () {
|
||||
let m = this.getMeasurement(SyncMeasurement1.prototype.name,
|
||||
SyncMeasurement1.prototype.version);
|
||||
|
||||
let svc = Cc["@mozilla.org/weave/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject;
|
||||
|
||||
let enabled = svc.enabled;
|
||||
yield m.setDailyLastNumeric("enabled", enabled ? 1 : 0);
|
||||
|
||||
// preferredProtocol is constant and only changes as the client
|
||||
// evolves.
|
||||
yield m.setDailyLastText("preferredProtocol", "1.5");
|
||||
|
||||
let protocol = svc.fxAccountsEnabled ? "1.5" : "1.1";
|
||||
yield m.setDailyLastText("activeProtocol", protocol);
|
||||
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Before grabbing more information, be sure the Sync service
|
||||
// is fully initialized. This has the potential to initialize
|
||||
// Sync on the spot. This may be undesired if Sync appears to
|
||||
// be enabled but it really isn't. That responsibility should
|
||||
// be up to svc.enabled to not return false positives, however.
|
||||
yield svc.whenLoaded();
|
||||
|
||||
if (Weave.Status.service != Weave.STATUS_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Device types are dynamic. So we need to dynamically create fields if
|
||||
// they don't exist.
|
||||
let dm = this.getMeasurement(SyncDevicesMeasurement1.prototype.name,
|
||||
SyncDevicesMeasurement1.prototype.version);
|
||||
let devices = Weave.Service.clientsEngine.deviceTypes;
|
||||
for (let [field, count] of devices) {
|
||||
let hasField = this.storage.hasFieldFromMeasurement(dm.id, field,
|
||||
this.storage.FIELD_DAILY_LAST_NUMERIC);
|
||||
let fieldID;
|
||||
if (hasField) {
|
||||
fieldID = this.storage.fieldIDFromMeasurement(dm.id, field);
|
||||
} else {
|
||||
fieldID = yield this.storage.registerField(dm.id, field,
|
||||
this.storage.FIELD_DAILY_LAST_NUMERIC);
|
||||
}
|
||||
|
||||
yield this.storage.setDailyLastNumericFromFieldID(fieldID, count);
|
||||
}
|
||||
},
|
||||
});
|
@ -12,11 +12,8 @@ DIRS += ['locales']
|
||||
XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
|
||||
|
||||
EXTRA_COMPONENTS += [
|
||||
'Weave.js',
|
||||
]
|
||||
|
||||
EXTRA_PP_COMPONENTS += [
|
||||
'SyncComponents.manifest',
|
||||
'Weave.js',
|
||||
]
|
||||
|
||||
EXTRA_JS_MODULES['services-sync'] += [
|
||||
@ -25,7 +22,6 @@ EXTRA_JS_MODULES['services-sync'] += [
|
||||
'modules/browserid_identity.js',
|
||||
'modules/engines.js',
|
||||
'modules/FxaMigrator.jsm',
|
||||
'modules/healthreport.jsm',
|
||||
'modules/identity.js',
|
||||
'modules/jpakeclient.js',
|
||||
'modules/keys.js',
|
||||
|
@ -1,194 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
Cu.import("resource://gre/modules/Metrics.jsm", this);
|
||||
Cu.import("resource://gre/modules/Preferences.jsm", this);
|
||||
Cu.import("resource://gre/modules/Promise.jsm", this);
|
||||
Cu.import("resource://services-sync/main.js", this);
|
||||
Cu.import("resource://services-sync/healthreport.jsm", this);
|
||||
Cu.import("resource://testing-common/services/common/logging.js", this);
|
||||
Cu.import("resource://testing-common/services/healthreport/utils.jsm", this);
|
||||
|
||||
function run_test() {
|
||||
initTestLogging();
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function test_constructor() {
|
||||
let provider = new SyncProvider();
|
||||
});
|
||||
|
||||
// Provider can initialize and de-initialize properly.
|
||||
add_task(function* test_init() {
|
||||
let storage = yield Metrics.Storage("init");
|
||||
let provider = new SyncProvider();
|
||||
yield provider.init(storage);
|
||||
yield provider.shutdown();
|
||||
yield storage.close();
|
||||
});
|
||||
|
||||
add_task(function* test_collect() {
|
||||
let storage = yield Metrics.Storage("collect");
|
||||
let provider = new SyncProvider();
|
||||
yield provider.init(storage);
|
||||
|
||||
// Initially nothing should be configured.
|
||||
let now = new Date();
|
||||
yield provider.collectDailyData();
|
||||
|
||||
let m = provider.getMeasurement("sync", 1);
|
||||
let values = yield m.getValues();
|
||||
Assert.equal(values.days.size, 1);
|
||||
Assert.ok(values.days.hasDay(now));
|
||||
let day = values.days.getDay(now);
|
||||
Assert.ok(day.has("enabled"));
|
||||
Assert.ok(day.has("activeProtocol"));
|
||||
Assert.ok(day.has("preferredProtocol"));
|
||||
Assert.equal(day.get("enabled"), 0);
|
||||
Assert.equal(day.get("preferredProtocol"), "1.5");
|
||||
Assert.equal(day.get("activeProtocol"), "1.5",
|
||||
"Protocol without setup should be FX Accounts version.");
|
||||
|
||||
// Now check for old Sync setup.
|
||||
let branch = new Preferences("services.sync.");
|
||||
branch.set("username", "foo");
|
||||
branch.reset("fxaccounts.enabled");
|
||||
yield provider.collectDailyData();
|
||||
values = yield m.getValues();
|
||||
Assert.equal(values.days.getDay(now).get("activeProtocol"), "1.1",
|
||||
"Protocol with old Sync setup is correct.");
|
||||
|
||||
Assert.equal(Weave.Status.__authManager, undefined, "Detect code changes");
|
||||
|
||||
// Let's enable Sync so we can get more useful data.
|
||||
// We need to do this because the FHR probe only records more info if Sync
|
||||
// is configured properly.
|
||||
Weave.Service.identity.account = "johndoe";
|
||||
Weave.Service.identity.basicPassword = "ilovejane";
|
||||
Weave.Service.identity.syncKey = Weave.Utils.generatePassphrase();
|
||||
Weave.Service.clusterURL = "http://localhost/";
|
||||
Assert.equal(Weave.Status.checkSetup(), Weave.STATUS_OK);
|
||||
|
||||
yield provider.collectDailyData();
|
||||
values = yield m.getValues();
|
||||
day = values.days.getDay(now);
|
||||
Assert.equal(day.get("enabled"), 1);
|
||||
|
||||
// An empty account should have 1 device: us.
|
||||
let dm = provider.getMeasurement("devices", 1);
|
||||
values = yield dm.getValues();
|
||||
Assert.ok(values.days.hasDay(now));
|
||||
day = values.days.getDay(now);
|
||||
Assert.equal(day.size, 1);
|
||||
let engine = Weave.Service.clientsEngine;
|
||||
Assert.ok(engine);
|
||||
Assert.ok(day.has(engine.localType));
|
||||
Assert.equal(day.get(engine.localType), 1);
|
||||
|
||||
// Add some devices and ensure they show up.
|
||||
engine._store._remoteClients["id1"] = {type: "mobile"};
|
||||
engine._store._remoteClients["id2"] = {type: "tablet"};
|
||||
engine._store._remoteClients["id3"] = {type: "mobile"};
|
||||
|
||||
yield provider.collectDailyData();
|
||||
values = yield dm.getValues();
|
||||
day = values.days.getDay(now);
|
||||
|
||||
let expected = {
|
||||
"foobar": 0,
|
||||
"tablet": 1,
|
||||
"mobile": 2,
|
||||
"desktop": 0,
|
||||
};
|
||||
|
||||
for (let type in expected) {
|
||||
let count = expected[type];
|
||||
|
||||
if (engine.localType == type) {
|
||||
count++;
|
||||
}
|
||||
|
||||
if (!count) {
|
||||
Assert.ok(!day.has(type));
|
||||
} else {
|
||||
Assert.ok(day.has(type));
|
||||
Assert.equal(day.get(type), count);
|
||||
}
|
||||
}
|
||||
|
||||
engine._store._remoteClients = {};
|
||||
|
||||
yield provider.shutdown();
|
||||
yield storage.close();
|
||||
});
|
||||
|
||||
add_task(function* test_sync_events() {
|
||||
let storage = yield Metrics.Storage("sync_events");
|
||||
let provider = new SyncProvider();
|
||||
yield provider.init(storage);
|
||||
|
||||
let m = provider.getMeasurement("sync", 1);
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
Services.obs.notifyObservers(null, "weave:service:sync:start", null);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
Services.obs.notifyObservers(null, "weave:service:sync:finish", null);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
Services.obs.notifyObservers(null, "weave:service:sync:error", null);
|
||||
}
|
||||
|
||||
// Wait for storage to complete.
|
||||
yield m.storage.enqueueOperation(() => {
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
let values = yield m.getValues();
|
||||
let now = new Date();
|
||||
Assert.ok(values.days.hasDay(now));
|
||||
let day = values.days.getDay(now);
|
||||
|
||||
Assert.ok(day.has("syncStart"));
|
||||
Assert.ok(day.has("syncSuccess"));
|
||||
Assert.ok(day.has("syncError"));
|
||||
Assert.equal(day.get("syncStart"), 5);
|
||||
Assert.equal(day.get("syncSuccess"), 3);
|
||||
Assert.equal(day.get("syncError"), 2);
|
||||
|
||||
yield provider.shutdown();
|
||||
yield storage.close();
|
||||
});
|
||||
|
||||
add_task(function* test_healthreporter_json() {
|
||||
let reporter = yield getHealthReporter("healthreporter_json");
|
||||
yield reporter.init();
|
||||
try {
|
||||
yield reporter._providerManager.registerProvider(new SyncProvider());
|
||||
yield reporter.collectMeasurements();
|
||||
let payload = yield reporter.getJSONPayload(true);
|
||||
let now = new Date();
|
||||
let today = reporter._formatDate(now);
|
||||
|
||||
Assert.ok(today in payload.data.days);
|
||||
let day = payload.data.days[today];
|
||||
|
||||
Assert.ok("org.mozilla.sync.sync" in day);
|
||||
Assert.ok("org.mozilla.sync.devices" in day);
|
||||
|
||||
let devices = day["org.mozilla.sync.devices"];
|
||||
let engine = Weave.Service.clientsEngine;
|
||||
Assert.ok(engine);
|
||||
let type = engine.localType;
|
||||
Assert.ok(type);
|
||||
Assert.ok(type in devices);
|
||||
Assert.equal(devices[type], 1);
|
||||
} finally {
|
||||
reporter._shutdown();
|
||||
}
|
||||
});
|
@ -174,9 +174,6 @@ skip-if = debug
|
||||
[test_tab_store.js]
|
||||
[test_tab_tracker.js]
|
||||
|
||||
[test_healthreport.js]
|
||||
skip-if = ! healthreport
|
||||
|
||||
[test_warn_on_truncated_response.js]
|
||||
|
||||
# FxA migration
|
||||
|
Loading…
Reference in New Issue
Block a user