Commit 75313498 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Add save data boolean to previews UKM

A boolean value is set to true if the save data feature
is enabled in Chrome at the time of page commit.

Bug: 827608
Change-Id: I2cfa207694bb5aefe5bcb756fe9443248415e4d4
Reviewed-on: https://chromium-review.googlesource.com/1033821Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554813}
parent 2ec39745
......@@ -8,14 +8,19 @@
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/loader/chrome_navigation_data.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
#include "chrome/browser/previews/previews_infobar_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/page_load_metrics/page_load_timing.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/previews/content/previews_content_util.h"
#include "components/ukm/ukm_source.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/previews_state.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
......@@ -30,6 +35,9 @@ page_load_metrics::PageLoadMetricsObserver::ObservePolicy
PreviewsUKMObserver::OnCommit(content::NavigationHandle* navigation_handle,
ukm::SourceId source_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
save_data_enabled_ = IsDataSaverEnabled(navigation_handle);
// As documented in content/public/browser/navigation_handle.h, this
// NavigationData is a clone of the NavigationData instance returned from
// ResourceDispatcherHostDelegate::GetNavigationData during commit.
......@@ -91,8 +99,10 @@ void PreviewsUKMObserver::RecordPreviewsTypes(
const page_load_metrics::PageLoadExtraInfo& info) {
// Only record previews types when they are active.
if (!server_lofi_seen_ && !client_lofi_seen_ && !lite_page_seen_ &&
!noscript_seen_ && !origin_opt_out_occurred_)
!noscript_seen_ && !origin_opt_out_occurred_ && !save_data_enabled_) {
return;
}
ukm::builders::Previews builder(info.source_id);
if (server_lofi_seen_)
builder.Setserver_lofi(1);
......@@ -106,6 +116,8 @@ void PreviewsUKMObserver::RecordPreviewsTypes(
builder.Setopt_out(1);
if (origin_opt_out_occurred_)
builder.Setorigin_opt_out(1);
if (save_data_enabled_)
builder.Setsave_data_enabled(1);
builder.Record(ukm::UkmRecorder::Get());
}
......@@ -131,4 +143,21 @@ void PreviewsUKMObserver::OnEventOccurred(const void* const event_key) {
opt_out_occurred_ = true;
}
bool PreviewsUKMObserver::IsDataSaverEnabled(
content::NavigationHandle* navigation_handle) const {
Profile* profile = Profile::FromBrowserContext(
navigation_handle->GetWebContents()->GetBrowserContext());
data_reduction_proxy::DataReductionProxySettings*
data_reduction_proxy_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
profile);
if (!data_reduction_proxy_settings) {
DCHECK(profile->IsOffTheRecord());
return false;
}
return data_reduction_proxy_settings->IsDataReductionProxyEnabled();
}
} // namespace previews
......@@ -37,6 +37,12 @@ class PreviewsUKMObserver : public page_load_metrics::PageLoadMetricsObserver {
extra_request_complete_info) override;
void OnEventOccurred(const void* const event_key) override;
protected:
// Returns true if data saver feature is enabled in Chrome. Virtualized for
// testing.
virtual bool IsDataSaverEnabled(
content::NavigationHandle* navigation_handle) const;
private:
void RecordPreviewsTypes(const page_load_metrics::PageLoadExtraInfo& info);
......@@ -46,6 +52,7 @@ class PreviewsUKMObserver : public page_load_metrics::PageLoadMetricsObserver {
bool noscript_seen_ = false;
bool opt_out_occurred_ = false;
bool origin_opt_out_occurred_ = false;
bool save_data_enabled_ = false;
SEQUENCE_CHECKER(sequence_checker_);
......
......@@ -115,6 +115,8 @@ void DataReductionProxySettings::SetCallbackToRegisterSyntheticFieldTrial(
}
bool DataReductionProxySettings::IsDataReductionProxyEnabled() const {
if (spdy_proxy_auth_enabled_.GetPrefName().empty())
return false;
return spdy_proxy_auth_enabled_.GetValue() ||
params::ShouldForceEnableDataReductionProxy();
}
......
......@@ -2492,6 +2492,12 @@ be describing additional metrics about the same event.
by the origin site (rather than the user).
</summary>
</metric>
<metric name="save_data_enabled">
<summary>
Set to 1 if the data saver feature was enabled in Chrome at the time of
the page commit.
</summary>
</metric>
<metric name="server_lofi">
<summary>
Set to 1 when a user is shown a server lo-fi image in a page load.
......
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