зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1199077 - Sync changes to store the history sync ID and last sync time in Places. r=markh
MozReview-Commit-ID: 59kON9kHvfP --HG-- extra : rebase_source : 2a56151e79a8928681bbbaa818bcb98e60c859c4
This commit is contained in:
Родитель
004720e0a3
Коммит
242cde0bed
|
@ -45,6 +45,75 @@ HistoryEngine.prototype = {
|
|||
|
||||
syncPriority: 7,
|
||||
|
||||
_migratedSyncMetadata: false,
|
||||
async _migrateSyncMetadata() {
|
||||
if (this._migratedSyncMetadata) {
|
||||
return;
|
||||
}
|
||||
// Migrate the history sync ID and last sync time from prefs, to avoid
|
||||
// triggering a full sync on upgrade. This can be removed in bug 1443021.
|
||||
let existingSyncID = await super.getSyncID();
|
||||
if (existingSyncID) {
|
||||
this._log.debug("Migrating existing sync ID ${existingSyncID} from prefs",
|
||||
{ existingSyncID });
|
||||
await PlacesSyncUtils.history.ensureCurrentSyncId(existingSyncID);
|
||||
}
|
||||
let existingLastSync = await super.getLastSync();
|
||||
if (existingLastSync) {
|
||||
this._log.debug("Migrating existing last sync time ${existingLastSync} " +
|
||||
"from prefs", { existingLastSync });
|
||||
await PlacesSyncUtils.history.setLastSync(existingLastSync);
|
||||
}
|
||||
this._migratedSyncMetadata = true;
|
||||
},
|
||||
|
||||
async getSyncID() {
|
||||
return PlacesSyncUtils.history.getSyncId();
|
||||
},
|
||||
|
||||
async ensureCurrentSyncID(newSyncID) {
|
||||
this._log.debug("Checking if server sync ID ${newSyncID} matches existing",
|
||||
{ newSyncID });
|
||||
await PlacesSyncUtils.history.ensureCurrentSyncId(newSyncID);
|
||||
super.setSyncIDPref(newSyncID); // Remove in bug 1443021.
|
||||
return newSyncID;
|
||||
},
|
||||
|
||||
async resetSyncID() {
|
||||
// First, delete the collection on the server. It's fine if we're
|
||||
// interrupted here: on the next sync, we'll detect that our old sync ID is
|
||||
// now stale, and start over as a first sync.
|
||||
await this._deleteServerCollection();
|
||||
// Then, reset our local sync ID.
|
||||
return this.resetLocalSyncID();
|
||||
},
|
||||
|
||||
async resetLocalSyncID() {
|
||||
let newSyncID = await PlacesSyncUtils.history.resetSyncId();
|
||||
this._log.debug("Assigned new sync ID ${newSyncID}", { newSyncID });
|
||||
await super.setSyncIDPref(newSyncID); // Remove in bug 1443021.
|
||||
return newSyncID;
|
||||
},
|
||||
|
||||
setSyncIDPref(syncID) {
|
||||
throw new Error("Use ensureCurrentSyncID or resetLocalSyncID");
|
||||
},
|
||||
|
||||
async getLastSync() {
|
||||
let lastSync = await PlacesSyncUtils.history.getLastSync();
|
||||
return lastSync;
|
||||
},
|
||||
|
||||
async setLastSync(lastSync) {
|
||||
await PlacesSyncUtils.history.setLastSync(lastSync);
|
||||
await super.setLastSync(lastSync); // Remove in bug 1443021.
|
||||
},
|
||||
|
||||
async _syncStartup() {
|
||||
await this._migrateSyncMetadata();
|
||||
await super._syncStartup();
|
||||
},
|
||||
|
||||
async _processIncoming(newitems) {
|
||||
// We want to notify history observers that a batch operation is underway
|
||||
// so they don't do lots of work for each incoming record.
|
||||
|
@ -79,6 +148,11 @@ HistoryEngine.prototype = {
|
|||
await this._tracker.removeChangedID(...guidsToRemove);
|
||||
return changedIDs;
|
||||
},
|
||||
|
||||
async _resetClient() {
|
||||
await super._resetClient();
|
||||
await PlacesSyncUtils.history.reset();
|
||||
},
|
||||
};
|
||||
|
||||
function HistoryStore(name, engine) {
|
||||
|
@ -423,7 +497,7 @@ HistoryStore.prototype = {
|
|||
},
|
||||
|
||||
async wipe() {
|
||||
return PlacesUtils.history.clear();
|
||||
return PlacesSyncUtils.history.wipe();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -256,3 +256,43 @@ add_task(async function test_history_visit_dedupe_old() {
|
|||
await engine.wipeClient();
|
||||
await engine.finalize();
|
||||
});
|
||||
|
||||
add_task(async function test_migrate_sync_metadata() {
|
||||
let engine = new HistoryEngine(Service);
|
||||
await engine.initialize();
|
||||
await engine.resetClient();
|
||||
|
||||
let syncID = Utils.makeGUID();
|
||||
let lastSync = Date.now() / 1000;
|
||||
|
||||
Svc.Prefs.set(`${engine.name}.syncID`, syncID);
|
||||
Svc.Prefs.set(`${engine.name}.lastSync`, lastSync.toString());
|
||||
|
||||
strictEqual(await engine.getSyncID(), "",
|
||||
"Engine should start with empty sync ID");
|
||||
strictEqual(await engine.getLastSync(), 0,
|
||||
"Engine should start with empty last sync");
|
||||
|
||||
info("Migrate Sync metadata prefs");
|
||||
await engine._migrateSyncMetadata();
|
||||
|
||||
equal(await engine.getSyncID(), syncID,
|
||||
"Initializing engine should migrate sync ID");
|
||||
equal(await engine.getLastSync(), lastSync,
|
||||
"Initializing engine should migrate last sync time");
|
||||
|
||||
let newSyncID = Utils.makeGUID();
|
||||
await engine.ensureCurrentSyncID(newSyncID);
|
||||
|
||||
equal(await engine.getSyncID(), newSyncID,
|
||||
"Changing engine sync ID should update Places");
|
||||
strictEqual(await engine.getLastSync(), 0,
|
||||
"Changing engine sync ID should clear last sync in Places");
|
||||
|
||||
equal(Svc.Prefs.get(`${engine.name}.syncID`), newSyncID,
|
||||
"Changing engine sync ID should update prefs");
|
||||
strictEqual(Svc.Prefs.get(`${engine.name}.lastSync`), "0",
|
||||
"Changing engine sync ID should clear last sync pref");
|
||||
|
||||
await engine.wipeClient();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче