Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc

Issue 2504963004: Record time to first data reduction proxy request (Closed)
Patch Set: Rebased Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc
index 6988b4fbf7f935ddf23cc4f43d13c7fc8daf4761..a0ace27e88fe0e207e459edf57878e1bdb4696c4 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc
@@ -8,6 +8,8 @@
#include "base/command_line.h"
#include "base/metrics/histogram_macros.h"
+#include "base/time/default_tick_clock.h"
+#include "base/time/tick_clock.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
@@ -20,6 +22,7 @@
#include "net/base/url_util.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
+#include "net/proxy/proxy_info.h"
#include "net/proxy/proxy_service.h"
namespace data_reduction_proxy {
@@ -39,15 +42,26 @@ DataReductionProxyDelegate::DataReductionProxyDelegate(
event_creator_(event_creator),
bypass_stats_(bypass_stats),
alternative_proxies_broken_(false),
+ tick_clock_(new base::DefaultTickClock()),
+ first_data_saver_request_recorded_(false),
net_log_(net_log) {
- DCHECK(config);
- DCHECK(configurator);
- DCHECK(event_creator);
- DCHECK(bypass_stats);
- DCHECK(net_log);
+ DCHECK(config_);
+ DCHECK(configurator_);
+ DCHECK(event_creator_);
+ DCHECK(bypass_stats_);
+ DCHECK(net_log_);
+ // Constructed on the UI thread, but should be checked on the IO thread.
+ thread_checker_.DetachFromThread();
}
DataReductionProxyDelegate::~DataReductionProxyDelegate() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
+}
+
+void DataReductionProxyDelegate::InitializeOnIOThread() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ net::NetworkChangeNotifier::AddIPAddressObserver(this);
}
void DataReductionProxyDelegate::OnResolveProxy(
@@ -56,18 +70,30 @@ void DataReductionProxyDelegate::OnResolveProxy(
const net::ProxyService& proxy_service,
net::ProxyInfo* result) {
DCHECK(result);
+ DCHECK(thread_checker_.CalledOnValidThread());
+
OnResolveProxyHandler(url, method, configurator_->GetProxyConfig(),
proxy_service.proxy_retry_info(), config_, result);
+
+ if (!first_data_saver_request_recorded_ && !result->is_empty() &&
+ config_->IsDataReductionProxy(result->proxy_server(), nullptr)) {
+ UMA_HISTOGRAM_MEDIUM_TIMES(
+ "DataReductionProxy.TimeToFirstDataSaverRequest",
+ tick_clock_->NowTicks() - last_network_change_time_);
+ first_data_saver_request_recorded_ = true;
+ }
}
void DataReductionProxyDelegate::OnTunnelConnectCompleted(
const net::HostPortPair& endpoint,
const net::HostPortPair& proxy_server,
int net_error) {
+ DCHECK(thread_checker_.CalledOnValidThread());
}
void DataReductionProxyDelegate::OnFallback(const net::ProxyServer& bad_proxy,
int net_error) {
+ DCHECK(thread_checker_.CalledOnValidThread());
if (bad_proxy.is_valid() &&
config_->IsDataReductionProxy(bad_proxy, nullptr)) {
event_creator_->AddProxyFallbackEvent(net_log_, bad_proxy.ToURI(),
@@ -81,10 +107,12 @@ void DataReductionProxyDelegate::OnFallback(const net::ProxyServer& bad_proxy,
void DataReductionProxyDelegate::OnBeforeTunnelRequest(
const net::HostPortPair& proxy_server,
net::HttpRequestHeaders* extra_headers) {
+ DCHECK(thread_checker_.CalledOnValidThread());
}
bool DataReductionProxyDelegate::IsTrustedSpdyProxy(
const net::ProxyServer& proxy_server) {
+ DCHECK(thread_checker_.CalledOnValidThread());
if (!proxy_server.is_https() ||
!params::IsIncludedInTrustedSpdyProxyFieldTrial() ||
!proxy_server.is_valid()) {
@@ -97,12 +125,22 @@ void DataReductionProxyDelegate::OnTunnelHeadersReceived(
const net::HostPortPair& origin,
const net::HostPortPair& proxy_server,
const net::HttpResponseHeaders& response_headers) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+void DataReductionProxyDelegate::SetTickClockForTesting(
+ std::unique_ptr<base::TickClock> tick_clock) {
+ tick_clock_ = std::move(tick_clock);
+ // Update |last_network_change_time_| to the provided tick clock's current
+ // time for testing.
+ last_network_change_time_ = tick_clock_->NowTicks();
}
void DataReductionProxyDelegate::GetAlternativeProxy(
const GURL& url,
const net::ProxyServer& resolved_proxy_server,
net::ProxyServer* alternative_proxy_server) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!alternative_proxy_server->is_valid());
if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS() ||
@@ -140,6 +178,7 @@ void DataReductionProxyDelegate::GetAlternativeProxy(
void DataReductionProxyDelegate::OnAlternativeProxyBroken(
const net::ProxyServer& alternative_proxy_server) {
+ DCHECK(thread_checker_.CalledOnValidThread());
// TODO(tbansal): Reset this on connection change events.
// Currently, DataReductionProxyDelegate does not maintain a list of broken
// proxies. If one alternative proxy is broken, use of all alternative proxies
@@ -152,6 +191,7 @@ void DataReductionProxyDelegate::OnAlternativeProxyBroken(
net::ProxyServer DataReductionProxyDelegate::GetDefaultAlternativeProxy()
const {
+ DCHECK(thread_checker_.CalledOnValidThread());
if (!params::IsZeroRttQuicEnabled())
return net::ProxyServer();
@@ -175,6 +215,7 @@ net::ProxyServer DataReductionProxyDelegate::GetDefaultAlternativeProxy()
bool DataReductionProxyDelegate::SupportsQUIC(
const net::ProxyServer& proxy_server) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
// Enable QUIC for whitelisted proxies.
// TODO(tbansal): Use client config service to control this whitelist.
return base::CommandLine::ForCurrentProcess()->HasSwitch(
@@ -186,16 +227,24 @@ bool DataReductionProxyDelegate::SupportsQUIC(
void DataReductionProxyDelegate::RecordQuicProxyStatus(
QuicProxyStatus status) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.Quic.ProxyStatus", status,
QUIC_PROXY_STATUS_BOUNDARY);
}
void DataReductionProxyDelegate::RecordGetDefaultAlternativeProxy(
DefaultAlternativeProxyStatus status) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.Quic.DefaultAlternativeProxy",
status, DEFAULT_ALTERNATIVE_PROXY_STATUS_BOUNDARY);
}
+void DataReductionProxyDelegate::OnIPAddressChanged() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ first_data_saver_request_recorded_ = false;
+ last_network_change_time_ = tick_clock_->NowTicks();
+}
+
void OnResolveProxyHandler(const GURL& url,
const std::string& method,
const net::ProxyConfig& data_reduction_proxy_config,

Powered by Google App Engine
This is Rietveld 408576698