Bug 1301717 - Dispatch an event informing listeners that uri has been stored in history table r=sebastian draft
authorGrisha Kruglov <gkruglov@mozilla.com>
Thu, 27 Oct 2016 15:44:51 -0700
changeset 433465 790b43e02c6786bf4d1c094eed37a027cba34b98
parent 433464 181e39d55412288b511f687bb1d51009459fac4b
child 433466 37b1396e5471a4fde6eece6ae34955c48997cac5
child 433468 1375b1a47c0795ae0842bfc955584e710f199986
push id34588
push userbmo:gkruglov@mozilla.com
push dateThu, 03 Nov 2016 19:11:14 +0000
reviewerssebastian
bugs1301717
milestone52.0a1
Bug 1301717 - Dispatch an event informing listeners that uri has been stored in history table r=sebastian MozReview-Commit-ID: JHv6BO1rJsL
mobile/android/base/java/org/mozilla/gecko/GlobalHistory.java
--- a/mobile/android/base/java/org/mozilla/gecko/GlobalHistory.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GlobalHistory.java
@@ -13,23 +13,27 @@ import java.util.Set;
 
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.reader.ReaderModeUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.content.ContentResolver;
 import android.content.Context;
 import android.database.Cursor;
+import android.os.Bundle;
 import android.os.Handler;
 import android.os.SystemClock;
 import android.util.Log;
 
 class GlobalHistory {
     private static final String LOGTAG = "GeckoGlobalHistory";
 
+    public static final String EVENT_URI_AVAILABLE_IN_HISTORY = "URI_INSERTED_TO_HISTORY";
+    public static final String EVENT_PARAM_URI = "uri";
+
     private static final String TELEMETRY_HISTOGRAM_ADD = "FENNEC_GLOBALHISTORY_ADD_MS";
     private static final String TELEMETRY_HISTOGRAM_UPDATE = "FENNEC_GLOBALHISTORY_UPDATE_MS";
     private static final String TELEMETRY_HISTOGRAM_BUILD_VISITED_LINK = "FENNEC_GLOBALHISTORY_VISITED_BUILD_MS";
 
     private static final GlobalHistory sInstance = new GlobalHistory();
 
     static GlobalHistory getInstance() {
         return sInstance;
@@ -123,16 +127,17 @@ class GlobalHistory {
         final String uriToStore = ReaderModeUtils.stripAboutReaderUrl(uri);
 
         db.updateVisitedHistory(context.getContentResolver(), uriToStore);
 
         final long end = SystemClock.uptimeMillis();
         final long took = end - start;
         Telemetry.addToHistogram(TELEMETRY_HISTOGRAM_ADD, (int) Math.min(took, Integer.MAX_VALUE));
         addToGeckoOnly(uriToStore);
+        dispatchUriAvailableMessage(uri);
     }
 
     @SuppressWarnings("static-method")
     public void update(final ContentResolver cr, final BrowserDB db, String uri, String title) {
         ThreadUtils.assertOnBackgroundThread();
         final long start = SystemClock.uptimeMillis();
 
         final String uriToStore = ReaderModeUtils.stripAboutReaderUrl(uri);
@@ -159,9 +164,15 @@ class GlobalHistory {
                     // no need to post another
                     return;
                 }
                 mProcessing = true;
                 mHandler.postDelayed(runnable, BATCHING_DELAY_MS);
             }
         });
     }
+
+    private void dispatchUriAvailableMessage(String uri) {
+        final Bundle message = new Bundle();
+        message.putString(EVENT_PARAM_URI, uri);
+        EventDispatcher.getInstance().dispatch(EVENT_URI_AVAILABLE_IN_HISTORY, message);
+    }
 }