Bug 1072332 - Allow clearing metadata based on a profile name. r=mfinkle
authorwesj <wjohnston@mozilla.com>
Fri, 26 Sep 2014 11:31:11 -0700
changeset 207476 5cd5fb2dc27eeae36f913d1afd1ccd5edad9fea5
parent 207475 0c8a202cc44f108449e9930346a2e566703e3b02
child 207477 dd5ffa28355ab2238e4f69d2f3031195744076ae
push id27555
push userryanvm@gmail.com
push dateFri, 26 Sep 2014 20:30:28 +0000
treeherderautoland@4ff52be673f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1072332
milestone35.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 1072332 - Allow clearing metadata based on a profile name. r=mfinkle
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
@@ -1355,17 +1355,18 @@ public class BrowserProvider extends Sha
                 + " 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) +
-               URLMetadata.deleteUnused(getContext().getContentResolver());
+               URLMetadata.deleteUnused(getContext().getContentResolver(),
+                                        uri.getQueryParameter(BrowserContract.PARAM_PROFILE));
     }
 
     @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
@@ -14,16 +14,17 @@ import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.content.ContentValues;
 import android.content.ContentResolver;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.net.Uri;
 import android.support.v4.util.LruCache;
+import android.text.TextUtils;
 import android.util.Log;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -185,22 +186,29 @@ public class URLMetadata {
             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) {
+    public static int deleteUnused(final ContentResolver cr, final String profile) {
         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);
+        Uri uri = URLMetadataTable.CONTENT_URI;
+        if (!TextUtils.isEmpty(profile)) {
+            uri = uri.buildUpon()
+                     .appendQueryParameter(BrowserContract.PARAM_PROFILE, profile)
+                     .build();
+        }
+
+        return cr.delete(uri, selection, null);
     }
 }