Commit f18cb859 authored by Sofiya Semenova's avatar Sofiya Semenova Committed by Commit Bot

In NavigationPredictor, send the top URLs in a page to the UKM

based on the area rank of the URLs and not on their navigation scores.

Bug: 995600
Change-Id: I2f043cf1859b0b335b0f672b9ffc2b93c3e65c01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761429Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Sofiya Semenova <sofiyase@google.com>
Cr-Commit-Position: refs/heads/master@{#690072}
parent 6f1712f5
...@@ -475,7 +475,7 @@ void NavigationPredictor::MaybeSendMetricsToUkm() const { ...@@ -475,7 +475,7 @@ void NavigationPredictor::MaybeSendMetricsToUkm() const {
ukm::builders::NavigationPredictorAnchorElementMetrics ukm::builders::NavigationPredictorAnchorElementMetrics
anchor_element_builder(ukm_source_id_); anchor_element_builder(ukm_source_id_);
std::string url = top_urls_[i]; std::string url = top_urls_[i].spec();
auto iter = navigation_scores_map_.find(url); auto iter = navigation_scores_map_.find(url);
if (iter != navigation_scores_map_.end()) { if (iter != navigation_scores_map_.end()) {
...@@ -829,6 +829,16 @@ void NavigationPredictor::ReportAnchorElementMetricsOnLoad( ...@@ -829,6 +829,16 @@ void NavigationPredictor::ReportAnchorElementMetricsOnLoad(
return a->ratio_area > b->ratio_area; return a->ratio_area > b->ratio_area;
}); });
// Store either the top 10 links (or all the links, if the page
// contains fewer than 10 links), in |top_urls_|. Then, shuffle the
// list to randomize data sent to the UKM.
int top_urls_size = std::min(10, static_cast<int>(metrics.size()));
top_urls_.reserve(top_urls_size);
for (int i = 0; i < top_urls_size; i++) {
top_urls_.push_back(metrics[i]->target_url);
}
base::RandomShuffle(top_urls_.begin(), top_urls_.end());
// Loop |metrics| to compute navigation scores. // Loop |metrics| to compute navigation scores.
std::vector<std::unique_ptr<NavigationScore>> navigation_scores; std::vector<std::unique_ptr<NavigationScore>> navigation_scores;
navigation_scores.reserve(metrics.size()); navigation_scores.reserve(metrics.size());
...@@ -888,23 +898,14 @@ void NavigationPredictor::ReportAnchorElementMetricsOnLoad( ...@@ -888,23 +898,14 @@ void NavigationPredictor::ReportAnchorElementMetricsOnLoad(
MaybeTakeActionOnLoad(document_origin_, navigation_scores); MaybeTakeActionOnLoad(document_origin_, navigation_scores);
// Store navigation scores in |navigation_scores_map_| for fast look up upon // Store navigation scores in |navigation_scores_map_| for fast look up upon
// clicks. Store either the top 10 links (or all the links, if the page // clicks.
// contains fewer than 10 links, in |top_urls_|.
navigation_scores_map_.reserve(navigation_scores.size()); navigation_scores_map_.reserve(navigation_scores.size());
top_urls_.reserve(std::min(10, static_cast<int>(navigation_scores.size())));
for (size_t i = 0; i != navigation_scores.size(); ++i) { for (size_t i = 0; i != navigation_scores.size(); ++i) {
navigation_scores[i]->score_rank = base::make_optional(i); navigation_scores[i]->score_rank = base::make_optional(i);
std::string url_spec = navigation_scores[i]->url.spec(); std::string url_spec = navigation_scores[i]->url.spec();
navigation_scores_map_[url_spec] = std::move(navigation_scores[i]); navigation_scores_map_[url_spec] = std::move(navigation_scores[i]);
if (i < 10) {
top_urls_.push_back(url_spec);
}
} }
// Shuffle the list of top URLs to randomize data sent to the UKM about which
// link was clicked on.
base::RandomShuffle(top_urls_.begin(), top_urls_.end());
MaybeSendMetricsToUkm(); MaybeSendMetricsToUkm();
} }
......
...@@ -227,7 +227,7 @@ class NavigationPredictor : public blink::mojom::AnchorElementMetricsHost, ...@@ -227,7 +227,7 @@ class NavigationPredictor : public blink::mojom::AnchorElementMetricsHost,
// The urls of the top anchor elements in the page, in a random order. // The urls of the top anchor elements in the page, in a random order.
// If there are 10 or more urls on the page, |top_urls_| contains 10 urls. // If there are 10 or more urls on the page, |top_urls_| contains 10 urls.
// Otherwise, it contains all the urls. // Otherwise, it contains all the urls.
std::vector<std::string> top_urls_; std::vector<GURL> top_urls_;
// Total number of anchors that: href has the same host as the document, // Total number of anchors that: href has the same host as the document,
// contains image, inside an iframe, href incremented by 1 from document url. // contains image, inside an iframe, href incremented by 1 from document url.
......
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