Commit 5047692d authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Reporting UMA and pingback for cached DRP responses

This CL adds detection of cached DRP responses for the purpose of making
different previews types (with different cache affinities) easier to
compare.

A follow-up will add whether the main frame response was cached or not
to the PLM pingback proto.

Bug: 880655
Change-Id: I1591d2f10823514648bb05bd0d26cb7ae97a7244
Reviewed-on: https://chromium-review.googlesource.com/1208938
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589364}
parent 3e174935
......@@ -145,8 +145,10 @@ DataReductionProxyMetricsObserver::OnCommit(
return STOP_OBSERVING;
data_reduction_proxy::DataReductionProxyData* data =
chrome_navigation_data->GetDataReductionProxyData();
if (!data || !data->used_data_reduction_proxy())
if (!data || !(data->used_data_reduction_proxy() ||
data->was_cached_data_reduction_proxy_response())) {
return STOP_OBSERVING;
}
data_ = data->DeepCopy();
previews::PreviewsUserData* previews_data =
......
......@@ -127,11 +127,13 @@ class TestDataReductionProxyMetricsObserver
TestDataReductionProxyMetricsObserver(content::WebContents* web_contents,
TestPingbackClient* pingback_client,
bool data_reduction_proxy_used,
bool cached_data_reduction_proxy_used,
bool lite_page_used,
bool black_listed)
: web_contents_(web_contents),
pingback_client_(pingback_client),
data_reduction_proxy_used_(data_reduction_proxy_used),
cached_data_reduction_proxy_used_(cached_data_reduction_proxy_used),
lite_page_used_(lite_page_used),
black_listed_(black_listed) {}
......@@ -143,6 +145,8 @@ class TestDataReductionProxyMetricsObserver
DataReductionProxyData* data =
DataForNavigationHandle(web_contents_, navigation_handle);
data->set_used_data_reduction_proxy(data_reduction_proxy_used_);
data->set_was_cached_data_reduction_proxy_response(
cached_data_reduction_proxy_used_);
data->set_request_url(GURL(kDefaultTestUrl));
data->set_lite_page_received(lite_page_used_);
......@@ -180,6 +184,7 @@ class TestDataReductionProxyMetricsObserver
content::WebContents* web_contents_;
TestPingbackClient* pingback_client_;
bool data_reduction_proxy_used_;
bool cached_data_reduction_proxy_used_;
bool lite_page_used_;
bool black_listed_;
......@@ -329,12 +334,13 @@ class DataReductionProxyMetricsObserverTest
histogram_tester().ExpectTotalCount(
std::string(internal::kHistogramDataReductionProxyPrefix)
.append(histogram_suffix),
data_reduction_proxy_used_ ? 1 : 0);
data_reduction_proxy_used_ || cached_data_reduction_proxy_used_ ? 1
: 0);
histogram_tester().ExpectTotalCount(
std::string(internal::kHistogramDataReductionProxyLitePagePrefix)
.append(histogram_suffix),
is_using_lite_page_ ? 1 : 0);
if (!data_reduction_proxy_used_)
if (!(data_reduction_proxy_used_ || cached_data_reduction_proxy_used_))
return;
histogram_tester().ExpectUniqueSample(
std::string(internal::kHistogramDataReductionProxyPrefix)
......@@ -427,12 +433,15 @@ class DataReductionProxyMetricsObserverTest
tracker->AddObserver(
std::make_unique<TestDataReductionProxyMetricsObserver>(
web_contents(), pingback_client_.get(), data_reduction_proxy_used_,
is_using_lite_page_, black_listed_));
cached_data_reduction_proxy_used_, is_using_lite_page_,
black_listed_));
}
std::unique_ptr<TestPingbackClient> pingback_client_;
page_load_metrics::mojom::PageLoadTiming timing_;
bool cached_data_reduction_proxy_used_ = false;
private:
bool data_reduction_proxy_used_;
bool is_using_lite_page_;
......@@ -549,6 +558,12 @@ TEST_F(DataReductionProxyMetricsObserverTest, OnCompletePingback) {
RunTestAndNavigateToUntrackedUrl(false, false, false);
EXPECT_FALSE(pingback_client_->send_pingback_called());
ResetTest();
cached_data_reduction_proxy_used_ = true;
RunTestAndNavigateToUntrackedUrl(false, false, false);
EXPECT_TRUE(pingback_client_->send_pingback_called());
cached_data_reduction_proxy_used_ = false;
ResetTest();
// Verify that when the holdback experiment is enabled, a pingback is sent.
base::FieldTrialList field_trial_list(nullptr);
......
......@@ -50,7 +50,7 @@ PreviewsUKMObserver::OnCommit(content::NavigationHandle* navigation_handle,
return STOP_OBSERVING;
data_reduction_proxy::DataReductionProxyData* data =
chrome_navigation_data->GetDataReductionProxyData();
if (data && data->used_data_reduction_proxy() && data->lite_page_received()) {
if (data && data->lite_page_received()) {
lite_page_seen_ = true;
}
content::PreviewsState previews_state =
......
......@@ -38,6 +38,7 @@ DataReductionProxyData::DataReductionProxyData()
lofi_policy_received_(false),
lofi_received_(false),
black_listed_(false),
was_cached_data_reduction_proxy_response_(false),
effective_connection_type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
connection_type_(net::NetworkChangeNotifier::CONNECTION_UNKNOWN),
request_info_(std::vector<DataReductionProxyData::RequestInfo>()) {}
......
......@@ -107,6 +107,16 @@ class DataReductionProxyData : public base::SupportsUserData::Data {
client_lofi_requested_ = client_lofi_requested;
}
// This response was fetched from cache, but the original request used DRP.
bool was_cached_data_reduction_proxy_response() const {
return was_cached_data_reduction_proxy_response_;
}
void set_was_cached_data_reduction_proxy_response(
bool was_cached_data_reduction_proxy_response) {
was_cached_data_reduction_proxy_response_ =
was_cached_data_reduction_proxy_response;
}
// The session key used for this request. Only set for main frame requests.
std::string session_key() const { return session_key_; }
void set_session_key(const std::string& session_key) {
......@@ -188,6 +198,7 @@ class DataReductionProxyData : public base::SupportsUserData::Data {
// Whether the DataReductionProxy was used for this request or navigation.
// Also true if the user is the holdback experiment, and the request would
// otherwise be eligible to use the proxy.
// Cached responses are not considered to have used DRP.
bool used_data_reduction_proxy_;
// Whether server Lo-Fi was requested for this request or navigation. True if
......@@ -213,6 +224,9 @@ class DataReductionProxyData : public base::SupportsUserData::Data {
// Whether the blacklist prevented a preview.
bool black_listed_;
// This response was fetched from cache, but the original request used DRP.
bool was_cached_data_reduction_proxy_response_;
// The session key used for this request or navigation.
std::string session_key_;
......
......@@ -514,6 +514,14 @@ void DataReductionProxyNetworkDelegate::OnHeadersReceivedInternal(
original_response_headers->IsRedirect(nullptr))
return;
if (request->was_cached() && request->url().SchemeIsHTTPOrHTTPS() &&
!request->url().SchemeIsCryptographic() &&
original_response_headers->HasHeader(chrome_proxy_header())) {
DataReductionProxyData* data =
DataReductionProxyData::GetDataAndCreateIfNecessary(request);
data->set_was_cached_data_reduction_proxy_response(true);
}
switch (ParseResponseTransform(*original_response_headers)) {
case TRANSFORM_LITE_PAGE:
DataReductionProxyData::GetDataAndCreateIfNecessary(request)
......
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