diff --git a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java index f9ab62c59c8..adf54f77403 100644 --- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java +++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java @@ -149,17 +149,21 @@ public class AndroidBrowserBookmarksDataAccessor extends AndroidBrowserRepositor protected Map idsForGUIDs(String[] guids) throws NullCursorException { final String where = RepoUtils.computeSQLInClause(guids.length, BrowserContract.Bookmarks.GUID); Cursor c = queryHelper.safeQuery(".idsForGUIDs", GUID_AND_ID, where, guids, null); - HashMap out = new HashMap(); - if (!c.moveToFirst()) { + try { + HashMap out = new HashMap(); + if (!c.moveToFirst()) { + return out; + } + final int guidIndex = c.getColumnIndexOrThrow(BrowserContract.Bookmarks.GUID); + final int idIndex = c.getColumnIndexOrThrow(BrowserContract.Bookmarks._ID); + while (!c.isAfterLast()) { + out.put(c.getString(guidIndex), c.getLong(idIndex)); + c.moveToNext(); + } return out; + } finally { + c.close(); } - final int guidIndex = c.getColumnIndexOrThrow(BrowserContract.Bookmarks.GUID); - final int idIndex = c.getColumnIndexOrThrow(BrowserContract.Bookmarks._ID); - while (!c.isAfterLast()) { - out.put(c.getString(guidIndex), c.getLong(idIndex)); - c.moveToNext(); - } - return out; } /** diff --git a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java index f014484e6e7..bbb9010bdff 100644 --- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java +++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java @@ -713,8 +713,10 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo return; } final BookmarkRecord bookmarkRecord = (BookmarkRecord) record; - final boolean isFolder = ((BookmarkRecord) existingRecord).isFolder(); - deletionManager.deleteRecord(bookmarkRecord, isFolder); + final BookmarkRecord existingBookmark = (BookmarkRecord) existingRecord; + final boolean isFolder = existingBookmark.isFolder(); + final String parentGUID = existingBookmark.parentID; + deletionManager.deleteRecord(bookmarkRecord.guid, isFolder, parentGUID); } protected void flushDeletions() { diff --git a/mobile/android/base/sync/repositories/android/BookmarksDeletionManager.java b/mobile/android/base/sync/repositories/android/BookmarksDeletionManager.java index d30421fa13c..cecd811335a 100644 --- a/mobile/android/base/sync/repositories/android/BookmarksDeletionManager.java +++ b/mobile/android/base/sync/repositories/android/BookmarksDeletionManager.java @@ -88,31 +88,31 @@ public class BookmarksDeletionManager { this.delegate = delegate; } - public void deleteRecord(BookmarkRecord r, boolean isFolder) { - if (r.guid == null) { + public void deleteRecord(String guid, boolean isFolder, String parentGUID) { + if (guid == null) { Logger.warn(LOG_TAG, "Cannot queue deletion of record with no GUID."); return; } - Logger.debug(LOG_TAG, "Queuing deletion of " + r.guid); + Logger.debug(LOG_TAG, "Queuing deletion of " + guid); if (isFolder) { - folders.add(r.guid); - if (!folders.contains(r.parentID)) { + folders.add(guid); + if (!folders.contains(parentGUID)) { // We're not going to delete its parent; will need to bump it. - folderParents.add(r.parentID); + folderParents.add(parentGUID); } - nonFolderParents.remove(r.guid); - folderParents.remove(r.guid); + nonFolderParents.remove(guid); + folderParents.remove(guid); return; } - if (!folders.contains(r.parentID)) { + if (!folders.contains(parentGUID)) { // We're not going to delete its parent; will need to bump it. - nonFolderParents.add(r.parentID); + nonFolderParents.add(parentGUID); } - if (nonFolders.add(r.guid)) { + if (nonFolders.add(guid)) { if (++nonFolderCount >= flushThreshold) { deleteNonFolders(); }