Bug 1270213 - Update TelemetryPing & builders to use docID. r=sebastian

Future patches will change the remaining code - This is not yet expected
to compile.

MozReview-Commit-ID: FpqfThcV7dj

--HG--
extra : rebase_source : e01ea217aadd88853d6643c5642d866ba796aa81
This commit is contained in:
Michael Comella 2016-05-05 16:32:40 -07:00
Родитель 00cba0fcf9
Коммит efe06ac7a9
5 изменённых файлов: 20 добавлений и 27 удалений

Просмотреть файл

@ -10,9 +10,8 @@ import org.mozilla.gecko.sync.ExtendedJSONObject;
/**
* Container for telemetry data and the data necessary to upload it.
*
* The unique ID is used by a Store to manipulate its internal pings. Some ping
* payloads already contain a unique ID (e.g. sequence number in core ping) and
* this field can mirror that value.
* The doc ID is used by a Store to manipulate its internal pings and should
* be the same value found in the urlPath.
*
* If you want to create one of these, consider extending
* {@link org.mozilla.gecko.telemetry.pingbuilders.TelemetryPingBuilder}
@ -21,15 +20,15 @@ import org.mozilla.gecko.sync.ExtendedJSONObject;
public class TelemetryPing {
private final String urlPath;
private final ExtendedJSONObject payload;
private final int uniqueID;
private final String docID;
public TelemetryPing(final String urlPath, final ExtendedJSONObject payload, final int uniqueID) {
public TelemetryPing(final String urlPath, final ExtendedJSONObject payload, final String docID) {
this.urlPath = urlPath;
this.payload = payload;
this.uniqueID = uniqueID;
this.docID = docID;
}
public String getURLPath() { return urlPath; }
public ExtendedJSONObject getPayload() { return payload; }
public int getUniqueID() { return uniqueID; }
public String getDocID() { return docID; }
}

Просмотреть файл

@ -72,11 +72,11 @@ public class UploadTelemetryCorePingCallback implements SearchEngineManager.Sear
// Each profile can have different telemetry data so we intentionally grab the shared prefs for the profile.
final SharedPreferences sharedPrefs = GeckoSharedPrefs.forProfileName(activity, profile.getName());
final int sequenceNumber = TelemetryCorePingBuilder.getAndIncrementSequenceNumber(sharedPrefs);
final TelemetryCorePingBuilder pingBuilder = new TelemetryCorePingBuilder(activity, sequenceNumber)
final TelemetryCorePingBuilder pingBuilder = new TelemetryCorePingBuilder(activity)
.setClientID(clientID)
.setDefaultSearchEngine(TelemetryCorePingBuilder.getEngineIdentifier(engine))
.setProfileCreationDate(TelemetryCorePingBuilder.getProfileCreationDate(activity, profile));
.setProfileCreationDate(TelemetryCorePingBuilder.getProfileCreationDate(activity, profile))
.setSequenceNumber(TelemetryCorePingBuilder.getAndIncrementSequenceNumber(sharedPrefs));
final String distributionId = sharedPrefs.getString(DistributionStoreCallback.PREF_DISTRIBUTION_ID, null);
if (distributionId != null) {
pingBuilder.setOptDistributionID(distributionId);

Просмотреть файл

@ -53,13 +53,11 @@ public class TelemetryCorePingBuilder extends TelemetryPingBuilder {
private static final String OS_VERSION = "osversion";
private static final String PING_CREATION_DATE = "created";
private static final String PROFILE_CREATION_DATE = "profileDate";
public static final String SEQ = "seq";
private static final String SEQ = "seq";
private static final String TIMEZONE_OFFSET = "tz";
private static final String VERSION_ATTR = "v";
public TelemetryCorePingBuilder(final Context context, final int sequenceNumber) {
super(sequenceNumber);
setSequenceNumber(sequenceNumber);
public TelemetryCorePingBuilder(final Context context) {
initPayloadConstants(context);
}
@ -149,11 +147,12 @@ public class TelemetryCorePingBuilder extends TelemetryPingBuilder {
/**
* @param seq a positive sequence number.
*/
private void setSequenceNumber(final int seq) {
public TelemetryCorePingBuilder setSequenceNumber(final int seq) {
if (seq < 0) {
throw new IllegalArgumentException("Expected positive sequence number. Recived: " + seq);
}
payload.put(SEQ, seq);
return this;
}
/**

Просмотреть файл

@ -27,12 +27,12 @@ abstract class TelemetryPingBuilder {
private final String serverPath;
protected final ExtendedJSONObject payload;
private final int uniqueID;
private final String docID;
public TelemetryPingBuilder(final int uniqueID) {
serverPath = getTelemetryServerPath(getDocType());
public TelemetryPingBuilder() {
docID = UUID.randomUUID().toString();
serverPath = getTelemetryServerPath(getDocType(), docID);
payload = new ExtendedJSONObject();
this.uniqueID = uniqueID;
}
/**
@ -48,7 +48,7 @@ abstract class TelemetryPingBuilder {
public TelemetryPing build() {
validatePayload();
return new TelemetryPing(serverPath, payload, uniqueID);
return new TelemetryPing(serverPath, payload, docID);
}
private void validatePayload() {
@ -68,8 +68,7 @@ abstract class TelemetryPingBuilder {
* @param docType The name of the ping (e.g. "main")
* @return a url at which to POST the telemetry data to
*/
private static String getTelemetryServerPath(final String docType) {
final String docId = UUID.randomUUID().toString();
private static String getTelemetryServerPath(final String docType, final String docID) {
final String appName = AppConstants.MOZ_APP_BASENAME;
final String appVersion = AppConstants.MOZ_APP_VERSION;
final String appUpdateChannel = AppConstants.MOZ_UPDATE_CHANNEL;
@ -78,7 +77,7 @@ abstract class TelemetryPingBuilder {
// The compiler will optimize a single String concatenation into a StringBuilder statement.
// If you change this `return`, be sure to keep it as a single statement to keep it optimized!
return SERVER_INITIAL_PATH + '/' +
docId + '/' +
docID + '/' +
docType + '/' +
appName + '/' +
appVersion + '/' +

Просмотреть файл

@ -40,8 +40,6 @@ public class TestTelemetryPingBuilder {
}
private static class NoMandatoryFieldsBuilder extends TelemetryPingBuilder {
public NoMandatoryFieldsBuilder() { super(1); }
@Override
public String getDocType() {
return "";
@ -61,8 +59,6 @@ public class TestTelemetryPingBuilder {
private static class MandatoryFieldsBuilder extends TelemetryPingBuilder {
private static final String MANDATORY_FIELD = "mandatory-field";
public MandatoryFieldsBuilder() { super(0); }
@Override
public String getDocType() {
return "";