From 94461e643caa876759581d24c4441935b65f88ba Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Thu, 23 Feb 2012 08:14:05 -0800 Subject: [PATCH] Bug 718238 - Part 3: correct handling of deletion. Generate valid records for deleted bookmarks and history items. r=nalexander --- .../repositories/domain/BookmarkRecord.java | 35 ++++++++++++------- .../repositories/domain/HistoryRecord.java | 18 +++++++--- .../base/sync/repositories/domain/Record.java | 14 ++++++++ 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/mobile/android/base/sync/repositories/domain/BookmarkRecord.java b/mobile/android/base/sync/repositories/domain/BookmarkRecord.java index 8838316a46f..6c50446cad5 100644 --- a/mobile/android/base/sync/repositories/domain/BookmarkRecord.java +++ b/mobile/android/base/sync/repositories/domain/BookmarkRecord.java @@ -150,9 +150,13 @@ public class BookmarkRecord extends Record { this.guid = payload.guid; checkGUIDs(p); + final Object del = p.get("deleted"); + if (del instanceof Boolean) { + this.deleted = (Boolean) del; + } + this.collection = payload.collection; this.lastModified = payload.lastModified; - this.deleted = payload.deleted; this.type = (String) p.get("type"); this.title = (String) p.get("title"); @@ -209,18 +213,23 @@ public class BookmarkRecord extends Record { CryptoRecord rec = new CryptoRecord(this); rec.payload = new ExtendedJSONObject(); rec.payload.put("id", this.guid); - rec.payload.put("type", this.type); - rec.payload.put("title", this.title); - rec.payload.put("description", this.description); - rec.payload.put("parentid", this.parentID); - rec.payload.put("parentName", this.parentName); - if (isBookmark()) { - rec.payload.put("bmkUri", bookmarkURI); - rec.payload.put("keyword", keyword); - rec.payload.put("tags", this.tags); - } - if (isFolder()) { - rec.payload.put("children", this.children); + + if (this.deleted) { + rec.payload.put("deleted", true); + } else { + putPayload(rec, "type", this.type); + putPayload(rec, "title", this.title); + putPayload(rec, "description", this.description); + putPayload(rec, "parentid", this.parentID); + putPayload(rec, "parentName", this.parentName); + + if (isBookmark()) { + rec.payload.put("bmkUri", bookmarkURI); + rec.payload.put("keyword", keyword); + rec.payload.put("tags", this.tags); + } else if (isFolder()) { + rec.payload.put("children", this.children); + } } return rec; } diff --git a/mobile/android/base/sync/repositories/domain/HistoryRecord.java b/mobile/android/base/sync/repositories/domain/HistoryRecord.java index 07a1b04f942..6531b8090ad 100644 --- a/mobile/android/base/sync/repositories/domain/HistoryRecord.java +++ b/mobile/android/base/sync/repositories/domain/HistoryRecord.java @@ -116,7 +116,10 @@ public class HistoryRecord extends Record { this.checkGUIDs(p); this.lastModified = payload.lastModified; - this.deleted = payload.deleted; + final Object del = p.get("deleted"); + if (del instanceof Boolean) { + this.deleted = (Boolean) del; + } this.histURI = (String) p.get("histUri"); this.title = (String) p.get("title"); @@ -133,10 +136,15 @@ public class HistoryRecord extends Record { CryptoRecord rec = new CryptoRecord(this); rec.payload = new ExtendedJSONObject(); Logger.debug(LOG_TAG, "Getting payload for history record " + this.guid + " (" + this.guid.length() + ")."); - rec.payload.put("id", this.guid); - rec.payload.put("title", this.title); - rec.payload.put("histUri", this.histURI); // TODO: encoding? - rec.payload.put("visits", this.visits); + + if (this.deleted) { + rec.payload.put("deleted", true); + } else { + putPayload(rec, "id", this.guid); + putPayload(rec, "title", this.title); + putPayload(rec, "histUri", this.histURI); // TODO: encoding? + rec.payload.put("visits", this.visits); + } return rec; } diff --git a/mobile/android/base/sync/repositories/domain/Record.java b/mobile/android/base/sync/repositories/domain/Record.java index 0fc050b0602..26d221e7890 100644 --- a/mobile/android/base/sync/repositories/domain/Record.java +++ b/mobile/android/base/sync/repositories/domain/Record.java @@ -240,6 +240,20 @@ public abstract class Record { } } + /** + * Utility for safely populating an output CryptoRecord. + * + * @param rec + * @param key + * @param value + */ + protected void putPayload(CryptoRecord rec, String key, String value) { + if (value == null) { + return; + } + rec.payload.put(key, value); + } + protected void checkGUIDs(ExtendedJSONObject payload) { String payloadGUID = (String) payload.get("id"); if (this.guid == null ||