Bug 724739 - Part 4: Close cursor in idsForGUIDs, thread parent GUID through deletion. r=trivial

This commit is contained in:
Richard Newman 2012-04-10 23:22:03 -07:00
Родитель c42fbc19e8
Коммит eab1ae6a1b
3 изменённых файлов: 28 добавлений и 22 удалений

Просмотреть файл

@ -149,17 +149,21 @@ public class AndroidBrowserBookmarksDataAccessor extends AndroidBrowserRepositor
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;
}
/**

Просмотреть файл

@ -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() {

Просмотреть файл

@ -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();
}