Commit 449a75ae authored by Michael Crouse's avatar Michael Crouse Committed by Commit Bot

Add rounded SiteEngagementScore for the navigation URL to the UKM.

Add rounded SiteEngagementScore for the navigation URL to the UKM.
The SiteEngagementScore is obtained in from the SiteEngagementService, rounded
up/down to nearest multiple of 10, and added to the UKM during
TimingMetricsReporting. Needed to understand how first contentful paint (FCP)
varies with SiteEngagementScore, and if it’s possible to predict slow page
loads using SiteEngagementScore.



Bug: 930999
Change-Id: I0f4231d4b9e41da972b2c5b8ed7abff11064ce11
Reviewed-on: https://chromium-review.googlesource.com/c/1471334Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Michael Crouse <mcrouse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634394}
parent 76e4800c
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
#include "chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_observer.h" #include "chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_observer.h"
#include <cmath>
#include <memory> #include <memory>
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_util.h" #include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/metrics/net/network_metrics_provider.h" #include "components/metrics/net/network_metrics_provider.h"
#include "content/public/browser/web_contents.h"
#include "net/base/load_timing_info.h" #include "net/base/load_timing_info.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "services/metrics/public/cpp/metrics_utils.h" #include "services/metrics/public/cpp/metrics_utils.h"
...@@ -46,6 +49,8 @@ UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnStart( ...@@ -46,6 +49,8 @@ UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnStart(
return CONTINUE_OBSERVING; return CONTINUE_OBSERVING;
} }
browser_context_ = navigation_handle->GetWebContents()->GetBrowserContext();
// When OnStart is invoked, we don't yet know whether we're observing a web // When OnStart is invoked, we don't yet know whether we're observing a web
// page load, vs another kind of load (e.g. a download or a PDF). Thus, // page load, vs another kind of load (e.g. a download or a PDF). Thus,
// metrics and source information should not be recorded here. Instead, we // metrics and source information should not be recorded here. Instead, we
...@@ -161,6 +166,13 @@ void UkmPageLoadMetricsObserver::RecordTimingMetrics( ...@@ -161,6 +166,13 @@ void UkmPageLoadMetricsObserver::RecordTimingMetrics(
const page_load_metrics::mojom::PageLoadTiming& timing, const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info) { const page_load_metrics::PageLoadExtraInfo& info) {
ukm::builders::PageLoad builder(info.source_id); ukm::builders::PageLoad builder(info.source_id);
base::Optional<int64_t> rounded_site_engagement_score =
GetRoundedSiteEngagementScore(info);
if (rounded_site_engagement_score) {
builder.SetSiteEngagementScore(rounded_site_engagement_score.value());
}
if (timing.input_to_navigation_start) { if (timing.input_to_navigation_start) {
builder.SetExperimental_InputToNavigationStart( builder.SetExperimental_InputToNavigationStart(
timing.input_to_navigation_start.value().InMilliseconds()); timing.input_to_navigation_start.value().InMilliseconds());
...@@ -420,3 +432,27 @@ void UkmPageLoadMetricsObserver::ReportLayoutStability( ...@@ -420,3 +432,27 @@ void UkmPageLoadMetricsObserver::ReportLayoutStability(
UMA_HISTOGRAM_COUNTS_100("PageLoad.Experimental.LayoutStability.JankScore", UMA_HISTOGRAM_COUNTS_100("PageLoad.Experimental.LayoutStability.JankScore",
uma_value); uma_value);
} }
base::Optional<int64_t>
UkmPageLoadMetricsObserver::GetRoundedSiteEngagementScore(
const page_load_metrics::PageLoadExtraInfo& info) const {
if (!browser_context_)
return base::nullopt;
Profile* profile = Profile::FromBrowserContext(browser_context_);
SiteEngagementService* engagement_service =
SiteEngagementService::Get(profile);
// UKM privacy requires the engagement score be rounded to nearest
// value of 10.
int64_t rounded_document_engagement_score =
static_cast<int>(
std::roundf(engagement_service->GetScore(info.url) / 10.0)) *
10;
DCHECK(rounded_document_engagement_score >= 0 &&
rounded_document_engagement_score <=
engagement_service->GetMaxPoints());
return rounded_document_engagement_score;
}
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
#include "services/metrics/public/cpp/ukm_source.h" #include "services/metrics/public/cpp/ukm_source.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
namespace content {
class BrowserContext;
}
namespace network { namespace network {
class NetworkQualityTracker; class NetworkQualityTracker;
} }
...@@ -85,6 +89,11 @@ class UkmPageLoadMetricsObserver ...@@ -85,6 +89,11 @@ class UkmPageLoadMetricsObserver
void ReportLayoutStability(const page_load_metrics::PageLoadExtraInfo& info); void ReportLayoutStability(const page_load_metrics::PageLoadExtraInfo& info);
// Captures the site engagement score for the commited URL and
// returns the score rounded to the nearest 10.
base::Optional<int64_t> GetRoundedSiteEngagementScore(
const page_load_metrics::PageLoadExtraInfo& info) const;
// Guaranteed to be non-null during the lifetime of |this|. // Guaranteed to be non-null during the lifetime of |this|.
network::NetworkQualityTracker* network_quality_tracker_; network::NetworkQualityTracker* network_quality_tracker_;
...@@ -119,6 +128,9 @@ class UkmPageLoadMetricsObserver ...@@ -119,6 +128,9 @@ class UkmPageLoadMetricsObserver
// The number of main frame redirects that occurred before commit. // The number of main frame redirects that occurred before commit.
uint32_t main_frame_request_redirect_count_ = 0; uint32_t main_frame_request_redirect_count_ = 0;
// The browser context this navigation is operating in.
content::BrowserContext* browser_context_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(UkmPageLoadMetricsObserver); DISALLOW_COPY_AND_ASSIGN(UkmPageLoadMetricsObserver);
}; };
......
...@@ -257,6 +257,8 @@ IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NewPage) { ...@@ -257,6 +257,8 @@ IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NewPage) {
EXPECT_TRUE(test_ukm_recorder_->EntryHasMetric( EXPECT_TRUE(test_ukm_recorder_->EntryHasMetric(
kv.second.get(), kv.second.get(),
PageLoad::kMainFrameResource_NavigationStartToRequestStartName)); PageLoad::kMainFrameResource_NavigationStartToRequestStartName));
EXPECT_TRUE(test_ukm_recorder_->EntryHasMetric(
kv.second.get(), PageLoad::kSiteEngagementScoreName));
} }
// Verify that NoPageLoadMetricsRecorded returns false when PageLoad metrics // Verify that NoPageLoadMetricsRecorded returns false when PageLoad metrics
......
...@@ -3827,6 +3827,14 @@ be describing additional metrics about the same event. ...@@ -3827,6 +3827,14 @@ be describing additional metrics about the same event.
start to the time the parser started, for main frame documents. start to the time the parser started, for main frame documents.
</summary> </summary>
</metric> </metric>
<metric name="SiteEngagementScore">
<owner>mcrouse@chromium.org</owner>
<owner>tbansal@chromium.org</owner>
<summary>
Measures the Site Engagement Score for the commited URL rounded to the
nearest 10.
</summary>
</metric>
<metric name="WasCached"> <metric name="WasCached">
<summary> <summary>
Set to 1 if the main resource was served from cache. Set to 1 if the main resource was served from cache.
......
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