Commit 14c57c5a authored by Robbie McElrath's avatar Robbie McElrath Committed by Commit Bot

[AW] Remove SeedInfo.date fallback logic

We changed how we store the seed date in October 2019 and included
fallback logic to handle the old date format. This CL removes that
logic now that the change has been in prod for a (long) while.

Bug: 1013390
Change-Id: Ie860871aa77c7d1018f62559742045b3238a1342
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317717Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792820}
parent 0dba726a
...@@ -22,7 +22,6 @@ import java.io.File; ...@@ -22,7 +22,6 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -112,9 +111,8 @@ public class VariationsUtils { ...@@ -112,9 +111,8 @@ public class VariationsUtils {
return null; return null;
} }
if (!proto.hasSignature() || !proto.hasCountry() if (!proto.hasSignature() || !proto.hasCountry() || !proto.hasDate()
|| (!proto.hasDate() && !proto.hasDateHeader()) || !proto.hasIsGzipCompressed() || !proto.hasIsGzipCompressed() || !proto.hasSeedData()) {
|| !proto.hasSeedData()) {
return null; return null;
} }
...@@ -123,23 +121,12 @@ public class VariationsUtils { ...@@ -123,23 +121,12 @@ public class VariationsUtils {
info.country = proto.getCountry(); info.country = proto.getCountry();
info.isGzipCompressed = proto.getIsGzipCompressed(); info.isGzipCompressed = proto.getIsGzipCompressed();
info.seedData = proto.getSeedData().toByteArray(); info.seedData = proto.getSeedData().toByteArray();
info.date = proto.getDate();
if (proto.hasDate()) {
info.date = proto.getDate();
} else {
// |dateHeader| is deprecated in favor of |date|, but parse |dateHeader| in case
// this seed predates the deprecation.
// TODO(crbug.com/1013390): Remove this fallback logic.
info.date = SeedInfo.parseDateHeader(proto.getDateHeader());
}
return info; return info;
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Failed reading seed file \"" + inFile + "\": " + e.getMessage()); Log.e(TAG, "Failed reading seed file \"" + inFile + "\": " + e.getMessage());
return null; return null;
} catch (ParseException e) {
Log.e(TAG, "Malformed seed date: " + e.getMessage());
return null;
} finally { } finally {
closeSafely(in); closeSafely(in);
} }
......
...@@ -9,9 +9,6 @@ import android.util.Base64; ...@@ -9,9 +9,6 @@ import android.util.Base64;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.components.variations.firstrun.VariationsSeedFetcher.SeedInfo;
import java.text.ParseException;
/** /**
* VariationsSeedBridge is a class which is used to pass variations first run seed that was fetched * VariationsSeedBridge is a class which is used to pass variations first run seed that was fetched
...@@ -23,7 +20,6 @@ public class VariationsSeedBridge { ...@@ -23,7 +20,6 @@ public class VariationsSeedBridge {
protected static final String VARIATIONS_FIRST_RUN_SEED_BASE64 = "variations_seed_base64"; protected static final String VARIATIONS_FIRST_RUN_SEED_BASE64 = "variations_seed_base64";
protected static final String VARIATIONS_FIRST_RUN_SEED_SIGNATURE = "variations_seed_signature"; protected static final String VARIATIONS_FIRST_RUN_SEED_SIGNATURE = "variations_seed_signature";
protected static final String VARIATIONS_FIRST_RUN_SEED_COUNTRY = "variations_seed_country"; protected static final String VARIATIONS_FIRST_RUN_SEED_COUNTRY = "variations_seed_country";
protected static final String VARIATIONS_FIRST_RUN_SEED_DATE_HEADER = "variations_seed_date";
protected static final String VARIATIONS_FIRST_RUN_SEED_DATE = "variations_seed_date_ms"; protected static final String VARIATIONS_FIRST_RUN_SEED_DATE = "variations_seed_date_ms";
protected static final String VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED = protected static final String VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED =
"variations_seed_is_gzip_compressed"; "variations_seed_is_gzip_compressed";
...@@ -81,7 +77,6 @@ public class VariationsSeedBridge { ...@@ -81,7 +77,6 @@ public class VariationsSeedBridge {
.remove(VARIATIONS_FIRST_RUN_SEED_SIGNATURE) .remove(VARIATIONS_FIRST_RUN_SEED_SIGNATURE)
.remove(VARIATIONS_FIRST_RUN_SEED_COUNTRY) .remove(VARIATIONS_FIRST_RUN_SEED_COUNTRY)
.remove(VARIATIONS_FIRST_RUN_SEED_DATE) .remove(VARIATIONS_FIRST_RUN_SEED_DATE)
.remove(VARIATIONS_FIRST_RUN_SEED_DATE_HEADER)
.remove(VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED) .remove(VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED)
.apply(); .apply();
logDebugHistogram(DEBUG_PREFS_CLEARED); logDebugHistogram(DEBUG_PREFS_CLEARED);
...@@ -133,21 +128,7 @@ public class VariationsSeedBridge { ...@@ -133,21 +128,7 @@ public class VariationsSeedBridge {
@CalledByNative @CalledByNative
private static long getVariationsFirstRunSeedDate() { private static long getVariationsFirstRunSeedDate() {
long date = return ContextUtils.getAppSharedPreferences().getLong(VARIATIONS_FIRST_RUN_SEED_DATE, 0);
ContextUtils.getAppSharedPreferences().getLong(VARIATIONS_FIRST_RUN_SEED_DATE, 0);
if (date > 0) return date;
// VARIATIONS_FIRST_RUN_SEED_DATE_HEADER is deprecated in favor of
// VARIATIONS_FIRST_RUN_SEED_DATE, but fall back on the old value in case the prefs were
// written by an old version.
// TODO(crbug.com/1013390): Remove this fallback logic.
String header = getVariationsFirstRunSeedPref(VARIATIONS_FIRST_RUN_SEED_DATE_HEADER);
if (header.isEmpty()) return 0;
try {
return SeedInfo.parseDateHeader(header);
} catch (ParseException e) {
// Shouldn't happen as the date will have been verified in VariationsSeedFetcher.
throw new RuntimeException("Invalid date in first run seed pref", e);
}
} }
@CalledByNative @CalledByNative
......
...@@ -26,11 +26,8 @@ import java.net.MalformedURLException; ...@@ -26,11 +26,8 @@ import java.net.MalformedURLException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Locale;
/** /**
* Fetches the variations seed before the actual first run of Chrome. * Fetches the variations seed before the actual first run of Chrome.
...@@ -152,17 +149,6 @@ public class VariationsSeedFetcher { ...@@ -152,17 +149,6 @@ public class VariationsSeedFetcher {
public boolean isGzipCompressed; public boolean isGzipCompressed;
public byte[] seedData; public byte[] seedData;
// TODO(crbug.com/1013390): Delete once Date header to timestamp migration is done (~M81).
@Deprecated
public static long parseDateHeader(String header) throws ParseException {
// The date field comes from the HTTP "Date" header, which has this format.
// (See RFC 2616, sections 3.3.1 and 14.18.) SimpleDateFormat is weirdly not
// thread-safe, so instantiate a new one for each call.
return new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US)
.parse(header)
.getTime();
}
@Override @Override
public String toString() { public String toString() {
if (BuildConfig.DCHECK_IS_ON) { if (BuildConfig.DCHECK_IS_ON) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment