Bug 1056468 - Clear metadata when history entries are removed. r=lucasr
authorWes Johnston <wjohnston@mozilla.com>
Thu, 21 Aug 2014 10:03:44 -0700
changeset 200837 4de1c030dd85fe6a040a87bd167c8f5a8d87f9a3
parent 200836 d53b90e407ce14d8f1084016d8d8f5e4778498ed
child 200838 992700d61f2b6ab3e774c95d01fb1c0b0536812a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerslucasr
bugs1056468
milestone34.0a1
Bug 1056468 - Clear metadata when history entries are removed. r=lucasr
mobile/android/base/db/BrowserProvider.java
mobile/android/base/db/URLMetadata.java
--- a/mobile/android/base/db/BrowserProvider.java
+++ b/mobile/android/base/db/BrowserProvider.java
@@ -1395,17 +1395,18 @@ public class BrowserProvider extends Sha
                 + " WHERE " + History.IS_DELETED + " = 0"
                 + " AND " + History.URL + " IS NOT NULL"
                 + " UNION ALL SELECT " + Bookmarks.URL
                 + " FROM " + TABLE_BOOKMARKS
                 + " WHERE " + Bookmarks.IS_DELETED + " = 0"
                 + " AND " + Bookmarks.URL + " IS NOT NULL)";
 
         return deleteFavicons(uri, faviconSelection, null) +
-               deleteThumbnails(uri, thumbnailSelection, null);
+               deleteThumbnails(uri, thumbnailSelection, null) +
+               URLMetadata.deleteUnused(getContext().getContentResolver());
     }
 
     @Override
     public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations)
         throws OperationApplicationException {
         final int numOperations = operations.size();
         final ContentProviderResult[] results = new ContentProviderResult[numOperations];
 
--- a/mobile/android/base/db/URLMetadata.java
+++ b/mobile/android/base/db/URLMetadata.java
@@ -1,15 +1,17 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 package org.mozilla.gecko.db;
 
+import org.mozilla.gecko.db.BrowserContract.Bookmarks;
+import org.mozilla.gecko.db.BrowserContract.History;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.Telemetry;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.content.ContentValues;
 import android.content.ContentResolver;
@@ -182,9 +184,23 @@ public class URLMetadata {
                                  .build();
             cr.update(uri, values, URLMetadataTable.URL_COLUMN + "=?", new String[] {
                 (String) data.get(URLMetadataTable.URL_COLUMN)
             });
         } catch (Exception ex) {
             Log.e(LOGTAG, "error saving", ex);
         }
     }
+
+    public static int deleteUnused(final ContentResolver cr) {
+        final String selection = URLMetadataTable.URL_COLUMN + " NOT IN "
+                + "(SELECT " + History.URL
+                + " FROM " + History.TABLE_NAME
+                + " WHERE " + History.IS_DELETED + " = 0"
+                + " UNION "
+                + " SELECT " + Bookmarks.URL
+                + " FROM " + Bookmarks.TABLE_NAME
+                + " WHERE " + Bookmarks.IS_DELETED + " = 0 "
+                + " AND " + Bookmarks.URL + " IS NOT NULL)";
+
+        return cr.delete(URLMetadataTable.CONTENT_URI, selection, null);
+    }
 }