Log NavigationPredictor metrics when links enter the viewport.

NavigationPredictorAnchorElementMetrics will now be logged only for
links that enter the viewport. Links that are inserted after onload
will also be reported.Only a fraction (1% by default) of links entering
the viewport are reported.

Aggregate statistic on all links on the page
(NavigationPredictorPageLinkMetrics) will now be reported for all
links on the page (regardless of whether then enter the viewport),
including links inserted after onload.

Also remove obsolete Prefetching code in NavigationPredictor.
Now that we have Speculation Rules, prefetching code should be distinct
from link click prediction. Also we already have prefetching logic for
the prefetch proxy in chrome/browser/prefetch/prefetch_proxy. Despite
the name, most of that code is not proxy specific. If we want to
reintroduce non-proxied prefetching, that code can likely be
generalized.

Bug: 1157161, 1199367
Change-Id: Ie6f718bec09fc1e69415dce620a1164b07b20381
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2724978
Commit-Queue: Simon Pelchat <spelchat@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: Robert Kaplow <rkaplow@chromium.org>
Reviewed-by: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#875463}
GitOrigin-RevId: 60e8ab3f3be7eef75f5b43ba8d01a2136ff0f85b
diff --git a/metrics/histograms/histograms_xml/navigation/histograms.xml b/metrics/histograms/histograms_xml/navigation/histograms.xml
index ed14d7b..aedf93d 100644
--- a/metrics/histograms/histograms_xml/navigation/histograms.xml
+++ b/metrics/histograms/histograms_xml/navigation/histograms.xml
@@ -1191,6 +1191,9 @@
 
 <histogram base="true" name="NavigationPredictor.ActionTaken"
     enum="NavigationPredictorActionTaken" expires_after="M85">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>tbansal@chromium.org</owner>
   <summary>
     Tracks action taken by navigation predictor. Recorded at the time of page
@@ -1200,6 +1203,9 @@
 
 <histogram base="true" name="NavigationPredictor.CountOfStartedPrerenders"
     units="count" expires_after="M85">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>tbansal@chromium.org</owner>
   <owner>ryansturm@chromium.org</owner>
   <summary>
@@ -1211,6 +1217,9 @@
 
 <histogram base="true" name="NavigationPredictor.CountOfURLsAboveThreshold"
     units="count" expires_after="M85">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>tbansal@chromium.org</owner>
   <owner>ryansturm@chromium.org</owner>
   <summary>
@@ -1222,6 +1231,9 @@
 
 <histogram base="true" name="NavigationPredictor.CountOfURLsInPredictedSet"
     units="count" expires_after="M89">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>tbansal@chromium.org</owner>
   <owner>ryansturm@chromium.org</owner>
   <summary>
@@ -1248,6 +1260,9 @@
 
 <histogram name="NavigationPredictor.IsPubliclyRoutable" enum="Boolean"
     expires_after="2021-08-22">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>tbansal@chromium.org</owner>
   <owner>ryansturm@chromium.org</owner>
   <summary>
@@ -1259,6 +1274,9 @@
 
 <histogram base="true" name="NavigationPredictor.LinkClickedPrerenderResult"
     enum="NavigationPredictorLinkClickedPrerenderResult" expires_after="M85">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>ryansturm@chromium.org</owner>
   <owner>tbansal@chromium.org</owner>
   <summary>
@@ -1271,6 +1289,9 @@
 <histogram
     name="NavigationPredictor.SearchEnginePreconnector.IsBrowserAppLikelyInForeground"
     enum="BooleanForeground" expires_after="M95">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>tbansal@chromium.org</owner>
   <owner>ryansturm@chromium.org</owner>
   <summary>
diff --git a/metrics/histograms/histograms_xml/others/histograms.xml b/metrics/histograms/histograms_xml/others/histograms.xml
index f7c1d37..77fbe2d 100644
--- a/metrics/histograms/histograms_xml/others/histograms.xml
+++ b/metrics/histograms/histograms_xml/others/histograms.xml
@@ -437,6 +437,9 @@
 
 <histogram name="AnchorElementMetrics.Clicked.OnDSE.SameHost"
     enum="BooleanAnchorElementSameHost" expires_after="2021-08-09">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>tbansal@chromium.org</owner>
   <summary>
     True if the target link of the anchor element has the same host as the root
