Bug 1321368 - Exclude remote-only visits from AS Top Sites r=ahunt
authorGrisha Kruglov <gkruglov@mozilla.com>
Wed, 14 Dec 2016 16:53:31 -0800
changeset 450139 58eb2dac05da99a29b7623a6bcfc0c258896f0a8
parent 450138 d8c35632d389b21077be9f1d89afbf43c56f7767
child 450140 fe17931bfd5f0658a94f40a71b0463cfa1e03c6c
child 450366 57ab844a366fe32c8623e07c7637bfab81368fac
push id38763
push userbmo:jyavenard@mozilla.com
push dateFri, 16 Dec 2016 02:12:02 +0000
reviewersahunt
bugs1321368
milestone53.0a1
Bug 1321368 - Exclude remote-only visits from AS Top Sites r=ahunt MozReview-Commit-ID: Jacc3SGT2pw
mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
@@ -40,16 +40,17 @@ public class BrowserContract {
 
     public static final String LOGINS_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.logins";
     public static final Uri LOGINS_AUTHORITY_URI = Uri.parse("content://" + LOGINS_AUTHORITY);
 
     public static final String PARAM_PROFILE = "profile";
     public static final String PARAM_PROFILE_PATH = "profilePath";
     public static final String PARAM_LIMIT = "limit";
     public static final String PARAM_SUGGESTEDSITES_LIMIT = "suggestedsites_limit";
+    public static final String PARAM_TOPSITES_EXCLUDE_REMOTE_ONLY = "topsites_exclude_remote_only";
     public static final String PARAM_IS_SYNC = "sync";
     public static final String PARAM_SHOW_DELETED = "show_deleted";
     public static final String PARAM_IS_TEST = "test";
     public static final String PARAM_INSERT_IF_NEEDED = "insert_if_needed";
     public static final String PARAM_INCREMENT_VISITS = "increment_visits";
     public static final String PARAM_INCREMENT_REMOTE_AGGREGATES = "increment_remote_aggregates";
     public static final String PARAM_NON_POSITIONED_PINS = "non_positioned_pins";
     public static final String PARAM_EXPIRE_PRIORITY = "priority";
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -891,16 +891,18 @@ public class BrowserProvider extends Sha
         // 2. The topsites list is larger, hence we use a temporary table, which automatically provides rowids.
 
         final SQLiteDatabase db = getWritableDatabase(uri);
 
         final String TABLE_TOPSITES = "topsites";
 
         final String limitParam = uri.getQueryParameter(BrowserContract.PARAM_LIMIT);
         final String gridLimitParam = uri.getQueryParameter(BrowserContract.PARAM_SUGGESTEDSITES_LIMIT);
+        final boolean excludeRemoteOnly = Boolean.parseBoolean(
+                uri.getQueryParameter(BrowserContract.PARAM_TOPSITES_EXCLUDE_REMOTE_ONLY));
         final String nonPositionedPins = uri.getQueryParameter(BrowserContract.PARAM_NON_POSITIONED_PINS);
 
         final int totalLimit;
         final int suggestedGridLimit;
 
         if (limitParam == null) {
             totalLimit = 50;
         } else {
@@ -944,26 +946,30 @@ public class BrowserProvider extends Sha
                 " (SELECT position FROM numbers WHERE position NOT IN (SELECT " + Bookmarks.POSITION + " " + pinnedSitesFromClause + ")) AS free_ids" +
                 " ON numbers.position > free_ids.position" +
                 " GROUP BY numbers.position" +
                 " ORDER BY numbers.position ASC" +
                 " LIMIT " + suggestedGridLimit;
 
         // Filter out: unvisited pages (history_id == -1) pinned (and other special) sites, deleted sites,
         // and about: pages.
-        final String ignoreForTopSitesWhereClause =
+        String ignoreForTopSitesWhereClause =
                 "(" + Combined.HISTORY_ID + " IS NOT -1)" +
                 " AND " +
                 Combined.URL + " NOT IN (SELECT " +
                 Bookmarks.URL + " FROM bookmarks WHERE " +
                 DBUtils.qualifyColumn("bookmarks", Bookmarks.PARENT) + " < " + Bookmarks.FIXED_ROOT_ID + " AND " +
                 DBUtils.qualifyColumn("bookmarks", Bookmarks.IS_DELETED) + " == 0)" +
                 " AND " +
                 "(" + Combined.URL + " NOT LIKE ?)";
 
+        if (excludeRemoteOnly) {
+            ignoreForTopSitesWhereClause += " AND (" + Combined.LOCAL_VISITS_COUNT + " > 0)";
+        }
+
         final String[] ignoreForTopSitesArgs = new String[] {
                 AboutPages.URL_FILTER
         };
 
         // Stuff the suggested sites into SQL: this allows us to filter pinned and topsites out of the suggested
         // sites list as part of the final query (as opposed to walking cursors in java)
         final SuggestedSites suggestedSites = BrowserDB.from(GeckoProfile.get(
                 getContext(), uri.getQueryParameter(BrowserContract.PARAM_PROFILE))).getSuggestedSites();
--- a/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
@@ -1903,16 +1903,18 @@ public class LocalBrowserDB extends Brow
     public CursorLoader getActivityStreamTopSites(Context context, int suggestedRangeLimit, int limit) {
         final Uri uri = mTopSitesUriWithProfile.buildUpon()
                 .appendQueryParameter(BrowserContract.PARAM_LIMIT,
                         String.valueOf(limit))
                 .appendQueryParameter(BrowserContract.PARAM_SUGGESTEDSITES_LIMIT,
                         String.valueOf(suggestedRangeLimit))
                 .appendQueryParameter(BrowserContract.PARAM_NON_POSITIONED_PINS,
                         String.valueOf(true))
+                .appendQueryParameter(BrowserContract.PARAM_TOPSITES_EXCLUDE_REMOTE_ONLY,
+                        String.valueOf(true))
                 .build();
 
         return new TelemetrisedCursorLoader(context,
                 uri,
                 new String[]{ Combined._ID,
                         Combined.URL,
                         Combined.TITLE,
                         Combined.BOOKMARK_ID,