Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(979)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java

Issue 2882693002: Custom Tabs: add speculation status histograms. (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/enums.xml » ('j') | tools/metrics/histograms/enums.xml » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
index e956f15e993554de848da6485ceea32ff6d9ec4e..cb9040775ec53900d51503eb94ed19ad5fee3b96 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
@@ -80,6 +80,30 @@ public class CustomTabsConnection {
@VisibleForTesting
static final String PAGE_LOAD_METRICS_CALLBACK = "NavigationMetrics";
+ // For CustomTabs.SpeculationStatusOnStart, see tools/metrics/enums.xml. Append only.
+ private static final int SPECULATION_STATUS_ON_START_ALLOWED = 0;
+ // What kind of speculation was started, counted in addition to
+ // SPECULATION_STATUS_ALLOWED.
+ private static final int SPECULATION_STATUS_ON_START_PREFETCH = 1;
+ private static final int SPECULATION_STATUS_ON_START_PRERENDER = 2;
+ private static final int SPECULATION_STATUS_ON_START_BACKGROUND_TAB = 3;
+ private static final int SPECULATION_STATUS_ON_START_PRERENDER_NOT_STARTED = 4;
+ // The following describe reasons why a speculation was aborted at some point, and are
+ // counted instead of SPECULATION_STATUS_ALLOWED.
+ private static final int SPECULATION_STATUS_ON_START_ABORTED_DEVICE_CLASS = 5;
+ private static final int SPECULATION_STATUS_ON_START_ABORTED_BLOCK_3RD_PARTY_COOKIES = 6;
+ private static final int SPECULATION_STATUS_ON_START_ABORTED_NETWORK_PREDICTION_DISABLED = 7;
+ private static final int SPECULATION_STATUS_ON_START_ABORTED_DATA_REDUCTION_ENABLED = 8;
+ private static final int SPECULATION_STATUS_ON_START_ABORTED_NETWORK_METERED = 9;
+ private static final int SPECULATION_STATUS_ON_START_MAX = 10;
+
+ // For CustomTabs.SpeculationStatusOnSwap, see tools/metrics/enums.xml. Append only.
+ private static final int SPECULATION_STATUS_ON_SWAP_BACKGROUND_TAB_TAKEN = 0;
+ private static final int SPECULATION_STATUS_ON_SWAP_BACKGROUND_TAB_NOT_MATCHED = 1;
+ private static final int SPECULATION_STATUS_ON_SWAP_PRERENDER_TAKEN = 2;
+ private static final int SPECULATION_STATUS_ON_SWAP_PRERENDER_NOT_MATCHED = 3;
+ private static final int SPECULATION_STATUS_ON_SWAP_MAX = 4;
+
// For testing only, DO NOT USE.
@VisibleForTesting
static final String DEBUG_OVERRIDE_KEY =
@@ -616,9 +640,11 @@ public class CustomTabsConnection {
&& UrlUtilities.urlsMatchIgnoringFragments(prerenderedUrl, url));
WebContents result = null;
if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) {
+ recordSpeculationStatusOnSwap(SPECULATION_STATUS_ON_SWAP_PRERENDER_TAKEN);
result = webContents;
mSpeculation = null;
} else {
+ recordSpeculationStatusOnSwap(SPECULATION_STATUS_ON_SWAP_PRERENDER_NOT_MATCHED);
cancelSpeculation(session);
}
if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) {
@@ -671,8 +697,11 @@ public class CustomTabsConnection {
&& UrlUtilities.urlsMatchIgnoringFragments(speculatedUrl, url));
if (referrer == null) referrer = "";
if (urlsMatch && TextUtils.equals(speculationReferrer, referrer)) {
+ recordSpeculationStatusOnSwap(SPECULATION_STATUS_ON_SWAP_BACKGROUND_TAB_TAKEN);
return tab;
} else {
+ recordSpeculationStatusOnSwap(
+ SPECULATION_STATUS_ON_SWAP_BACKGROUND_TAB_NOT_MATCHED);
tab.destroy();
}
}
@@ -953,19 +982,36 @@ public class CustomTabsConnection {
}
@VisibleForTesting
- boolean maySpeculate(CustomTabsSessionToken session) {
- if (!DeviceClassManager.enablePrerendering()) return false;
+ int maySpeculateWithResult(CustomTabsSessionToken session) {
+ if (!DeviceClassManager.enablePrerendering()) {
+ return SPECULATION_STATUS_ON_START_ABORTED_DEVICE_CLASS;
+ }
PrefServiceBridge prefs = PrefServiceBridge.getInstance();
- if (prefs.isBlockThirdPartyCookiesEnabled()) return false;
- // TODO(yusufo): The check for prerender in PrivacyManager now checks for the network
- // connection type as well, we should either change that or add another check for custom
- // tabs. Then PrivacyManager should be used to make the below check.
- if (!prefs.getNetworkPredictionEnabled()) return false;
- if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return false;
+ if (prefs.isBlockThirdPartyCookiesEnabled()) {
+ return SPECULATION_STATUS_ON_START_ABORTED_BLOCK_3RD_PARTY_COOKIES;
+ }
+ // TODO(yusufo): The check for prerender in PrivacyPreferencesManager now checks for the
+ // network connection type as well, we should either change that or add another check for
+ // custom tabs. Then PrivacyManager should be used to make the below check.
+ if (!prefs.getNetworkPredictionEnabled()) {
+ return SPECULATION_STATUS_ON_START_ABORTED_NETWORK_PREDICTION_DISABLED;
+ }
+ if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) {
+ return SPECULATION_STATUS_ON_START_ABORTED_DATA_REDUCTION_ENABLED;
+ }
ConnectivityManager cm =
(ConnectivityManager) mApplication.getApplicationContext().getSystemService(
Context.CONNECTIVITY_SERVICE);
- return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSession(session);
+ if (cm.isActiveNetworkMetered() && !shouldPrerenderOnCellularForSession(session)) {
+ return SPECULATION_STATUS_ON_START_ABORTED_NETWORK_METERED;
+ }
+ return SPECULATION_STATUS_ON_START_ALLOWED;
+ }
+
+ boolean maySpeculate(CustomTabsSessionToken session) {
+ int speculationResult = maySpeculateWithResult(session);
+ recordSpeculationStatusOnStart(speculationResult);
+ return speculationResult == SPECULATION_STATUS_ON_START_ALLOWED;
}
/** Cancels the speculation for a given session, or any session if null. */
@@ -1006,14 +1052,19 @@ public class CustomTabsConnection {
switch (speculationMode) {
case SpeculationParams.PREFETCH:
boolean didPrefetch = new LoadingPredictor(profile).prepareForPageLoad(url);
+ recordSpeculationStatusOnStart(SPECULATION_STATUS_ON_START_PREFETCH);
if (didPrefetch) mSpeculation = SpeculationParams.forPrefetch(session, url);
preconnect = !didPrefetch;
break;
case SpeculationParams.PRERENDER:
boolean didPrerender = prerenderUrl(session, url, extras, uid);
+ recordSpeculationStatusOnStart(didPrerender
+ ? SPECULATION_STATUS_ON_START_PRERENDER
+ : SPECULATION_STATUS_ON_START_PRERENDER_NOT_STARTED);
createSpareWebContents = !didPrerender;
break;
case SpeculationParams.HIDDEN_TAB:
+ recordSpeculationStatusOnStart(SPECULATION_STATUS_ON_START_BACKGROUND_TAB);
launchUrlInHiddenTab(session, url, extras);
break;
default:
@@ -1145,4 +1196,14 @@ public class CustomTabsConnection {
if (referrer == null) referrer = "";
return referrer;
}
+
+ private static void recordSpeculationStatusOnStart(int status) {
+ RecordHistogram.recordEnumeratedHistogram(
+ "CustomTabs.SpeculationStatusOnStart", status, SPECULATION_STATUS_ON_START_MAX);
+ }
+
+ private static void recordSpeculationStatusOnSwap(int status) {
+ RecordHistogram.recordEnumeratedHistogram(
+ "CustomTabs.SpeculationStatusOnSwap", status, SPECULATION_STATUS_ON_SWAP_MAX);
+ }
}
« no previous file with comments | « no previous file | tools/metrics/histograms/enums.xml » ('j') | tools/metrics/histograms/enums.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698