Bug 482670 - WBORecord should implement a .deleted property

Expose a .deleted property that engines can set to true to store an even thinner deleted payload (empty string "" instead of "[null]") on the server. Handle deserializing of deleted records by setting the property. Note: Engines must set their payloads to something JSON-able if it's not a delete record.
This commit is contained in:
Edward Lee 2009-04-03 12:38:47 -05:00
parent c1e5c50285
commit a9b1c2cc31
7 changed files with 50 additions and 34 deletions

View File

@ -84,8 +84,8 @@ CryptoWrapper.prototype = {
_encrypt: function CryptoWrap__encrypt(passphrase) {
let self = yield;
// Don't encrypt empty payloads
if (!this.payload) {
// No need to encrypt deleted records
if (this.deleted) {
self.done();
return;
}
@ -109,8 +109,8 @@ CryptoWrapper.prototype = {
_decrypt: function CryptoWrap__decrypt(passphrase) {
let self = yield;
// Empty payloads aren't encrypted
if (!this.payload) {
// Deleted records aren't encrypted
if (this.deleted) {
self.done();
return;
}
@ -132,13 +132,13 @@ CryptoWrapper.prototype = {
this._decrypt.async(this, onComplete, passphrase);
},
toString: function WBORec_toString() {
return "{ id: " + this.id + "\n" +
" parent: " + this.parentid + "\n" +
" depth: " + this.depth + ", index: " + this.sortindex + "\n" +
" modified: " + this.modified + "\n" +
" payload: " + JSON.stringify(this.cleartext) + " }";
}
toString: function CryptoWrap_toString() "{ " + [
"id: " + this.id,
"parent: " + this.parentid,
"depth: " + this.depth + ", index: " + this.sortindex,
"modified: " + this.modified,
"payload: " + (this.deleted ? "DELETED" : JSON.stringify(this.cleartext))
].join("\n ") + " }",
};
function CryptoMeta(uri) {

View File

@ -52,8 +52,16 @@ function WBORecord(uri) {
this._WBORec_init(uri);
}
WBORecord.prototype = {
//////////////////////////////////////////////////////////////////////////////
// WBORecord Attributes
deleted: false,
_logName: "Record.WBO",
//////////////////////////////////////////////////////////////////////////////
// WBORecord Methods
_WBORec_init: function WBORec_init(uri) {
this.data = {
payload: {}
@ -115,27 +123,36 @@ WBORecord.prototype = {
this.data.payload = value;
},
// payload is encoded twice in serialized form, because the
// server expects a string
serialize: function WBORec_serialize() {
this.payload = JSON.stringify([this.payload]);
// Convert the payload into a string because the server expects that
let payload = this.payload;
this.payload = this.deleted ? "" : JSON.stringify(payload);
let ret = JSON.stringify(this.data);
this.payload = JSON.parse(this.payload)[0];
// Restore the original payload
this.payload = payload;
return ret;
},
deserialize: function WBORec_deserialize(json) {
this.data = JSON.parse(json);
this.payload = JSON.parse(this.payload)[0];
// Empty string payloads are deleted records
if (this.payload === "")
this.deleted = true;
else
this.payload = JSON.parse(this.payload);
},
toString: function WBORec_toString() {
return "{ id: " + this.id + "\n" +
" parent: " + this.parentid + "\n" +
" depth: " + this.depth + ", index: " + this.sortindex + "\n" +
" modified: " + this.modified + "\n" +
" payload: " + JSON.stringify(this.payload) + " }";
}
toString: function WBORec_toString() "{ " + [
"id: " + this.id,
"parent: " + this.parentid,
"depth: " + this.depth + ", index: " + this.sortindex,
"modified: " + this.modified,
"payload: " + (this.deleted ? "DELETED" : JSON.stringify(this.payload))
].join("\n ") + " }",
};
Utils.lazy(this, 'Records', RecordManager);

View File

@ -246,7 +246,7 @@ SyncEngine.prototype = {
if (a.depth != b.depth)
return false;
// note: sortindex ignored
if (a.payload == null || b.payload == null) // deleted items
if (a.deleted || b.deleted)
return false;
return Utils.deepEquals(a.cleartext, b.cleartext);
},
@ -396,7 +396,7 @@ SyncEngine.prototype = {
// If the incoming item has been deleted, skip step 3
this._log.trace("Reconcile step 2.5");
if (item.payload === null) {
if (item.deleted) {
self.done(true);
return;
}
@ -451,7 +451,7 @@ SyncEngine.prototype = {
for (let id in this._tracker.changedIDs) {
let out = this._createRecord(id);
this._log.trace("Outgoing:\n" + out);
if (out.payload) // skip deleted records
if (!out.deleted)
this._store.createMetaRecords(out.id, meta);
yield out.encrypt(self.cb, ID.get('WeaveCryptoID').password);
up.pushData(JSON.parse(out.serialize())); // FIXME: inefficient

View File

@ -487,7 +487,7 @@ BookmarksStore.prototype = {
if (placeId <= 0) { // deleted item
record = new PlacesItem();
record.id = guid;
record.payload = null;
record.deleted = true;
this.cache.put(guid, record);
return record;
}

View File

@ -89,7 +89,7 @@ HistoryEngine.prototype = {
}
// Step 2: Check if the item is deleted - we don't support that (yet?)
if (item.cleartext == null) {
if (item.deleted) {
self.done(false);
return;
}
@ -455,9 +455,9 @@ HistoryStore.prototype = {
record.title = foo.title;
record.visits = this._getVisits(record.histUri);
record.encryption = cryptoMetaURL;
} else {
record.payload = null; // deleted item
}
else
record.deleted = true;
this.cache.put(guid, record);
return record;
},

View File

@ -180,10 +180,9 @@ PasswordStore.prototype = {
record.password = login.password;
record.usernameField = login.usernameField;
record.passwordField = login.passwordField;
} else {
/* Deleted item */
record.payload = null;
}
else
record.deleted = true;
return record;
},

View File

@ -77,7 +77,7 @@ Store.prototype = {
applyIncoming: function Store_applyIncoming(onComplete, record) {
let fn = function(rec) {
let self = yield;
if (rec.payload == null)
if (rec.deleted)
this.remove(rec);
else if (!this.itemExists(rec.id))
this.create(rec);