Bug 1298783 - Implement adding pages to highlights blocklist r=Grisha
authorAndrzej Hunt <ahunt@mozilla.com>
Wed, 21 Sep 2016 12:12:06 -0700
changeset 315775 0da42b264e172c1c1380ca7abeeb08ad8e2d92b5
parent 315774 7945daf16a508fe367f8efcd8a6a4f93570ea725
child 315776 818fa3036aef389fcc27e24f79a5edb130e15394
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGrisha
bugs1298783
milestone52.0a1
Bug 1298783 - Implement adding pages to highlights blocklist r=Grisha MozReview-Commit-ID: 5dCLHx2UJ5
mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.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/BrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java
@@ -171,16 +171,23 @@ public abstract class BrowserDB {
     /**
      * Obtain a set of links for highlights from bookmarks and history.
      *
      * @param context The context to load the cursor.
      * @param limit Maximum number of results to return.
      */
     public abstract CursorLoader getHighlights(Context context, int limit);
 
+    /**
+     * Block a page from the highlights list.
+     *
+     * @param url The page URL. Only pages exactly matching this URL will be blocked.
+     */
+    public abstract void blockActivityStreamSite(ContentResolver cr, String url);
+
     public static BrowserDB from(final Context context) {
         return from(GeckoProfile.get(context));
     }
 
     public static BrowserDB from(final GeckoProfile profile) {
         synchronized (profile.getLock()) {
             BrowserDB db = (BrowserDB) profile.getData();
             if (db != null) {
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -128,16 +128,18 @@ public class BrowserProvider extends Sha
     static final int TOPSITES = 1000;
 
     static final int VISITS = 1100;
 
     static final int METADATA = 1200;
 
     static final int HIGHLIGHTS = 1300;
 
+    static final int ACTIVITY_STREAM_BLOCKLIST = 1400;
+
     static final String DEFAULT_BOOKMARKS_SORT_ORDER = Bookmarks.TYPE
             + " ASC, " + Bookmarks.POSITION + " ASC, " + Bookmarks._ID
             + " ASC";
 
     static final String DEFAULT_HISTORY_SORT_ORDER = History.DATE_LAST_VISITED + " DESC";
     static final String DEFAULT_VISITS_SORT_ORDER = Visits.DATE_VISITED + " DESC";
 
     static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
@@ -292,16 +294,18 @@ public class BrowserProvider extends Sha
                 URI_MATCHER.addURI(BrowserContract.AUTHORITY, type.name, type.id);
             }
         }
 
         // Combined pinned sites, top visited sites, and suggested sites
         URI_MATCHER.addURI(BrowserContract.AUTHORITY, "topsites", TOPSITES);
 
         URI_MATCHER.addURI(BrowserContract.AUTHORITY, "highlights", HIGHLIGHTS);
+
+        URI_MATCHER.addURI(BrowserContract.AUTHORITY, ActivityStreamBlocklist.TABLE_NAME, ACTIVITY_STREAM_BLOCKLIST);
     }
 
     private static class ShrinkMemoryReceiver extends BroadcastReceiver {
         private final WeakReference<BrowserProvider> mBrowserProviderWeakReference;
 
         public ShrinkMemoryReceiver(final BrowserProvider browserProvider) {
             mBrowserProviderWeakReference = new WeakReference<>(browserProvider);
         }
@@ -644,16 +648,22 @@ public class BrowserProvider extends Sha
             }
 
             case URL_ANNOTATIONS: {
                 trace("Insert on URL_ANNOTATIONS: " + uri);
                 id = insertUrlAnnotation(uri, values);
                 break;
             }
 
+            case ACTIVITY_STREAM_BLOCKLIST: {
+                trace("Insert on ACTIVITY_STREAM_BLOCKLIST: " + uri);
+                id = insertActivityStreamBlocklistSite(uri, values);
+                break;
+            }
+
             default: {
                 Table table = findTableFor(match);
                 if (table == null) {
                     throw new UnsupportedOperationException("Unknown insert URI " + uri);
                 }
 
                 trace("Insert on TABLE: " + uri);
                 final SQLiteDatabase db = getWritableDatabase(uri);
@@ -1873,16 +1883,27 @@ public class BrowserProvider extends Sha
 
         DBUtils.stripEmptyByteArray(values, Thumbnails.DATA);
 
         final SQLiteDatabase db = getWritableDatabase(uri);
         beginWrite(db);
         return db.insertOrThrow(TABLE_THUMBNAILS, null, values);
     }
 
+    private long insertActivityStreamBlocklistSite(final Uri uri, final ContentValues values) {
+        final String url = values.getAsString(ActivityStreamBlocklist.URL);
+        trace("Inserting url into highlights blocklist, URL: " + url);
+
+        final SQLiteDatabase db = getWritableDatabase(uri);
+        values.put(ActivityStreamBlocklist.CREATED, System.currentTimeMillis());
+
+        beginWrite(db);
+        return db.insertOrThrow(TABLE_ACTIVITY_STREAM_BLOCKLIST, null, values);
+    }
+
     private long insertUrlAnnotation(final Uri uri, final ContentValues values) {
         final String url = values.getAsString(UrlAnnotations.URL);
         trace("Inserting url annotations for URL: " + url);
 
         final SQLiteDatabase db = getWritableDatabase(uri);
         beginWrite(db);
         return db.insertOrThrow(TABLE_URL_ANNOTATIONS, null, values);
     }
--- a/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
@@ -22,16 +22,17 @@ import java.util.regex.Pattern;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.db.BrowserContract.ActivityStreamBlocklist;
 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.Favicons;
 import org.mozilla.gecko.db.BrowserContract.History;
 import org.mozilla.gecko.db.BrowserContract.SyncColumns;
 import org.mozilla.gecko.db.BrowserContract.Thumbnails;
 import org.mozilla.gecko.db.BrowserContract.TopSites;
@@ -113,16 +114,17 @@ public class LocalBrowserDB extends Brow
     private final Uri mHistoryExpireUriWithProfile;
     private final Uri mCombinedUriWithProfile;
     private final Uri mUpdateHistoryUriWithProfile;
     private final Uri mFaviconsUriWithProfile;
     private final Uri mThumbnailsUriWithProfile;
     private final Uri mTopSitesUriWithProfile;
     private final Uri mHighlightsUriWithProfile;
     private final Uri mSearchHistoryUri;
+    private final Uri mActivityStreamBlockedUriWithProfile;
 
     private LocalSearches searches;
     private LocalTabsAccessor tabsAccessor;
     private LocalURLMetadata urlMetadata;
     private LocalUrlAnnotations urlAnnotations;
 
     private static final String[] DEFAULT_BOOKMARK_COLUMNS =
             new String[] { Bookmarks._ID,
@@ -140,16 +142,17 @@ public class LocalBrowserDB extends Brow
         mParentsUriWithProfile = DBUtils.appendProfile(profile, Bookmarks.PARENTS_CONTENT_URI);
         mHistoryUriWithProfile = DBUtils.appendProfile(profile, History.CONTENT_URI);
         mHistoryExpireUriWithProfile = DBUtils.appendProfile(profile, History.CONTENT_OLD_URI);
         mCombinedUriWithProfile = DBUtils.appendProfile(profile, Combined.CONTENT_URI);
         mFaviconsUriWithProfile = DBUtils.appendProfile(profile, Favicons.CONTENT_URI);
         mTopSitesUriWithProfile = DBUtils.appendProfile(profile, TopSites.CONTENT_URI);
         mHighlightsUriWithProfile = DBUtils.appendProfile(profile, Highlights.CONTENT_URI);
         mThumbnailsUriWithProfile = DBUtils.appendProfile(profile, Thumbnails.CONTENT_URI);
+        mActivityStreamBlockedUriWithProfile = DBUtils.appendProfile(profile, ActivityStreamBlocklist.CONTENT_URI);
 
         mSearchHistoryUri = BrowserContract.SearchHistory.CONTENT_URI;
 
         mUpdateHistoryUriWithProfile =
                 mHistoryUriWithProfile.buildUpon()
                                       .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true")
                                       .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true")
                                       .build();
@@ -1838,9 +1841,17 @@ public class LocalBrowserDB extends Brow
     @Override
     public CursorLoader getHighlights(Context context, int limit) {
         final Uri uri = mHighlightsUriWithProfile.buildUpon()
                 .appendQueryParameter(BrowserContract.PARAM_LIMIT, String.valueOf(limit))
                 .build();
 
         return new CursorLoader(context, uri, null, null, null, null);
     }
+
+    @Override
+    public void blockActivityStreamSite(ContentResolver cr, String url) {
+        final ContentValues values = new ContentValues();
+        values.put(ActivityStreamBlocklist.URL, url);
+        cr.insert(mActivityStreamBlockedUriWithProfile, values);
+    }
+
 }