Bug 675397 - Add syncing priority to be able to reshuffle the default syncing order. r=rnewman

This commit is contained in:
Mathias De Maré 2014-10-01 08:44:52 +02:00
parent 6a5defd4d0
commit 8fc86e01c4
11 changed files with 50 additions and 9 deletions

View File

@ -483,7 +483,9 @@ EngineManager.prototype = {
* N.B., does not pay attention to the declined list. * N.B., does not pay attention to the declined list.
*/ */
getEnabled: function () { getEnabled: function () {
return this.getAll().filter(function(engine) engine.enabled); return this.getAll()
.filter((engine) => engine.enabled)
.sort((a, b) => a.syncPriority - b.syncPriority);
}, },
get enabledEngineNames() { get enabledEngineNames() {
@ -700,6 +702,13 @@ SyncEngine.prototype = {
_recordObj: CryptoWrapper, _recordObj: CryptoWrapper,
version: 1, version: 1,
// A relative priority to use when computing an order
// for engines to be synced. Higher-priority engines
// (lower numbers) are synced first.
// It is recommended that a unique value be used for each engine,
// in order to guarantee a stable sequence.
syncPriority: 0,
// How many records to pull in a single sync. This is primarily to avoid very // How many records to pull in a single sync. This is primarily to avoid very
// long first syncs against profiles with many history records. // long first syncs against profiles with many history records.
downloadLimit: null, downloadLimit: null,

View File

@ -119,6 +119,8 @@ AddonsEngine.prototype = {
_recordObj: AddonRecord, _recordObj: AddonRecord,
version: 1, version: 1,
syncPriority: 5,
_reconciler: null, _reconciler: null,
/** /**

View File

@ -203,6 +203,8 @@ BookmarksEngine.prototype = {
_trackerObj: BookmarksTracker, _trackerObj: BookmarksTracker,
version: 2, version: 2,
syncPriority: 4,
_sync: function _sync() { _sync: function _sync() {
let engine = this; let engine = this;
let batchEx = null; let batchEx = null;

View File

@ -107,6 +107,8 @@ FormEngine.prototype = {
_recordObj: FormRec, _recordObj: FormRec,
applyIncomingBatchSize: FORMS_STORE_BATCH_SIZE, applyIncomingBatchSize: FORMS_STORE_BATCH_SIZE,
syncPriority: 6,
get prefName() "history", get prefName() "history",
_findDupe: function _findDupe(item) { _findDupe: function _findDupe(item) {

View File

@ -41,7 +41,9 @@ HistoryEngine.prototype = {
_storeObj: HistoryStore, _storeObj: HistoryStore,
_trackerObj: HistoryTracker, _trackerObj: HistoryTracker,
downloadLimit: MAX_HISTORY_DOWNLOAD, downloadLimit: MAX_HISTORY_DOWNLOAD,
applyIncomingBatchSize: HISTORY_STORE_BATCH_SIZE applyIncomingBatchSize: HISTORY_STORE_BATCH_SIZE,
syncPriority: 7,
}; };
function HistoryStore(name, engine) { function HistoryStore(name, engine) {

View File

@ -36,6 +36,8 @@ PasswordEngine.prototype = {
_recordObj: LoginRec, _recordObj: LoginRec,
applyIncomingBatchSize: PASSWORDS_STORE_BATCH_SIZE, applyIncomingBatchSize: PASSWORDS_STORE_BATCH_SIZE,
syncPriority: 2,
_syncFinish: function _syncFinish() { _syncFinish: function _syncFinish() {
SyncEngine.prototype._syncFinish.call(this); SyncEngine.prototype._syncFinish.call(this);

View File

@ -41,6 +41,8 @@ PrefsEngine.prototype = {
_recordObj: PrefRec, _recordObj: PrefRec,
version: 2, version: 2,
syncPriority: 1,
getChangedIDs: function getChangedIDs() { getChangedIDs: function getChangedIDs() {
// No need for a proper timestamp (no conflict resolution needed). // No need for a proper timestamp (no conflict resolution needed).
let changedIDs = {}; let changedIDs = {};

View File

@ -45,6 +45,8 @@ TabEngine.prototype = {
_trackerObj: TabTracker, _trackerObj: TabTracker,
_recordObj: TabSetRecord, _recordObj: TabSetRecord,
syncPriority: 3,
getChangedIDs: function getChangedIDs() { getChangedIDs: function getChangedIDs() {
// No need for a proper timestamp (no conflict resolution needed). // No need for a proper timestamp (no conflict resolution needed).
let changedIDs = {}; let changedIDs = {};

View File

@ -192,3 +192,11 @@ function mockGetWindowEnumerator(url, numWindows, numTabs) {
}, },
}; };
} }
// Helper that allows checking array equality.
function do_check_array_eq(a1, a2) {
do_check_eq(a1.length, a2.length);
for (let i = 0; i < a1.length; ++i) {
do_check_eq(a1[i], a2[i]);
}
}

View File

@ -75,6 +75,23 @@ add_test(function test_basics() {
engines = manager.getEnabled(); engines = manager.getEnabled();
do_check_eq(engines.length, 3); do_check_eq(engines.length, 3);
_("getEnabled() returns enabled engines in sorted order");
petrol.syncPriority = 1;
dummy.syncPriority = 2;
diesel.syncPriority = 3;
engines = manager.getEnabled();
do_check_array_eq(engines, [petrol, dummy, diesel]);
_("Changing the priorities should change the order in getEnabled()");
dummy.syncPriority = 4;
engines = manager.getEnabled();
do_check_array_eq(engines, [petrol, diesel, dummy]);
_("Unregister an engine by name"); _("Unregister an engine by name");
manager.unregister('dummy'); manager.unregister('dummy');
do_check_eq(manager.get('dummy'), undefined); do_check_eq(manager.get('dummy'), undefined);

View File

@ -14,13 +14,6 @@ function sha256HMAC(message, key) {
return Utils.digestBytes(message, h); return Utils.digestBytes(message, h);
} }
function do_check_array_eq(a1, a2) {
do_check_eq(a1.length, a2.length);
for (let i = 0; i < a1.length; ++i) {
do_check_eq(a1[i], a2[i]);
}
}
function do_check_keypair_eq(a, b) { function do_check_keypair_eq(a, b) {
do_check_eq(2, a.length); do_check_eq(2, a.length);
do_check_eq(2, b.length); do_check_eq(2, b.length);