michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = [ michael@0: "RotaryEngine", michael@0: "RotaryRecord", michael@0: "RotaryStore", michael@0: "RotaryTracker", michael@0: ]; michael@0: michael@0: const {utils: Cu} = Components; michael@0: michael@0: Cu.import("resource://services-sync/engines.js"); michael@0: Cu.import("resource://services-sync/record.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: michael@0: /* michael@0: * A fake engine implementation. michael@0: * This is used all over the place. michael@0: * michael@0: * Complete with record, store, and tracker implementations. michael@0: */ michael@0: michael@0: this.RotaryRecord = function RotaryRecord(collection, id) { michael@0: CryptoWrapper.call(this, collection, id); michael@0: } michael@0: RotaryRecord.prototype = { michael@0: __proto__: CryptoWrapper.prototype michael@0: }; michael@0: Utils.deferGetSet(RotaryRecord, "cleartext", ["denomination"]); michael@0: michael@0: this.RotaryStore = function RotaryStore(engine) { michael@0: Store.call(this, "Rotary", engine); michael@0: this.items = {}; michael@0: } michael@0: RotaryStore.prototype = { michael@0: __proto__: Store.prototype, michael@0: michael@0: create: function create(record) { michael@0: this.items[record.id] = record.denomination; michael@0: }, michael@0: michael@0: remove: function remove(record) { michael@0: delete this.items[record.id]; michael@0: }, michael@0: michael@0: update: function update(record) { michael@0: this.items[record.id] = record.denomination; michael@0: }, michael@0: michael@0: itemExists: function itemExists(id) { michael@0: return (id in this.items); michael@0: }, michael@0: michael@0: createRecord: function createRecord(id, collection) { michael@0: let record = new RotaryRecord(collection, id); michael@0: michael@0: if (!(id in this.items)) { michael@0: record.deleted = true; michael@0: return record; michael@0: } michael@0: michael@0: record.denomination = this.items[id] || "Data for new record: " + id; michael@0: return record; michael@0: }, michael@0: michael@0: changeItemID: function changeItemID(oldID, newID) { michael@0: if (oldID in this.items) { michael@0: this.items[newID] = this.items[oldID]; michael@0: } michael@0: michael@0: delete this.items[oldID]; michael@0: }, michael@0: michael@0: getAllIDs: function getAllIDs() { michael@0: let ids = {}; michael@0: for (let id in this.items) { michael@0: ids[id] = true; michael@0: } michael@0: return ids; michael@0: }, michael@0: michael@0: wipe: function wipe() { michael@0: this.items = {}; michael@0: } michael@0: }; michael@0: michael@0: this.RotaryTracker = function RotaryTracker(engine) { michael@0: Tracker.call(this, "Rotary", engine); michael@0: } michael@0: RotaryTracker.prototype = { michael@0: __proto__: Tracker.prototype michael@0: }; michael@0: michael@0: michael@0: this.RotaryEngine = function RotaryEngine(service) { michael@0: SyncEngine.call(this, "Rotary", service); michael@0: // Ensure that the engine starts with a clean slate. michael@0: this.toFetch = []; michael@0: this.previousFailed = []; michael@0: } michael@0: RotaryEngine.prototype = { michael@0: __proto__: SyncEngine.prototype, michael@0: _storeObj: RotaryStore, michael@0: _trackerObj: RotaryTracker, michael@0: _recordObj: RotaryRecord, michael@0: michael@0: _findDupe: function _findDupe(item) { michael@0: // This is a semaphore used for testing proper reconciling on dupe michael@0: // detection. michael@0: if (item.id == "DUPE_INCOMING") { michael@0: return "DUPE_LOCAL"; michael@0: } michael@0: michael@0: for (let [id, value] in Iterator(this._store.items)) { michael@0: if (item.denomination == value) { michael@0: return id; michael@0: } michael@0: } michael@0: } michael@0: };