Bug 1025062 - Part 1: Add filter flag to exclude pinned sites in searches. r=rnewman, a=lmandel
authorLucas Rocha <lucasr@mozilla.com>
Mon, 07 Jul 2014 15:56:06 +0100
changeset 208936 5353e53b7bc0583d1f51483e76f2d21d9c12a28f
parent 208935 534d0fd2f00882799d525e445dd6ec3dd15ed858
child 208937 9c1cfbfcc8277d4fb332dcd9de6081f2d8fad7be
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lmandel
bugs1025062
milestone32.0a2
Bug 1025062 - Part 1: Add filter flag to exclude pinned sites in searches. r=rnewman, a=lmandel
mobile/android/base/db/BrowserDB.java
mobile/android/base/db/LocalBrowserDB.java
mobile/android/base/tests/testBrowserProviderPerf.java
--- a/mobile/android/base/db/BrowserDB.java
+++ b/mobile/android/base/db/BrowserDB.java
@@ -1,16 +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 java.util.ArrayList;
+import java.util.EnumSet;
 import java.util.List;
 
 import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
 import org.mozilla.gecko.db.SuggestedSites;
 import org.mozilla.gecko.favicons.decoders.LoadFaviconResult;
 import org.mozilla.gecko.mozglue.RobocopTarget;
 
 import android.content.ContentResolver;
@@ -28,24 +29,29 @@ public class BrowserDB {
         public static String TITLE = "title";
         public static String FAVICON = "favicon";
         public static String THUMBNAIL = "thumbnail";
         public static String DATE_LAST_VISITED = "date-last-visited";
         public static String VISITS = "visits";
         public static String KEYWORD = "keyword";
     }
 
+    public static enum FilterFlags {
+        EXCLUDE_PINNED_SITES
+    }
+
     private static BrowserDBIface sDb = null;
     private static SuggestedSites sSuggestedSites;
 
     public interface BrowserDBIface {
         public void invalidateCachedState();
 
         @RobocopTarget
-        public Cursor filter(ContentResolver cr, CharSequence constraint, int limit);
+        public Cursor filter(ContentResolver cr, CharSequence constraint, int limit,
+                             EnumSet<FilterFlags> flags);
 
         // This should only return frecent sites. BrowserDB.getTopSites will do the
         // work to combine that list with the pinned sites list.
         public Cursor getTopSites(ContentResolver cr, int limit);
 
         public void updateVisitedHistory(ContentResolver cr, String uri);
 
         public void updateHistoryTitle(ContentResolver cr, String uri, String title);
@@ -158,17 +164,23 @@ public class BrowserDB {
     }
 
     public static void invalidateCachedState() {
         sDb.invalidateCachedState();
     }
 
     @RobocopTarget
     public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
-        return sDb.filter(cr, constraint, limit);
+        return filter(cr, constraint, limit, EnumSet.noneOf(FilterFlags.class));
+    }
+
+    @RobocopTarget
+    public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit,
+                                EnumSet<FilterFlags> flags) {
+        return sDb.filter(cr, constraint, limit, flags);
     }
 
     private static void appendUrlsFromCursor(List<String> urls, Cursor c) {
         c.moveToPosition(-1);
         while (c.moveToNext()) {
             urls.add(c.getString(c.getColumnIndex(URLColumns.URL)));
         };
     }
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -2,30 +2,32 @@
  * 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 java.io.ByteArrayOutputStream;
 import java.util.Collection;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
 
 import org.mozilla.gecko.AboutPages;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
 import org.mozilla.gecko.db.BrowserContract.FaviconColumns;
 import org.mozilla.gecko.db.BrowserContract.Favicons;
 import org.mozilla.gecko.db.BrowserContract.History;
 import org.mozilla.gecko.db.BrowserContract.ReadingListItems;
 import org.mozilla.gecko.db.BrowserContract.SyncColumns;
 import org.mozilla.gecko.db.BrowserContract.Thumbnails;
 import org.mozilla.gecko.db.BrowserContract.URLColumns;
+import org.mozilla.gecko.db.BrowserDB.FilterFlags;
 import org.mozilla.gecko.favicons.decoders.FaviconDecoder;
 import org.mozilla.gecko.favicons.decoders.LoadFaviconResult;
 
 import android.content.ContentProviderOperation;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.database.ContentObserver;
 import android.database.Cursor;
