From eab1ae6a1b881ce7f49fef58047c46fe7e785af8 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Tue, 10 Apr 2012 23:22:03 -0700 Subject: [PATCH] Bug 724739 - Part 4: Close cursor in idsForGUIDs, thread parent GUID through deletion. r=trivial --- .../AndroidBrowserBookmarksDataAccessor.java | 22 +++++++++++-------- ...roidBrowserBookmarksRepositorySession.java | 6 +++-- .../android/BookmarksDeletionManager.java | 22 +++++++++---------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java index f9ab62c59c80..adf54f77403f 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 f014484e6e7e..bbb9010bdff8 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 d30421fa13c1..cecd811335a6 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(); }