Commit 4c99354d authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding data savings reporting to Previews URLLoader

This CL adds reporting Data savings based on original content length
header vs content length header in the HTTPS Server previews URLLoader
implementation.

Bug: 921757
Change-Id: I38ac67b43b3fd1bc17f27a4ec7e0a8a65229cc81
Reviewed-on: https://chromium-review.googlesource.com/c/1488062
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarRobert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635736}
parent f4644489
...@@ -1258,8 +1258,6 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest, ...@@ -1258,8 +1258,6 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest,
IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest, IN_PROC_BROWSER_TEST_P(PreviewsLitePageServerBrowserTest,
DISABLE_ON_WIN_MAC(LitePagePreviewsReportSavings)) { DISABLE_ON_WIN_MAC(LitePagePreviewsReportSavings)) {
if (GetParam())
return;
PrefService* prefs = browser()->profile()->GetPrefs(); PrefService* prefs = browser()->profile()->GetPrefs();
prefs->SetBoolean(data_reduction_proxy::prefs::kDataUsageReportingEnabled, prefs->SetBoolean(data_reduction_proxy::prefs::kDataUsageReportingEnabled,
true); true);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/previews/previews_lite_page_serving_url_loader.h" #include "chrome/browser/previews/previews_lite_page_serving_url_loader.h"
#include <stdint.h>
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -88,6 +89,33 @@ void SetServerUnavailableFor(base::TimeDelta duration, int frame_tree_node_id) { ...@@ -88,6 +89,33 @@ void SetServerUnavailableFor(base::TimeDelta duration, int frame_tree_node_id) {
frame_tree_node_id)); frame_tree_node_id));
} }
void ReportDataSavingsOnUIThread(int64_t network_bytes,
int64_t original_bytes,
std::string host,
int frame_tree_node_id) {
auto* web_contents =
content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
// If the WebContents has been closed this may be null.
if (!web_contents)
return;
static_cast<PreviewsLitePageNavigationThrottleManager*>(
PreviewsServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext()))
->previews_lite_page_decider())
->ReportDataSavings(network_bytes, original_bytes, host);
}
void ReportDataSavings(int64_t network_bytes,
int64_t original_bytes,
std::string host,
int frame_tree_node_id) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&ReportDataSavingsOnUIThread, network_bytes,
original_bytes, std::move(host), frame_tree_node_id));
}
const base::TimeDelta kBlacklistDuration = base::TimeDelta::FromDays(30); const base::TimeDelta kBlacklistDuration = base::TimeDelta::FromDays(30);
// Used for mojo pipe size. Same constant as navigation code. // Used for mojo pipe size. Same constant as navigation code.
...@@ -275,6 +303,17 @@ void PreviewsLitePageServingURLLoader::OnReceiveResponse( ...@@ -275,6 +303,17 @@ void PreviewsLitePageServingURLLoader::OnReceiveResponse(
resource_response_ = base::MakeRefCounted<network::ResourceResponse>(); resource_response_ = base::MakeRefCounted<network::ResourceResponse>();
resource_response_->head = head; resource_response_->head = head;
const int64_t ofcl =
data_reduction_proxy::GetDataReductionProxyOFCL(response_headers);
if (ofcl > 0) {
std::string original_url;
previews::ExtractOriginalURLFromLitePageRedirectURL(previews_url_,
&original_url);
ReportDataSavings(response_headers->GetContentLength(), ofcl,
GURL(original_url).host(), frame_tree_node_id_);
}
url_loader_binding_.PauseIncomingMethodCallProcessing(); url_loader_binding_.PauseIncomingMethodCallProcessing();
std::move(result_callback_) std::move(result_callback_)
.Run(ServingLoaderResult::kSuccess, base::nullopt, nullptr); .Run(ServingLoaderResult::kSuccess, base::nullopt, nullptr);
......
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