Bug 1433178 p2 - Allow callers to SyncedBookmarksMirror.apply() to pass explicit weak uploads. r=kitcambridge

MozReview-Commit-ID: EqVmk7AqHWS

--HG--
extra : rebase_source : e4c93aa30f66a8313e5e372b35e929b1472227c6
This commit is contained in:
Edouard Oger 2018-02-27 18:01:19 -05:00
Родитель 89405d6bba
Коммит b2cd60e2b5
4 изменённых файлов: 62 добавлений и 7 удалений

Просмотреть файл

@ -727,7 +727,9 @@ BufferedBookmarksEngine.prototype = {
let buf = await this._store.ensureOpenMirror();
let recordsToUpload = await buf.apply({
remoteTimeSeconds: Resource.serverTime,
weakUpload: [...this._needWeakUpload.keys()],
});
this._needWeakUpload.clear();
this._modified.replace(recordsToUpload);
},
@ -736,9 +738,6 @@ BufferedBookmarksEngine.prototype = {
},
async _createRecord(id) {
if (this._needWeakUpload.has(id)) {
return this._store.createRecord(id, this.name);
}
let change = this._modified.changes[id];
if (!change) {
this._log.error("Creating record for item ${id} not in strong " +

Просмотреть файл

@ -310,14 +310,17 @@ class SyncedBookmarksMirror {
* The current local time, in seconds.
* @param {Number} [options.remoteTimeSeconds]
* The current server time, in seconds.
* @param {String[]} [options.weakUpload]
* GUIDs of bookmarks to weakly upload.
* @return {Object.<String, BookmarkChangeRecord>}
* A changeset containing locally changed and reconciled records to
* upload to the server, and to store in the mirror once upload
* succeeds.
*/
async apply({ localTimeSeconds = Date.now() / 1000,
remoteTimeSeconds = 0 } = {}) {
let hasChanges = await this.hasChanges();
remoteTimeSeconds = 0,
weakUpload = [] } = {}) {
let hasChanges = weakUpload.length > 0 || (await this.hasChanges());
if (!hasChanges) {
MirrorLog.debug("No changes detected in both mirror and Places");
return {};
@ -425,7 +428,7 @@ class SyncedBookmarksMirror {
await this.noteObserverChanges(observersToNotify);
MirrorLog.debug("Staging locally changed items for upload");
await this.stageItemsToUpload();
await this.stageItemsToUpload(weakUpload);
MirrorLog.debug("Fetching records for local items to upload");
let changeRecords = await this.fetchLocalChangeRecords();
@ -1472,8 +1475,21 @@ class SyncedBookmarksMirror {
* items. The change counter in Places is the persistent record of items that
* we need to upload, so, if upload is interrupted or fails, we'll stage the
* items again on the next sync.
*
* @param {String[]} weakUpload
* GUIDs of bookmarks to weakly upload.
*/
async stageItemsToUpload() {
async stageItemsToUpload(weakUpload) {
// Stage explicit weak uploads such as repair responses.
for (let chunk of PlacesSyncUtils.chunkArray(weakUpload,
SQLITE_MAX_VARIABLE_NUMBER)) {
await this.db.execute(`
INSERT INTO itemsToWeaklyReupload(id)
SELECT b.id FROM moz_bookmarks b
WHERE b.guid IN (${new Array(chunk.length).fill("?").join(",")})`,
chunk);
}
// Stage remotely changed items with older local creation dates. These are
// tracked "weakly": if the upload is interrupted or fails, we won't
// reupload the record on the next sync.

Просмотреть файл

@ -0,0 +1,39 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function test_explicit_weakupload() {
let buf = await openMirror("weakupload");
await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.menuGuid,
children: [{
guid: "mozBmk______",
url: "https://mozilla.org",
title: "Mozilla",
tags: ["moz", "dot", "org"],
}],
});
await buf.store(shuffle([{
id: "menu",
type: "folder",
children: ["mozBmk______"],
}, {
id: "mozBmk______",
type: "bookmark",
title: "Mozilla",
bmkUri: "https://mozilla.org",
tags: ["moz", "dot", "org"],
}]), { needsMerge: false });
await PlacesTestUtils.markBookmarksAsSynced();
let changesToUpload = await buf.apply({
weakUpload: ["mozBmk______"]
});
ok("mozBmk______" in changesToUpload);
equal(changesToUpload.mozBmk______.counter, 0);
await buf.finalize();
await PlacesUtils.bookmarks.eraseEverything();
await PlacesSyncUtils.bookmarks.reset();
});

Просмотреть файл

@ -8,6 +8,7 @@ support-files =
[test_bookmark_corruption.js]
[test_bookmark_deduping.js]
[test_bookmark_deletion.js]
[test_bookmark_explicit_weakupload.js]
[test_bookmark_haschanges.js]
[test_bookmark_kinds.js]
[test_bookmark_structure_changes.js]