@@ -446,6 +449,9 @@
 
 <histogram name="AnchorElementMetrics.Clicked.OnNonDSE.SameHost"
     enum="BooleanAnchorElementSameHost" expires_after="2021-08-22">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>tbansal@chromium.org</owner>
   <owner>ryansturm@chromium.org</owner>
   <owner>src/chrome/browser/navigation_predictor/OWNERS</owner>
@@ -458,6 +464,9 @@
 
 <histogram base="true" name="AnchorElementMetrics.IsSameHost" enum="Boolean"
     expires_after="2021-05-21">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>chelu@chromium.org</owner>
   <owner>tbansal@chromium.org</owner>
   <summary>
@@ -468,6 +477,9 @@
 
 <histogram name="AnchorElementMetrics.Visible.NumberOfAnchorElementsAfterMerge"
     units="count" expires_after="2021-04-26">
+  <obsolete>
+    Removed 04/2020.
+  </obsolete>
   <owner>chelu@chromium.org</owner>
   <owner>tbansal@chromium.org</owner>
   <summary>
diff --git a/metrics/ukm/ukm.xml b/metrics/ukm/ukm.xml
index 99e99d2..a23bb25 100644
--- a/metrics/ukm/ukm.xml
+++ b/metrics/ukm/ukm.xml
@@ -2209,6 +2209,12 @@
 
     This event is not recorded on machines with low-resolution clocks.
   </summary>
+  <metric name="AnchorElementMetricsIntersectionObserver">
+    <summary>
+      Time spent computing IntersectionObservations for anchor elements, in
+      microseconds.
+    </summary>
+  </metric>
   <metric name="Animate">
     <summary>
       The time spent in main frame animation, between navigation and First
@@ -2456,6 +2462,26 @@
 
     This event is not recorded on machines with low-resolution clocks.
   </summary>
+  <metric name="AnchorElementMetricsIntersectionObserver">
+    <summary>
+      Time spent computing IntersectionObservations for anchor elements, in
+      microseconds.
+    </summary>
+    <aggregation>
+      <history>
+        <index fields="profile.country"/>
+        <statistics>
+          <quantiles type="std-percentiles"/>
+        </statistics>
+      </history>
+    </aggregation>
+  </metric>
+  <metric name="AnchorElementMetricsIntersectionObserverBeginMainFrame">
+    <summary>
+      The total main frame time used to compute IntersectionObservations for
+      anchor elements, in microseconds.
+    </summary>
+  </metric>
   <metric name="Animate">
     <summary>
       The time taken for main frame animation in microseconds during the sampled
@@ -9840,12 +9866,22 @@
 <event name="NavigationPredictorPageLinkClick">
   <owner>ryansturm@chromium.org</owner>
   <summary>
-    Sent on an in-page link click. An integer from 0-10 (1-indexed),
-    corresponding to the index of that anchor element in the list of top ten
-    anchor elements on that page, sorted by their navigation scores. If an
-    anchor element is clicked that is not on the top ten list, 0 is returned.
+    Sent on an in-page link click.
   </summary>
-  <metric name="AnchorElementIndex"/>
+  <metric name="AnchorElementIndex">
+    <summary>
+      An integer (0-indexed), corresponding to the index of that anchor element
+      in the list of top ten anchor elements on that page, sorted by their
+      navigation scores. If an anchor element is clicked that is not in
+      NavigationPredictorAnchorElementMetrics, -1 is returned.
+    </summary>
+  </metric>
+  <metric name="HrefUnchanged">
+    <summary>
+      1 if the href of the anchor element at the time the click is handled is
+      the same as the href when the element was created. 0 if the href changed.
+    </summary>
+  </metric>
 </event>
 
 <event name="NavigationPredictorPageLinkMetrics" singular="True">