Bug 1042951 - Part 2: allow for delayed recording of searches with FHR. r=margaret

This commit is contained in:
Richard Newman 2014-10-07 17:52:21 -07:00
parent a6f8911b76
commit 6d7da5da76
4 changed files with 45 additions and 0 deletions

View File

@ -1910,6 +1910,7 @@ public abstract class GeckoApp
final HealthRecorder rec = mHealthRecorder;
if (rec != null) {
rec.setCurrentSession(currentSession);
rec.processDelayed();
} else {
Log.w(LOGTAG, "Can't record session: rec is null.");
}

View File

@ -17,6 +17,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONException;
@ -899,4 +900,42 @@ public class BrowserHealthRecorder implements HealthRecorder, GeckoEventListener
// double-counted on next run.
session.recordCompletion(editor);
}
private static class Search {
public final String location;
public final String engineID;
public Search(final String location, final String engineID) {
if (!SEARCH_LOCATIONS.contains(location)) {
throw new IllegalArgumentException("Unknown search location: " + location);
}
this.location = location;
this.engineID = engineID;
}
}
private static ConcurrentLinkedQueue<Search> delayedSearches = new ConcurrentLinkedQueue<>();
public static void recordSearchDelayed(String location, String engineID) {
final Search search = new Search(location, engineID);
delayedSearches.add(search);
}
@Override
public void processDelayed() {
if (delayedSearches.isEmpty()) {
return;
}
if (this.state != State.INITIALIZED) {
Log.d(LOG_TAG, "Not initialized: not processing delayed items. (" + this.state + ")");
return;
}
Search poll;
while ((poll = delayedSearches.poll()) != null) {
recordSearch(poll.engineID, poll.location);
}
}
}

View File

@ -34,4 +34,6 @@ public interface HealthRecorder {
public void onEnvironmentChanged(final boolean startNewSession, final String sessionEndReason);
public void close();
public void processDelayed();
}

View File

@ -32,4 +32,7 @@ public class StubbedHealthRecorder implements HealthRecorder {
public void onEnvironmentChanged(final boolean startNewSession, final String sessionEndReason) { }
public void close() { }
@Override
public void processDelayed() { }
}