Commit 21fe97f0 authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

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: default avatarRobert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636282}
parent 2c8d17a4
......@@ -37,7 +37,11 @@ DataSaverSiteBreakdownMetricsObserver::OnCommit(
// will be called is in MetricsWebContentsObserver's destructor, which is
// called in WebContents destructor.
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;
}
......
......@@ -1312,7 +1312,8 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest,
ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com"));
EXPECT_EQ(GetTotalOriginalContentLength() - GetTotalDataUsage(), 40U);
EXPECT_EQ(GetDataUsage(), 20U);
// Headers, etc. will make data usage larger than content length.
EXPECT_LE(20U, GetDataUsage());
}
IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest,
......
......@@ -340,11 +340,14 @@ void PreviewsLitePageDecider::ReportDataSavings(int64_t network_bytes,
if (!drp_settings_ || !drp_settings_->data_reduction_proxy_service())
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(
network_bytes, original_bytes, host);
0, data_saved, host);
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::
VIA_DATA_REDUCTION_PROXY,
"text/html", true /* is_user_traffic */,
......
......@@ -38,7 +38,8 @@ class PreviewsLitePageNavigationThrottleManager {
// Generates a new page id for a request to the previews server.
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,
int64_t original_bytes,
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