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 0e71b3ea77e622d1756d6bca214cac7c0d676f32..b50f5f849ff29cf6a3890ae0d8b1e718633d76b2 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,32 @@ public class CustomTabsConnection { |
@VisibleForTesting |
static final String PAGE_LOAD_METRICS_CALLBACK = "NavigationMetrics"; |
+ // For CustomTabs.SpeculationStatus, see histograms.xml. Append only. |
+ private static final String SPECULATION_STATUS_TAG = "CustomTabs.SpeculationStatus"; |
+ // Speculation is allowed, but may not have been used. |
+ private static final int SPECULATION_STATUS_ALLOWED = 0; |
+ // What kind of speculation was started, counted in addition to |
+ // SPECULATION_STATUS_ALLOWED. |
+ private static final int SPECULATION_STATUS_PREFETCH = 1; |
+ private static final int SPECULATION_STATUS_PRERENDER = 2; |
+ private static final int SPECULATION_STATUS_BACKGROUND_TAB = 3; |
pasko
2017/05/15 12:56:14
Putting these into the same histogram makes it har
mattcary
2017/05/15 13:47:19
What exactly do you mean here? Can you provide an
pasko
2017/05/15 15:26:26
we have two potentially distant moments in time:
1
|
+ // Whether a background tab is used. These are counted in addition to |
+ // SPECULATION_STATUS_ALLOWED. |
+ private static final int SPECULATION_STATUS_BACKGROUND_TAB_TAKEN = 4; |
+ private static final int SPECULATION_STATUS_BACKGROUND_TAB_NOT_MATCHED = 5; |
+ // Status of a prerender. These are counted in addition to SPECULATION_STATUS_ALLOWED. |
+ private static final int SPECULATION_STATUS_PRERENDER_NOT_STARTED = 6; |
+ private static final int SPECULATION_STATUS_PRERENDER_TAKEN = 7; |
+ private static final int SPECULATION_STATUS_PRERENDER_NOT_MATCHED = 8; |
+ // 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_ABORTED_DEVICE_CLASS = 9; |
+ private static final int SPECULATION_STATUS_ABORTED_BLOCK_3RD_PARTY_COOKIES = 10; |
+ private static final int SPECULATION_STATUS_ABORTED_NETWORK_PREDICTION_DISABLED = 11; |
+ private static final int SPECULATION_STATUS_ABORTED_DATA_REDUCTION_ENABLED = 12; |
+ private static final int SPECULATION_STATUS_ABORTED_NETWORK_METERED = 13; |
+ private static final int SPECULATION_STATUS_MAX = 14; |
+ |
// For testing only, DO NOT USE. |
@VisibleForTesting |
static final String DEBUG_OVERRIDE_KEY = |
@@ -616,9 +642,13 @@ public class CustomTabsConnection { |
&& UrlUtilities.urlsMatchIgnoringFragments(prerenderedUrl, url)); |
WebContents result = null; |
if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) { |
+ RecordHistogram.recordEnumeratedHistogram(SPECULATION_STATUS_TAG, |
pasko
2017/05/15 12:56:14
it would be nice to shorten this common call as so
mattcary
2017/05/16 07:51:10
Done.
|
+ SPECULATION_STATUS_PRERENDER_TAKEN, SPECULATION_STATUS_MAX); |
result = webContents; |
mSpeculation = null; |
} else { |
+ RecordHistogram.recordEnumeratedHistogram(SPECULATION_STATUS_TAG, |
+ SPECULATION_STATUS_PRERENDER_NOT_MATCHED, SPECULATION_STATUS_MAX); |
cancelSpeculation(session); |
} |
if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) { |
@@ -671,8 +701,12 @@ public class CustomTabsConnection { |
&& UrlUtilities.urlsMatchIgnoringFragments(speculatedUrl, url)); |
if (referrer == null) referrer = ""; |
if (urlsMatch && TextUtils.equals(speculationReferrer, referrer)) { |
+ RecordHistogram.recordEnumeratedHistogram(SPECULATION_STATUS_TAG, |
+ SPECULATION_STATUS_BACKGROUND_TAB_TAKEN, SPECULATION_STATUS_MAX); |
return tab; |
} else { |
+ RecordHistogram.recordEnumeratedHistogram(SPECULATION_STATUS_TAG, |
+ SPECULATION_STATUS_BACKGROUND_TAB_NOT_MATCHED, SPECULATION_STATUS_MAX); |
tab.destroy(); |
} |
} |
@@ -953,19 +987,37 @@ public class CustomTabsConnection { |
} |
@VisibleForTesting |
- boolean maySpeculate(CustomTabsSessionToken session) { |
- if (!DeviceClassManager.enablePrerendering()) return false; |
+ int maySpeculateWithResult(CustomTabsSessionToken session) { |
+ if (!DeviceClassManager.enablePrerendering()) { |
+ return SPECULATION_STATUS_ABORTED_DEVICE_CLASS; |
+ } |
PrefServiceBridge prefs = PrefServiceBridge.getInstance(); |
- if (prefs.isBlockThirdPartyCookiesEnabled()) return false; |
+ if (prefs.isBlockThirdPartyCookiesEnabled()) { |
+ return SPECULATION_STATUS_ABORTED_BLOCK_3RD_PARTY_COOKIES; |
+ } |
// TODO(yusufo): The check for prerender in PrivacyManager now checks for the network |
pasko
2017/05/15 12:56:14
I think Yusuf wanted to say 'PrivacyPreferencesMan
mattcary
2017/05/16 07:51:10
Done.
|
// 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.getNetworkPredictionEnabled()) { |
+ return SPECULATION_STATUS_ABORTED_NETWORK_PREDICTION_DISABLED; |
+ } |
+ if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) { |
+ return SPECULATION_STATUS_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_ABORTED_NETWORK_METERED; |
+ } |
+ return SPECULATION_STATUS_ALLOWED; |
+ } |
+ |
+ boolean maySpeculate(CustomTabsSessionToken session) { |
+ int speculationResult = maySpeculateWithResult(session); |
+ RecordHistogram.recordEnumeratedHistogram( |
+ SPECULATION_STATUS_TAG, speculationResult, SPECULATION_STATUS_MAX); |
+ return speculationResult == SPECULATION_STATUS_ALLOWED; |
} |
/** Cancels the speculation for a given session, or any session if null. */ |
@@ -1005,15 +1057,25 @@ public class CustomTabsConnection { |
} |
switch (speculationMode) { |
case SpeculationParams.PREFETCH: |
+ RecordHistogram.recordEnumeratedHistogram(SPECULATION_STATUS_TAG, |
+ SPECULATION_STATUS_PREFETCH, SPECULATION_STATUS_MAX); |
boolean didPrefetch = new ResourcePrefetchPredictor(profile).startPrefetching(url); |
if (didPrefetch) mSpeculation = SpeculationParams.forPrefetch(session, url); |
preconnect = !didPrefetch; |
break; |
case SpeculationParams.PRERENDER: |
+ RecordHistogram.recordEnumeratedHistogram(SPECULATION_STATUS_TAG, |
+ SPECULATION_STATUS_PRERENDER, SPECULATION_STATUS_MAX); |
boolean didPrerender = prerenderUrl(session, url, extras, uid); |
+ if (!didPrerender) { |
+ RecordHistogram.recordEnumeratedHistogram(SPECULATION_STATUS_TAG, |
+ SPECULATION_STATUS_PRERENDER_NOT_STARTED, SPECULATION_STATUS_MAX); |
+ } |
createSpareWebContents = !didPrerender; |
break; |
case SpeculationParams.HIDDEN_TAB: |
+ RecordHistogram.recordEnumeratedHistogram(SPECULATION_STATUS_TAG, |
+ SPECULATION_STATUS_BACKGROUND_TAB, SPECULATION_STATUS_MAX); |
launchUrlInHiddenTab(session, url, extras); |
break; |
default: |