Bug 1258450 - Move GlobalHistory queries to GeckoInterface. r=snorp
authorNick Alexander <nalexander@mozilla.com>
Wed, 30 Mar 2016 10:21:29 -0700
changeset 291306 99c18eae6af0993af8e505f1d97a778cc336e6f7
parent 291305 ca6fcc658b21b559dc4eb25a34d267dc57baf521
child 291307 53b8d9973481a0795c30e6daeac2fae25f8b51ae
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1258450
milestone48.0a1
Bug 1258450 - Move GlobalHistory queries to GeckoInterface. r=snorp GlobalHistory is Fennec-specific: it accesses the Fennec history data store, and collects Telemetry. This allows other consumers to implement their own store as appropriate. MozReview-Commit-ID: 75Uxc5k8V0O
mobile/android/base/java/org/mozilla/gecko/BaseGeckoInterface.java
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
--- a/mobile/android/base/java/org/mozilla/gecko/BaseGeckoInterface.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BaseGeckoInterface.java
@@ -1,29 +1,25 @@
 /* -*- 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;
 
-import org.mozilla.gecko.AppConstants.Versions;
-import org.mozilla.gecko.prompts.PromptService;
 import org.mozilla.gecko.util.ActivityUtils;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Activity;
 import android.content.Context;
 import android.graphics.RectF;
 import android.hardware.SensorEventListener;
 import android.location.LocationListener;
 import android.view.View;
-import android.view.Window;
-import android.view.WindowManager;
 import android.widget.AbsoluteLayout;
 
 public class BaseGeckoInterface implements GeckoAppShell.GeckoInterface {
     // Bug 908744: Implement GeckoEventListener
     // Bug 908752: Implement SensorEventListener
     // Bug 908755: Implement LocationListener
     // Bug 908756: Implement Tabs.OnTabsChangedListener
     // Bug 908760: Implement GeckoEventResponder
@@ -140,9 +136,24 @@ public class BaseGeckoInterface implemen
     // Bug 908792: Implement this
     @Override
     public void invalidateOptionsMenu() {}
 
     @Override
     public void createShortcut(String title, String URI) {
         // By default, do nothing.
     }
+
+    @Override
+    public void checkUriVisited(String uri) {
+        // By default, no URIs are considered visited.
+    }
+
+    @Override
+    public void markUriVisited(final String uri) {
+        // By default, no URIs are marked as visited.
+    }
+
+    @Override
+    public void setUriTitle(final String uri, final String title) {
+        // By default, no titles are associated with URIs.
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -5,16 +5,17 @@
 
 package org.mozilla.gecko;
 
 import android.content.ContentResolver;
 import android.widget.AdapterView;
 import android.widget.Button;
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
+import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.URLMetadataTable;
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.gfx.FullScreenState;
 import org.mozilla.gecko.gfx.Layer;
 import org.mozilla.gecko.gfx.LayerView;
@@ -2755,9 +2756,38 @@ public abstract class GeckoApp
         // GeckoApp does not need to record any health information - return a stub.
         return new StubbedHealthRecorder();
     }
 
     protected StartupAction getStartupAction(final String passedURL, final String action) {
         // Default to NORMAL here. Subclasses can handle the other types.
         return StartupAction.NORMAL;
     }
+
+    @Override
+    public void checkUriVisited(String uri) {
+        GlobalHistory.getInstance().checkUriVisited(uri);
+    }
+
+    @Override
+    public void markUriVisited(final String uri) {
+        final Context context = getApplicationContext();
+        final BrowserDB db = GeckoProfile.get(context).getDB();
+        ThreadUtils.postToBackgroundThread(new Runnable() {
+            @Override
+            public void run() {
+                GlobalHistory.getInstance().add(context, db, uri);
+            }
+        });
+    }
+
+    @Override
+    public void setUriTitle(final String uri, final String title) {
+        final Context context = getApplicationContext();
+        final BrowserDB db = GeckoProfile.get(context).getDB();
+        ThreadUtils.postToBackgroundThread(new Runnable() {
+            @Override
+            public void run() {
+                GlobalHistory.getInstance().update(context.getContentResolver(), db, uri, title);
+            }
+        });
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
@@ -30,17 +30,16 @@ import java.util.StringTokenizer;
 import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
 
 import android.annotation.SuppressLint;
 import org.mozilla.gecko.annotation.JNITarget;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.AppConstants.Versions;
-import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.gfx.PanZoomController;
 import org.mozilla.gecko.mozglue.ContextUtils;
 import org.mozilla.gecko.overlays.ui.ShareDialog;
 import org.mozilla.gecko.permissions.Permissions;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoRequest;
@@ -2091,20 +2090,57 @@ public class GeckoAppShell
         public FormAssistPopup getFormAssistPopup();
         public boolean areTabsShown();
         public AbsoluteLayout getPluginContainer();
         public void notifyCheckUpdateResult(String result);
         public void invalidateOptionsMenu();
 
         /**
          * Create a shortcut -- generally a home-screen icon -- linking the given title to the given URI.
+         * <p>
+         * This method is always invoked on the Gecko thread.
+         *
          * @param title of URI to link to.
          * @param URI to link to.
          */
         public void createShortcut(String title, String URI);
