Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc |
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc |
index 76f0dddd3d45d5f40afbf47b1778ef59377ae6bb..aa76a07fa0d983392bf2d246e23e538fed34e2e2 100644 |
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc |
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc |
@@ -6,9 +6,11 @@ |
#include <stdint.h> |
+#include "base/bind_helpers.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/optional.h" |
#include "base/rand_util.h" |
+#include "base/threading/thread_task_runner_handle.h" |
#include "base/time/time.h" |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_page_load_timing.h" |
@@ -33,10 +35,16 @@ static const char kHistogramAttempted[] = |
"DataReductionProxy.Pingback.Attempted"; |
// Adds the relevant information to |request| for this page load based on page |
-// timing and data reduction proxy state. |
+// timing and data reduction proxy state. |opt_out_page_id| represents an opt |
+// out for a given load. If |opt_out_page_id| is empty, there was no opt out. If |
+// |opt_out_page_id| does not match the page id in |request_data|, it means the |
+// navigation for |opt_out_page_id| is old and was not originally tracked by the |
+// metrics observer when the opt out occured and the current page load did not |
+// see an opt out. |
void AddDataToPageloadMetrics(const DataReductionProxyData& request_data, |
const DataReductionProxyPageLoadTiming& timing, |
- PageloadMetrics* request) { |
+ PageloadMetrics* request, |
+ base::Optional<uint64_t> opt_out_page_id) { |
request->set_session_key(request_data.session_key()); |
// For the timing events, any of them could be zero. Fill the message as a |
// best effort. |
@@ -96,6 +104,29 @@ void AddDataToPageloadMetrics(const DataReductionProxyData& request_data, |
if (request_data.page_id()) { |
request->set_page_id(request_data.page_id().value()); |
} |
+ |
+ bool was_preview_shown = false; |
+ if (request_data.lofi_received()) { |
+ request->set_previews_type(PageloadMetrics_PreviewsType_LOFI); |
+ was_preview_shown = true; |
+ } else if (request_data.lite_page_received()) { |
+ request->set_previews_type(PageloadMetrics_PreviewsType_LITE_PAGE); |
+ was_preview_shown = true; |
+ } else { |
+ request->set_previews_type(PageloadMetrics_PreviewsType_NONE); |
+ } |
+ |
+ if (!was_preview_shown || timing.app_background_occured) { |
+ request->set_previews_opt_out(PageloadMetrics_PreviewsOptOut_UNKNOWN); |
+ return; |
+ } |
+ |
+ if (opt_out_page_id && request_data.page_id() && |
+ opt_out_page_id.value() == request_data.page_id().value()) { |
+ request->set_previews_opt_out(PageloadMetrics_PreviewsOptOut_OPT_OUT); |
+ return; |
+ } |
+ request->set_previews_opt_out(PageloadMetrics_PreviewsOptOut_NON_OPT_OUT); |
} |
// Adds |current_time| as the metrics sent time to |request_data|, and returns |
@@ -119,6 +150,7 @@ DataReductionProxyPingbackClient::DataReductionProxyPingbackClient( |
pingback_reporting_fraction_(0.0) {} |
DataReductionProxyPingbackClient::~DataReductionProxyPingbackClient() { |
+ DCHECK(tab_page_id_map_.empty()); |
DCHECK(thread_checker_.CalledOnValidThread()); |
} |
@@ -135,14 +167,24 @@ void DataReductionProxyPingbackClient::OnURLFetchComplete( |
void DataReductionProxyPingbackClient::SendPingback( |
const DataReductionProxyData& request_data, |
- const DataReductionProxyPageLoadTiming& timing) { |
+ const DataReductionProxyPageLoadTiming& timing, |
+ const void* tab_identifier_key) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
bool send_pingback = ShouldSendPingback(); |
UMA_HISTOGRAM_BOOLEAN(kHistogramAttempted, send_pingback); |
if (!send_pingback) |
return; |
+ |
+ auto page_id_iter = tab_page_id_map_.find(tab_identifier_key); |
+ base::Optional<uint64_t> opt_out_page_id; |
+ if (page_id_iter != tab_page_id_map_.end()) { |
+ opt_out_page_id = page_id_iter->second; |
+ tab_page_id_map_.erase(page_id_iter); |
+ } |
+ |
PageloadMetrics* pageload_metrics = metrics_request_.add_pageloads(); |
- AddDataToPageloadMetrics(request_data, timing, pageload_metrics); |
+ AddDataToPageloadMetrics(request_data, timing, pageload_metrics, |
+ opt_out_page_id); |
if (current_fetcher_.get()) |
return; |
DCHECK_EQ(1, metrics_request_.pageloads_size()); |
@@ -191,4 +233,25 @@ void DataReductionProxyPingbackClient::SetPingbackReportingFraction( |
pingback_reporting_fraction_ = pingback_reporting_fraction; |
} |
+void DataReductionProxyPingbackClient::AddOptOut(const void* tab_identifier_key, |
+ uint64_t page_id) { |
+ tab_page_id_map_[tab_identifier_key] = page_id; |
+} |
+ |
+void DataReductionProxyPingbackClient::ClearTabKeySync( |
+ const void* tab_identifier_key) { |
+ tab_page_id_map_.erase(tab_identifier_key); |
+} |
+ |
+void DataReductionProxyPingbackClient::ClearTabKeyAsync( |
+ const void* tab_identifier_key) { |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(&DataReductionProxyPingbackClient::ClearTabKeySync, |
+ base::Unretained(this), tab_identifier_key)); |
+} |
+ |
+size_t DataReductionProxyPingbackClient::PendingTabLoadsForTesting() const { |
+ return tab_page_id_map_.size(); |
+} |
+ |
} // namespace data_reduction_proxy |