Commit d023a00e authored by asvitkine's avatar asvitkine Committed by Commit bot

Re-land "Add histograms that monitor variation seed fetching from Java."

No changes from original CL:
https://codereview.chromium.org/2426343004/

The dependency CL has been relanded as:
https://codereview.chromium.org/2439113002/

BUG=632199
TBR=rkaplow@chromium.org

Review-Url: https://chromiumcodereview.appspot.com/2442823002
Cr-Commit-Position: refs/heads/master@{#426895}
parent 7829c011
......@@ -6,15 +6,19 @@ package org.chromium.components.variations.firstrun;
import android.app.IntentService;
import android.content.Intent;
import android.os.SystemClock;
import org.chromium.base.Log;
import org.chromium.base.metrics.CachedMetrics.SparseHistogramSample;
import org.chromium.base.metrics.CachedMetrics.TimesHistogramSample;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
/**
* Background service that fetches the variations seed before the actual first run of Chrome.
......@@ -27,6 +31,12 @@ public class VariationsSeedService extends IntentService {
private static final int READ_TIMEOUT = 10000; // time in ms
private static final int REQUEST_TIMEOUT = 15000; // time in ms
// Values for the "Variations.FirstRun.SeedFetchResult" sparse histogram, which also logs
// HTTP result codes. These are negative so that they don't conflict with the HTTP codes.
// These values should not be renumbered or re-used since they are logged to UMA.
private static final int SEED_FETCH_RESULT_TIMEOUT = -2;
private static final int SEED_FETCH_RESULT_IOEXCEPTION = -1;
// Static variable that indicates a status of the variations seed fetch. If one request is in
// progress, we do not start another fetch.
private static boolean sFetchInProgress = false;
......@@ -45,9 +55,7 @@ public class VariationsSeedService extends IntentService {
}
setFetchInProgressFlagValue(true);
try {
downloadContent(new URL(VARIATIONS_SERVER_URL));
} catch (MalformedURLException e) {
Log.w(TAG, "Variations server URL is malformed.", e);
downloadContent();
} finally {
setFetchInProgressFlagValue(false);
}
......@@ -59,16 +67,32 @@ public class VariationsSeedService extends IntentService {
sFetchInProgress = value;
}
private boolean downloadContent(URL variationsServerUrl) {
private void recordFetchResultOrCode(int resultOrCode) {
SparseHistogramSample histogram =
new SparseHistogramSample("Variations.FirstRun.SeedFetchResult");
histogram.record(resultOrCode);
}
private void recordSeedFetchTime(long timeDeltaMillis) {
Log.i(TAG, "Fetched first run seed in " + timeDeltaMillis + " ms");
TimesHistogramSample histogram = new TimesHistogramSample(
"Variations.FirstRun.SeedFetchTime", TimeUnit.MILLISECONDS);
histogram.record(timeDeltaMillis);
}
private boolean downloadContent() {
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) variationsServerUrl.openConnection();
long startTimeMillis = SystemClock.elapsedRealtime();
URL url = new URL(VARIATIONS_SERVER_URL);
connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(READ_TIMEOUT);
connection.setConnectTimeout(REQUEST_TIMEOUT);
connection.setDoInput(true);
connection.setRequestProperty("A-IM", "gzip");
connection.connect();
int responseCode = connection.getResponseCode();
recordFetchResultOrCode(responseCode);
if (responseCode != HttpURLConnection.HTTP_OK) {
Log.w(TAG, "Non-OK response code = %d", responseCode);
return false;
......@@ -82,8 +106,14 @@ public class VariationsSeedService extends IntentService {
boolean isGzipCompressed = getHeaderFieldOrEmpty(connection, "IM").equals("gzip");
VariationsSeedBridge.setVariationsFirstRunSeed(
getApplicationContext(), rawSeed, signature, country, date, isGzipCompressed);
recordSeedFetchTime(SystemClock.elapsedRealtime() - startTimeMillis);
return true;
} catch (SocketTimeoutException e) {
recordFetchResultOrCode(SEED_FETCH_RESULT_TIMEOUT);
Log.w(TAG, "SocketTimeoutException fetching first run seed: ", e);
return false;
} catch (IOException e) {
recordFetchResultOrCode(SEED_FETCH_RESULT_IOEXCEPTION);
Log.w(TAG, "IOException fetching first run seed: ", e);
return false;
} finally {
......
......@@ -67824,6 +67824,24 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>
<histogram name="Variations.FirstRun.SeedFetchResult"
enum="VariationsFirstRunSeedFetchResult">
<owner>asvitkine@chromium.org</owner>
<summary>
The result of attempting to fetch an initial variations seed during Android
Chrome first run. Records both the HTTP code and various error values in one
enumeration.
</summary>
</histogram>
<histogram name="Variations.FirstRun.SeedFetchTime" units="ms">
<owner>asvitkine@chromium.org</owner>
<summary>
The latency of fetching an initial variations seed during Android Chrome
first run. Only considers cases where an HTTP 200 result was received.
</summary>
</histogram>
<histogram name="Variations.FirstRunResult" enum="VariationsFirstRunResult">
<owner>asvitkine@chromium.org</owner>
<summary>
......@@ -102109,6 +102127,50 @@ value.
<int value="3" label="Seed import failed - failed to store seed"/>
</enum>
<enum name="VariationsFirstRunSeedFetchResult" type="int">
<int value="-2" label="Timeout fetching seed"/>
<int value="-1" label="IOException fetching seed"/>
<int value="200" label="200: OK"/>
<int value="201" label="201: Created"/>
<int value="202" label="202: Accepted"/>
<int value="203" label="203: Non-Authoritative Information"/>
<int value="204" label="204: No Content"/>
<int value="205" label="205: Reset Content"/>
<int value="206" label="206: Partial Content"/>
<int value="300" label="300: Multiple Choices"/>
<int value="301" label="301: Moved Permanently"/>
<int value="302" label="302: Found"/>
<int value="303" label="303: See Other"/>
<int value="304" label="304: Not Modified"/>
<int value="305" label="305: Use Proxy"/>
<int value="306" label="306: (Unused)"/>
<int value="307" label="307: Temporary Redirect"/>
<int value="400" label="400: Bad Request"/>
<int value="401" label="401: Unauthorized"/>
<int value="402" label="402: Payment Required"/>
<int value="403" label="403: Forbidden"/>
<int value="404" label="404: Not Found"/>
<int value="405" label="405: Method Not Allowed"/>
<int value="406" label="406: Not Acceptable"/>
<int value="407" label="407: Proxy Authentication Required"/>
<int value="408" label="408: Request Timeout"/>
<int value="409" label="409: Conflict"/>
<int value="410" label="410: Gone"/>
<int value="411" label="411: Length Required"/>
<int value="412" label="412: Precondition Failed"/>
<int value="413" label="413: Request Entity Too Large"/>
<int value="414" label="414: Request-URI Too Long"/>
<int value="415" label="415: Unsupported Media Type"/>
<int value="416" label="416: Requested Range Not Satisfiable"/>
<int value="417" label="417: Expectation Failed"/>
<int value="500" label="500: Internal Server Error"/>
<int value="501" label="501: Not Implemented"/>
<int value="502" label="502: Bad Gateway"/>
<int value="503" label="503: Service Unavailable"/>
<int value="504" label="504: Gateway Timeout"/>
<int value="505" label="505: HTTP Version Not Supported"/>
</enum>
<enum name="VariationsPermanentConsistencyCountryResult" type="int">
<int value="0" label="Saved pref missing and no country code in seed"/>
<int value="1" label="Saved pref missing and country code in seed"/>
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