Bug 724739 - Part 4: Close cursor in idsForGUIDs, thread parent GUID through deletion. r=trivial
authorRichard Newman <rnewman@mozilla.com>
Tue, 10 Apr 2012 23:22:03 -0700
changeset 94721 6cb5a238e20d79a6a72ebe201d52120413e87ba2
parent 94720 3aef4f7cbd6d00d0d7e77b71f3e6045c74280166
child 94722 cdd78230db65003364a15ee800a9d801ba32ede8
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstrivial
bugs724739
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 724739 - Part 4: Close cursor in idsForGUIDs, thread parent GUID through deletion. r=trivial
mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java
mobile/android/base/sync/repositories/android/BookmarksDeletionManager.java
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
@@ -144,27 +144,31 @@ public class AndroidBrowserBookmarksData
       cv.put(BrowserContract.Bookmarks.POSITION, position);
     }
     updateByGuid(guid, cv);
   }
 
   protected Map<String, Long> 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<String, Long> out = new HashMap<String, Long>();
-    if (!c.moveToFirst()) {
+    try {
+      HashMap<String, Long> out = new HashMap<String, Long>();
+      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;
   }
 
   /**
    * Move the children of each source folder to the destination folder.
    * Bump the modified time of each child.
    * The caller should bump the modified time of the destination if desired.
    *
    * @param from the source folders.
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java
@@ -708,18 +708,20 @@ public class AndroidBrowserBookmarksRepo
 
   @Override
   protected void storeRecordDeletion(final Record record, final Record existingRecord) {
     if (SPECIAL_GUIDS_MAP.containsKey(record.guid)) {
       Logger.debug(LOG_TAG, "Told to delete record " + record.guid + ". Ignoring.");
       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() {
     Logger.debug(LOG_TAG, "Applying deletions.");
     try {
       long now = now();
       untrackGUIDs(deletionManager.flushAll(getIDForGUID("unfiled"), now));
       Logger.debug(LOG_TAG, "Done applying deletions.");
--- a/mobile/android/base/sync/repositories/android/BookmarksDeletionManager.java
+++ b/mobile/android/base/sync/repositories/android/BookmarksDeletionManager.java
@@ -83,41 +83,41 @@ public class BookmarksDeletionManager {
    * If not invoked, no callbacks will be submitted.
    *
    * @param delegate a delegate, which should already be a delayed delegate.
    */
   public void setDelegate(RepositorySessionStoreDelegate delegate) {
     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();
       }
     }
   }
 
   /**
    * Flush deletions that can be easily taken care of right now.