Bug 1301717 - Dispatch an event informing listeners that uri has been stored in history table r=sebastian
MozReview-Commit-ID: JHv6BO1rJsL
--- 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);
+ }
}