Bug 1250707 - Add UrlAnnotations with insertion. r=sebastian
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 25 Feb 2016 17:53:35 -0800
changeset 323998 c57441126163dc9384ac1e2c6589e97e3a018c28
parent 323997 d8316642b8021f3bc1c054dbeaa2d9ca239bdd30
child 323999 3693e541f0ee18223dd00a1745a4cd09416722a9
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1250707
milestone47.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 1250707 - Add UrlAnnotations with insertion. r=sebastian MozReview-Commit-ID: A93dzl7hJPG
mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java
mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
mobile/android/base/java/org/mozilla/gecko/db/LocalUrlAnnotations.java
mobile/android/base/java/org/mozilla/gecko/db/StubBrowserDB.java
mobile/android/base/java/org/mozilla/gecko/db/UrlAnnotations.java
mobile/android/base/moz.build
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java
@@ -5,16 +5,17 @@
 package org.mozilla.gecko.db;
 
 import java.io.File;
 import java.util.Collection;
 import java.util.EnumSet;
 import java.util.List;
 
 import org.mozilla.gecko.GeckoProfile;
+import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
 import org.mozilla.gecko.distribution.Distribution;
 import org.mozilla.gecko.favicons.decoders.LoadFaviconResult;
 
 import android.content.ContentProviderOperation;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.database.ContentObserver;