+
+        /**
+         * Check if the given URI is visited.
+         * <p/>
+         * If it has been visited, call {@link GeckoAppShell#notifyUriVisited(String)}.  (If it
+         * has not been visited, do nothing.)
+         * <p/>
+         * This method is always invoked on the Gecko thread.
+         *
+         * @param uri to check.
+         */
+        public void checkUriVisited(String uri);
+
+        /**
+         * Mark the given URI as visited in Gecko.
+         * <p/>
+         * Implementors may maintain some local store of visited URIs in order to be able to
+         * answer {@link #checkUriVisited(String)} requests affirmatively.
+         * <p/>
+         * This method is always invoked on the Gecko thread.
+         *
+         * @param uri to mark.
+         */
+        public void markUriVisited(final String uri);
+
+        /**
+         * Set the title of the given URI, as determined by Gecko.
+         * <p/>
+         * This method is always invoked on the Gecko thread.
+         *
+         * @param uri given.
+         * @param title to associate with the given URI.
+         */
+        public void setUriTitle(final String uri, final String title);
     };
 
     private static GeckoInterface sGeckoInterface;
 
     public static GeckoInterface getGeckoInterface() {
         return sGeckoInterface;
     }
 
@@ -2254,41 +2290,39 @@ public class GeckoAppShell
 
     @WrapForJNI(stubName = "GetCurrentBatteryInformationWrapper")
     public static double[] getCurrentBatteryInformation() {
         return GeckoBatteryManager.getCurrentInformation();
     }
 
     @WrapForJNI(stubName = "CheckURIVisited")
     static void checkUriVisited(String uri) {
-        GlobalHistory.getInstance().checkUriVisited(uri);
+        final GeckoInterface geckoInterface = getGeckoInterface();
+        if (geckoInterface == null) {
+            return;
+        }
+        geckoInterface.checkUriVisited(uri);
     }
 
     @WrapForJNI(stubName = "MarkURIVisited")
     static void markUriVisited(final String uri) {
-        final Context context = getApplicationContext();
-        final BrowserDB db = GeckoProfile.get(context).getDB();
-        ThreadUtils.postToBackgroundThread(new Runnable() {
-            @Override
-            public void run() {
-                GlobalHistory.getInstance().add(context, db, uri);
-            }
-        });
+        final GeckoInterface geckoInterface = getGeckoInterface();
+        if (geckoInterface == null) {
+            return;
+        }
+        geckoInterface.markUriVisited(uri);
     }
 
     @WrapForJNI(stubName = "SetURITitle")
     static void setUriTitle(final String uri, final String title) {
-        final Context context = getApplicationContext();
-        final BrowserDB db = GeckoProfile.get(context).getDB();
-        ThreadUtils.postToBackgroundThread(new Runnable() {
-            @Override
-            public void run() {
-                GlobalHistory.getInstance().update(context.getContentResolver(), db, uri, title);
-            }
-        });
+        final GeckoInterface geckoInterface = getGeckoInterface();
+        if (geckoInterface == null) {
+            return;
+        }
+        geckoInterface.setUriTitle(uri, title);
     }
 
     @WrapForJNI
     static void hideProgressDialog() {
         // unused stub
     }
 
     /*