2012-09-25 00:42:31 +04:00
|
|
|
/* 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";
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = [
|
2012-09-25 00:42:31 +04:00
|
|
|
"RotaryEngine",
|
|
|
|
"RotaryRecord",
|
|
|
|
"RotaryStore",
|
|
|
|
"RotaryTracker",
|
|
|
|
];
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const {Store, SyncEngine, Tracker} = ChromeUtils.import("resource://services-sync/engines.js");
|
|
|
|
const {CryptoWrapper} = ChromeUtils.import("resource://services-sync/record.js");
|
|
|
|
const {SerializableSet, Utils} = ChromeUtils.import("resource://services-sync/util.js");
|
2012-09-25 00:42:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A fake engine implementation.
|
|
|
|
* This is used all over the place.
|
|
|
|
*
|
|
|
|
* Complete with record, store, and tracker implementations.
|
|
|
|
*/
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
function RotaryRecord(collection, id) {
|
2012-09-25 00:42:31 +04:00
|
|
|
CryptoWrapper.call(this, collection, id);
|
2018-02-23 22:50:01 +03:00
|
|
|
}
|
2012-09-25 00:42:31 +04:00
|
|
|
RotaryRecord.prototype = {
|
2018-08-31 08:59:17 +03:00
|
|
|
__proto__: CryptoWrapper.prototype,
|
2012-09-25 00:42:31 +04:00
|
|
|
};
|
|
|
|
Utils.deferGetSet(RotaryRecord, "cleartext", ["denomination"]);
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
function RotaryStore(name, engine) {
|
2015-09-16 04:18:04 +03:00
|
|
|
Store.call(this, name, engine);
|
2012-09-25 00:42:31 +04:00
|
|
|
this.items = {};
|
2018-02-23 22:50:01 +03:00
|
|
|
}
|
2012-09-25 00:42:31 +04:00
|
|
|
RotaryStore.prototype = {
|
|
|
|
__proto__: Store.prototype,
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async create(record) {
|
2012-09-25 00:42:31 +04:00
|
|
|
this.items[record.id] = record.denomination;
|
|
|
|
},
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async remove(record) {
|
2012-09-25 00:42:31 +04:00
|
|
|
delete this.items[record.id];
|
|
|
|
},
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async update(record) {
|
2012-09-25 00:42:31 +04:00
|
|
|
this.items[record.id] = record.denomination;
|
|
|
|
},
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async itemExists(id) {
|
2012-09-25 00:42:31 +04:00
|
|
|
return (id in this.items);
|
|
|
|
},
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async createRecord(id, collection) {
|
2012-09-25 00:42:31 +04:00
|
|
|
let record = new RotaryRecord(collection, id);
|
|
|
|
|
|
|
|
if (!(id in this.items)) {
|
|
|
|
record.deleted = true;
|
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
|
|
|
record.denomination = this.items[id] || "Data for new record: " + id;
|
|
|
|
return record;
|
|
|
|
},
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async changeItemID(oldID, newID) {
|
2012-09-25 00:42:31 +04:00
|
|
|
if (oldID in this.items) {
|
|
|
|
this.items[newID] = this.items[oldID];
|
|
|
|
}
|
|
|
|
|
|
|
|
delete this.items[oldID];
|
|
|
|
},
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async getAllIDs() {
|
2012-09-25 00:42:31 +04:00
|
|
|
let ids = {};
|
|
|
|
for (let id in this.items) {
|
|
|
|
ids[id] = true;
|
|
|
|
}
|
|
|
|
return ids;
|
|
|
|
},
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async wipe() {
|
2012-09-25 00:42:31 +04:00
|
|
|
this.items = {};
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2012-09-25 00:42:31 +04:00
|
|
|
};
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
function RotaryTracker(name, engine) {
|
2015-09-16 04:18:04 +03:00
|
|
|
Tracker.call(this, name, engine);
|
2018-02-23 22:50:01 +03:00
|
|
|
}
|
2012-09-25 00:42:31 +04:00
|
|
|
RotaryTracker.prototype = {
|
2017-02-14 00:48:08 +03:00
|
|
|
__proto__: Tracker.prototype,
|
|
|
|
persistChangedIDs: false,
|
2012-09-25 00:42:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
function RotaryEngine(service) {
|
2012-09-25 00:42:31 +04:00
|
|
|
SyncEngine.call(this, "Rotary", service);
|
|
|
|
// Ensure that the engine starts with a clean slate.
|
2018-01-10 03:22:33 +03:00
|
|
|
this.toFetch = new SerializableSet();
|
|
|
|
this.previousFailed = new SerializableSet();
|
2018-02-23 22:50:01 +03:00
|
|
|
}
|
2012-09-25 00:42:31 +04:00
|
|
|
RotaryEngine.prototype = {
|
|
|
|
__proto__: SyncEngine.prototype,
|
|
|
|
_storeObj: RotaryStore,
|
|
|
|
_trackerObj: RotaryTracker,
|
|
|
|
_recordObj: RotaryRecord,
|
|
|
|
|
2017-06-06 01:49:43 +03:00
|
|
|
async _findDupe(item) {
|
|
|
|
// This is a Special Value® used for testing proper reconciling on dupe
|
2012-09-25 00:42:31 +04:00
|
|
|
// detection.
|
|
|
|
if (item.id == "DUPE_INCOMING") {
|
|
|
|
return "DUPE_LOCAL";
|
|
|
|
}
|
|
|
|
|
2016-08-09 05:40:23 +03:00
|
|
|
for (let [id, value] of Object.entries(this._store.items)) {
|
2012-09-25 00:42:31 +04:00
|
|
|
if (item.denomination == value) {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
2017-02-17 04:34:45 +03:00
|
|
|
return null;
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2012-09-25 00:42:31 +04:00
|
|
|
};
|