Bug 1395427 p3 - Allow form history items to be created with a specific guid. r?markh
This allows us to have the same form history GUIDs across devices, which is mandatory
if we want tombstones to actually do something.
MozReview-Commit-ID: Hw6ahbVA5lB
--- a/services/sync/modules/engines/forms.js
+++ b/services/sync/modules/engines/forms.js
@@ -177,16 +177,17 @@ FormStore.prototype = {
}
return record;
},
async create(record) {
this._log.trace("Adding form record for " + record.name);
let change = {
op: "add",
+ guid: record.id,
fieldname: record.name,
value: record.value
};
await this._processChange(change);
},
async remove(record) {
this._log.trace("Removing form record: " + record.id);
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -671,17 +671,19 @@ function updateFormHistoryWrite(aChanges
} else {
change.guid = generateGUID();
stmt = makeAddStatement(change, now, bindingArrays);
notifications.push(["formhistory-add", change.guid]);
}
break;
case "add":
log("Add to form history " + change);
- change.guid = generateGUID();
+ if (!change.guid) {
+ change.guid = generateGUID();
+ }
stmt = makeAddStatement(change, now, bindingArrays);
notifications.push(["formhistory-add", change.guid]);
break;
default:
// We should've already guaranteed that change.op is one of the above
throw Components.Exception("Invalid operation " + operation,
Cr.NS_ERROR_ILLEGAL_VALUE);
}
@@ -917,23 +919,22 @@ this.FormHistory = {
}
} else {
throw Components.Exception(
"update op='bump' does not correctly reference a entry.",
Cr.NS_ERROR_ILLEGAL_VALUE);
}
break;
case "add":
- if (change.guid) {
+ if (change.fieldname && change.value) {
+ validateOpData(change, "Add");
+ } else {
throw Components.Exception(
- "op='add' cannot contain field 'guid'. Either use op='update' " +
- "explicitly or make 'guid' undefined.",
+ "update op='add' must have a fieldname and a value.",
Cr.NS_ERROR_ILLEGAL_VALUE);
- } else if (change.fieldname && change.value) {
- validateOpData(change, "Add");
}
break;
default:
throw Components.Exception(
"update does not recognize op='" + change.op + "'",
Cr.NS_ERROR_ILLEGAL_VALUE);
}