@@ -220,27 +222,40 @@ public class LocalBrowserDB implements B
                     cursor.close();
             }
         }
         debug("Got count " + count + " for " + database);
         return count;
     }
 
     @Override
-    public Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
+    public Cursor filter(ContentResolver cr, CharSequence constraint, int limit,
+                         EnumSet<FilterFlags> flags) {
+        String selection = "";
+        String[] selectionArgs = null;
+
+        if (flags.contains(FilterFlags.EXCLUDE_PINNED_SITES)) {
+            selection = Combined.URL + " NOT IN (SELECT " +
+                                                 Bookmarks.URL + " FROM bookmarks WHERE " +
+                                                 DBUtils.qualifyColumn("bookmarks", Bookmarks.PARENT) + " = ? AND " +
+                                                 DBUtils.qualifyColumn("bookmarks", Bookmarks.IS_DELETED) + " == 0)";
+            selectionArgs = new String[] { String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) };
+        }
+
         return filterAllSites(cr,
                               new String[] { Combined._ID,
                                              Combined.URL,
                                              Combined.TITLE,
                                              Combined.DISPLAY,
                                              Combined.BOOKMARK_ID,
                                              Combined.HISTORY_ID },
                               constraint,
                               limit,
-                              null);
+                              null,
+                              selection, selectionArgs);
     }
 
     @Override
     public Cursor getTopSites(ContentResolver cr, int limit) {
         // Filter out unvisited bookmarks and the ones that don't have real
         // parents (e.g. pinned sites or reading list items).
         String selection = DBUtils.concatenateWhere(Combined.HISTORY_ID + " <> -1",
                                              Combined.URL + " NOT IN (SELECT " +
--- a/mobile/android/base/tests/testBrowserProviderPerf.java
+++ b/mobile/android/base/tests/testBrowserProviderPerf.java
@@ -1,19 +1,21 @@
 /* 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.tests;
 
 import java.io.File;
+import java.util.EnumSet;
 import java.util.Random;
 import java.util.UUID;
 
 import org.mozilla.gecko.db.BrowserContract;
+import org.mozilla.gecko.db.BrowserDB.FilterFlags;
 import org.mozilla.gecko.db.BrowserProvider;
 import org.mozilla.gecko.db.LocalBrowserDB;
 import org.mozilla.gecko.util.FileUtils;
 
 import android.content.ContentProvider;
 import android.content.ContentProviderClient;
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -265,17 +267,18 @@ public class testBrowserProviderPerf ext
      */
     public void testBrowserProviderQueryPerf() throws Exception {
         // We add at least this many results.
         final int limit = 100;
 
         // Make sure we're querying the right profile.
         final LocalBrowserDB db = new LocalBrowserDB(mProfile);
 
-        final Cursor before = db.filter(mResolver, KNOWN_PREFIX, limit);
+        final Cursor before = db.filter(mResolver, KNOWN_PREFIX, limit,
+                                        EnumSet.noneOf(FilterFlags.class));
         try {
             mAsserter.is(before.getCount(), 0, "Starts empty");
         } finally {
             before.close();
         }
 
         // Add data.
         loadMobileFolderId();
@@ -290,17 +293,18 @@ public class testBrowserProviderPerf ext
         // * Adjusting the provider interface to allow a "don't notify" param.
         // * Adjusting the interface schema to include the profile in the path,
         //   and only observe the correct path.
         // * Launching a different activity.
         Thread.sleep(5000);
 
         // Time the query.
         final long start = SystemClock.uptimeMillis();
-        final Cursor c = db.filter(mResolver, KNOWN_PREFIX, limit);
+        final Cursor c = db.filter(mResolver, KNOWN_PREFIX, limit,
+                                   EnumSet.noneOf(FilterFlags.class));
 
         try {
             final int count = c.getCount();
             final long end = SystemClock.uptimeMillis();
 
             mAsserter.is(count, limit, "Retrieved results");
             mAsserter.dumpLog("Results: " + count);
             mAsserter.dumpLog("__start_report" + Long.toString(end - start) + "__end_report");