Commit 4992de92 authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Reland "Stop over-recording data use related to Previews"

This is a reland of 21fe97f0

Original change's description:
> Stop over-recording data use related to Previews
> 
> Lite Page Server Previews over records data use when it attempts to
> record data savings. Instead, only the savings should be recorded.
> 
> This also changes the data usage site breakdown code to use Virtual URL
> (the one in the omnibox) instead of the actual host for the sake of
> improving UI and tracking HTTPS Lite Page Previews more accurately.
> 
> Bug: 936577
> Change-Id: Ib7dfe8afeea0b277ac065d58c02b2962a4ab6c94
> Reviewed-on: https://chromium-review.googlesource.com/c/1492428
> Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
> Reviewed-by: Robert Ogden <robertogden@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#636282}

Bug: 936577
Change-Id: I342de5853cea0ffced06af1ac531846cdd1cc34b
Reviewed-on: https://chromium-review.googlesource.com/c/1494797Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636545}
parent a3f67947
...@@ -37,7 +37,11 @@ DataSaverSiteBreakdownMetricsObserver::OnCommit( ...@@ -37,7 +37,11 @@ DataSaverSiteBreakdownMetricsObserver::OnCommit(
// will be called is in MetricsWebContentsObserver's destructor, which is // will be called is in MetricsWebContentsObserver's destructor, which is
// called in WebContents destructor. // called in WebContents destructor.
browser_context_ = navigation_handle->GetWebContents()->GetBrowserContext(); browser_context_ = navigation_handle->GetWebContents()->GetBrowserContext();
committed_host_ = navigation_handle->GetURL().HostNoBrackets();
// Use Virtual URL instead of actual host.
committed_host_ = navigation_handle->GetWebContents()
->GetLastCommittedURL()
.HostNoBrackets();
return CONTINUE_OBSERVING; return CONTINUE_OBSERVING;
} }
......
...@@ -1307,12 +1307,13 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest, ...@@ -1307,12 +1307,13 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest,
ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kSuccess)); ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kSuccess));
VerifyPreviewLoaded(); VerifyPreviewLoaded();
base::RunLoop().RunUntilIdle();
// Navigate to an untracked (no preview) page before checking reported savings // Navigate to an untracked (no preview) page before checking reported savings
// to reduce flakiness. // to reduce flakiness.
ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com")); ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
EXPECT_EQ(GetTotalOriginalContentLength() - GetTotalDataUsage(), 40U); EXPECT_EQ(GetTotalOriginalContentLength() - GetTotalDataUsage(), 40U);
EXPECT_EQ(GetDataUsage(), 20U);
} }
IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest, IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest,
......
...@@ -340,11 +340,14 @@ void PreviewsLitePageDecider::ReportDataSavings(int64_t network_bytes, ...@@ -340,11 +340,14 @@ void PreviewsLitePageDecider::ReportDataSavings(int64_t network_bytes,
if (!drp_settings_ || !drp_settings_->data_reduction_proxy_service()) if (!drp_settings_ || !drp_settings_->data_reduction_proxy_service())
return; return;
// The total data usage is tracked for all data in Chrome, so we only need to
// update the savings.
int64_t data_saved = original_bytes - network_bytes;
drp_settings_->data_reduction_proxy_service()->UpdateDataUseForHost( drp_settings_->data_reduction_proxy_service()->UpdateDataUseForHost(
network_bytes, original_bytes, host); 0, data_saved, host);
drp_settings_->data_reduction_proxy_service()->UpdateContentLengths( drp_settings_->data_reduction_proxy_service()->UpdateContentLengths(
network_bytes, original_bytes, true /* data_reduction_proxy_enabled */, 0, data_saved, true /* data_reduction_proxy_enabled */,
data_reduction_proxy::DataReductionProxyRequestType:: data_reduction_proxy::DataReductionProxyRequestType::
VIA_DATA_REDUCTION_PROXY, VIA_DATA_REDUCTION_PROXY,
"text/html", true /* is_user_traffic */, "text/html", true /* is_user_traffic */,
......
...@@ -38,7 +38,8 @@ class PreviewsLitePageNavigationThrottleManager { ...@@ -38,7 +38,8 @@ class PreviewsLitePageNavigationThrottleManager {
// Generates a new page id for a request to the previews server. // Generates a new page id for a request to the previews server.
virtual uint64_t GeneratePageID() = 0; virtual uint64_t GeneratePageID() = 0;
// Reports data savings to Data Saver. // Reports data savings to Data Saver. Only the difference in |original_bytes|
// and |network_bytes| will be updated in the data saver calls.
virtual void ReportDataSavings(int64_t network_bytes, virtual void ReportDataSavings(int64_t network_bytes,
int64_t original_bytes, int64_t original_bytes,
const std::string& host) = 0; const std::string& host) = 0;
......
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