@@ -38,16 +39,17 @@ public interface BrowserDB {
     public static enum FilterFlags {
         EXCLUDE_PINNED_SITES
     }
 
     public abstract Searches getSearches();
     public abstract TabsAccessor getTabsAccessor();
     public abstract URLMetadata getURLMetadata();
     public abstract ReadingListAccessor getReadingListAccessor();
+    @RobocopTarget UrlAnnotations getUrlAnnotations();
 
     /**
      * Add default bookmarks to the database.
      * Takes an offset; returns a new offset.
      */
     public abstract int addDefaultBookmarks(Context context, ContentResolver cr, int offset);
 
     /**
--- a/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
@@ -96,16 +96,17 @@ public class LocalBrowserDB implements B
     private final Uri mFaviconsUriWithProfile;
     private final Uri mThumbnailsUriWithProfile;
     private final Uri mSearchHistoryUri;
 
     private LocalSearches searches;
     private LocalTabsAccessor tabsAccessor;
     private LocalURLMetadata urlMetadata;
     private LocalReadingListAccessor readingListAccessor;
+    private LocalUrlAnnotations urlAnnotations;
 
     private static final String[] DEFAULT_BOOKMARK_COLUMNS =
             new String[] { Bookmarks._ID,
                            Bookmarks.GUID,
                            Bookmarks.URL,
                            Bookmarks.TITLE,
                            Bookmarks.TYPE,
                            Bookmarks.PARENT };
@@ -129,16 +130,17 @@ public class LocalBrowserDB implements B
                                       .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true")
                                       .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true")
                                       .build();
 
         searches = new LocalSearches(mProfile);
         tabsAccessor = new LocalTabsAccessor(mProfile);
         urlMetadata = new LocalURLMetadata(mProfile);
         readingListAccessor = new LocalReadingListAccessor(mProfile);
+        urlAnnotations = new LocalUrlAnnotations(mProfile);
     }
 
     @Override
     public Searches getSearches() {
         return searches;
     }
 
     @Override
@@ -151,16 +153,22 @@ public class LocalBrowserDB implements B
         return urlMetadata;
     }
 
     @Override
     public ReadingListAccessor getReadingListAccessor() {
         return readingListAccessor;
     }
 
+    @RobocopTarget
+    @Override
+    public UrlAnnotations getUrlAnnotations() {
+        return urlAnnotations;
+    }
+
     /**
      * Not thread safe. A helper to allocate new IDs for arbitrary strings.
      */
     private static class NameCounter {
         private final HashMap<String, Integer> names = new HashMap<String, Integer>();
         private int counter;
         private final int increment;
 
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalUrlAnnotations.java
@@ -0,0 +1,31 @@
+/* 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 android.content.ContentResolver;
+import android.content.ContentValues;
+import android.net.Uri;
+import org.mozilla.gecko.annotation.RobocopTarget;
+
+public class LocalUrlAnnotations implements UrlAnnotations {
+    private Uri urlAnnotationsTableWithProfile;
+
+    public LocalUrlAnnotations(final String profile) {
+        urlAnnotationsTableWithProfile = DBUtils.appendProfile(profile, BrowserContract.UrlAnnotations.CONTENT_URI);
+    }
+
+    @RobocopTarget
+    @Override
+    public void insertAnnotation(final ContentResolver cr, final String url, final String key, final String value) {
+        final long creationTime = System.currentTimeMillis();
+        final ContentValues values = new ContentValues(5);
+        values.put(BrowserContract.UrlAnnotations.URL, url);
+        values.put(BrowserContract.UrlAnnotations.KEY, key);
+        values.put(BrowserContract.UrlAnnotations.VALUE, value);
+        values.put(BrowserContract.UrlAnnotations.DATE_CREATED, creationTime);
+        values.put(BrowserContract.UrlAnnotations.DATE_MODIFIED, creationTime);
+        cr.insert(urlAnnotationsTableWithProfile, values);
+    }
+}
--- a/mobile/android/base/java/org/mozilla/gecko/db/StubBrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/StubBrowserDB.java
@@ -145,25 +145,31 @@ class StubTabsAccessor implements TabsAc
     }
     public void getTabs(final Context context, final int limit, final OnQueryTabsCompleteListener listener) {
         listener.onQueryTabsComplete(new ArrayList<RemoteClient>());
     }
 
     public synchronized void persistLocalTabs(final ContentResolver cr, final Iterable<Tab> tabs) { }
 }
 
+class StubUrlAnnotations implements UrlAnnotations {
+    @Override
+    public void insertAnnotation(ContentResolver cr, String url, String key, String value) {}
+}
+
 /*
  * This base implementation just stubs all methods. For the
  * real implementations, see LocalBrowserDB.java.
  */
 public class StubBrowserDB implements BrowserDB {
     private final StubSearches searches = new StubSearches();
     private final StubTabsAccessor tabsAccessor = new StubTabsAccessor();
     private final StubURLMetadata urlMetadata = new StubURLMetadata();
     private final StubReadingListAccessor readingListAccessor = new StubReadingListAccessor();
+    private final StubUrlAnnotations urlAnnotations = new StubUrlAnnotations();
 
     @Override
     public Searches getSearches() {
         return searches;
     }
 
     @Override
     public TabsAccessor getTabsAccessor() {
@@ -175,16 +181,21 @@ public class StubBrowserDB implements Br
         return urlMetadata;
     }
 
     @Override
     public ReadingListAccessor getReadingListAccessor() {
         return readingListAccessor;
     }
 
+    @Override
+    public UrlAnnotations getUrlAnnotations() {
+        return urlAnnotations;
+    }
+
     protected static final Integer FAVICON_ID_NOT_FOUND = Integer.MIN_VALUE;
 
     public StubBrowserDB(String profile) {
     }
 
     public void invalidate() { }
 
     public int addDefaultBookmarks(Context context, ContentResolver cr, final int offset) {
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/db/UrlAnnotations.java
@@ -0,0 +1,12 @@
+/* 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 android.content.ContentResolver;
+import org.mozilla.gecko.annotation.RobocopTarget;
+
+public interface UrlAnnotations {
+    @RobocopTarget void insertAnnotation(ContentResolver cr, String url, String key, String value);
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -220,16 +220,17 @@ gbjar.sources += ['java/org/mozilla/geck
     'db/BrowserProvider.java',
     'db/DBUtils.java',
     'db/FormHistoryProvider.java',
     'db/HomeProvider.java',
     'db/LocalBrowserDB.java',
     'db/LocalReadingListAccessor.java',
     'db/LocalSearches.java',
     'db/LocalTabsAccessor.java',
+    'db/LocalUrlAnnotations.java',
     'db/LocalURLMetadata.java',
     'db/PasswordsProvider.java',
     'db/PerProfileDatabaseProvider.java',
     'db/PerProfileDatabases.java',
     'db/ReadingListAccessor.java',
     'db/ReadingListProvider.java',
     'db/RemoteClient.java',
     'db/RemoteTab.java',
@@ -238,16 +239,17 @@ gbjar.sources += ['java/org/mozilla/geck
     'db/SharedBrowserDatabaseProvider.java',
     'db/SQLiteBridgeContentProvider.java',
     'db/StubBrowserDB.java',
     'db/SuggestedSites.java',
     'db/Table.java',
     'db/TabsAccessor.java',
     'db/TabsProvider.java',
     'db/TopSitesCursorWrapper.java',
+    'db/UrlAnnotations.java',
     'db/URLMetadata.java',
     'db/URLMetadataTable.java',
     'DevToolsAuthHelper.java',
     'distribution/Distribution.java',
     'distribution/ReferrerDescriptor.java',
     'distribution/ReferrerReceiver.java',
     'dlc/BaseAction.java',
     'dlc/catalog/DownloadContent.java',