From e82faa1ec0e96751da4db1d0f0df9bf83af465f1 Mon Sep 17 00:00:00 2001 From: jeremyim Date: Mon, 24 Nov 2014 13:31:13 -0800 Subject: [PATCH] Add net_log events for data reduction proxy conditions. They will be exposed in the #bandwidth net-internals tab in a future CL. BUG=346356 Review URL: https://codereview.chromium.org/719373002 Cr-Commit-Position: refs/heads/master@{#305496} --- android_webview/browser/aw_browser_context.cc | 14 +- android_webview/browser/aw_browser_context.h | 6 + .../browser/net/aw_url_request_context_getter.cc | 3 +- .../data_reduction_proxy_chrome_configurator.cc | 18 +- .../data_reduction_proxy_chrome_configurator.h | 14 +- ...reduction_proxy_chrome_configurator_unittest.cc | 13 +- .../data_reduction_proxy_chrome_settings.cc | 8 +- .../data_reduction_proxy_chrome_settings.h | 6 +- chrome/browser/profiles/profile_impl.cc | 26 ++- chrome/browser/profiles/profile_impl_io_data.cc | 12 +- chrome/browser/profiles/profile_impl_io_data.h | 4 +- chrome/browser/profiles/profile_io_data.h | 15 ++ components/components_tests.gyp | 1 + components/data_reduction_proxy.gypi | 2 + .../browser/data_reduction_proxy_interceptor.cc | 8 +- .../browser/data_reduction_proxy_interceptor.h | 11 +- .../core/browser/data_reduction_proxy_protocol.cc | 19 +- .../core/browser/data_reduction_proxy_protocol.h | 4 +- .../data_reduction_proxy_protocol_unittest.cc | 9 +- .../core/browser/data_reduction_proxy_settings.cc | 24 ++- .../core/browser/data_reduction_proxy_settings.h | 19 +- .../data_reduction_proxy_settings_test_utils.cc | 8 +- .../data_reduction_proxy_settings_test_utils.h | 3 + .../data_reduction_proxy_settings_unittest.cc | 4 +- .../data_reduction_proxy/core/common/BUILD.gn | 3 + .../common/data_reduction_proxy_event_store.cc | 233 +++++++++++++++++++++ .../core/common/data_reduction_proxy_event_store.h | 119 +++++++++++ .../data_reduction_proxy_event_store_unittest.cc | 132 ++++++++++++ .../core/common/data_reduction_proxy_headers.cc | 28 ++- .../core/common/data_reduction_proxy_headers.h | 15 +- .../data_reduction_proxy_headers_unittest.cc | 37 +++- net/base/net_log_event_type_list.h | 61 ++++++ net/base/net_log_source_type_list.h | 1 + 33 files changed, 839 insertions(+), 41 deletions(-) create mode 100644 components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc create mode 100644 components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h create mode 100644 components/data_reduction_proxy/core/common/data_reduction_proxy_event_store_unittest.cc diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index 4175b3f5136b..25f91fcd8dbe 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -22,6 +22,7 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" #include "components/user_prefs/user_prefs.h" #include "components/visitedlink/browser/visitedlink_master.h" @@ -36,6 +37,7 @@ using base::FilePath; using content::BrowserThread; using data_reduction_proxy::DataReductionProxyConfigService; +using data_reduction_proxy::DataReductionProxyEventStore; using data_reduction_proxy::DataReductionProxySettings; namespace android_webview { @@ -137,6 +139,9 @@ void AwBrowserContext::PreMainMessageLoopRun() { new DataReductionProxySettings( new data_reduction_proxy::DataReductionProxyParams( data_reduction_proxy::DataReductionProxyParams::kAllowed))); + data_reduction_proxy_event_store_.reset( + new DataReductionProxyEventStore( + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); scoped_ptr data_reduction_proxy_config_service( new DataReductionProxyConfigService( @@ -226,6 +231,11 @@ DataReductionProxySettings* AwBrowserContext::GetDataReductionProxySettings() { return data_reduction_proxy_settings_.get(); } +DataReductionProxyEventStore* + AwBrowserContext::GetDataReductionProxyEventStore() { + return data_reduction_proxy_event_store_.get(); +} + AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() { return url_request_context_getter_.get(); } @@ -257,7 +267,9 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() { if (data_reduction_proxy_settings_.get()) { data_reduction_proxy_settings_->InitDataReductionProxySettings( user_pref_service_.get(), - GetRequestContext()); + GetRequestContext(), + GetAwURLRequestContext()->GetNetLog(), + GetDataReductionProxyEventStore()); data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true); SetDataReductionProxyEnabled(data_reduction_proxy_enabled_); diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h index 0fc8e8337229..3aed29526a41 100644 --- a/android_webview/browser/aw_browser_context.h +++ b/android_webview/browser/aw_browser_context.h @@ -29,6 +29,7 @@ class WebContents; namespace data_reduction_proxy { class DataReductionProxyConfigurator; +class DataReductionProxyEventStore; class DataReductionProxySettings; class DataReductionProxyStatisticsPrefs; } @@ -89,6 +90,9 @@ class AwBrowserContext : public content::BrowserContext, data_reduction_proxy::DataReductionProxySettings* GetDataReductionProxySettings(); + data_reduction_proxy::DataReductionProxyEventStore* + GetDataReductionProxyEventStore(); + AwURLRequestContextGetter* GetAwURLRequestContext(); void CreateUserPrefServiceIfNecessary(); @@ -149,6 +153,8 @@ class AwBrowserContext : public content::BrowserContext, data_reduction_proxy_statistics_; scoped_ptr data_reduction_proxy_settings_; + scoped_ptr + data_reduction_proxy_event_store_; DISALLOW_COPY_AND_ASSIGN(AwBrowserContext); }; diff --git a/android_webview/browser/net/aw_url_request_context_getter.cc b/android_webview/browser/net/aw_url_request_context_getter.cc index b600a460bf29..ce39602ab0c1 100644 --- a/android_webview/browser/net/aw_url_request_context_getter.cc +++ b/android_webview/browser/net/aw_url_request_context_getter.cc @@ -259,7 +259,8 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() { job_factory_.reset(new net::URLRequestInterceptingJobFactory( job_factory_.Pass(), make_scoped_ptr( new data_reduction_proxy::DataReductionProxyInterceptor( - data_reduction_proxy_settings->params(), NULL)))); + data_reduction_proxy_settings->params(), NULL, + browser_context->GetDataReductionProxyEventStore())))); url_request_context_->set_job_factory(job_factory_.get()); } diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc index e7c5487febcb..a5d41017c4ff 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc @@ -11,6 +11,7 @@ #include "base/values.h" #include "chrome/browser/prefs/proxy_prefs.h" #include "chrome/common/pref_names.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" #include "net/proxy/proxy_config.h" #include "net/proxy/proxy_info.h" @@ -19,8 +20,17 @@ DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( PrefService* prefs, - scoped_refptr network_task_runner) - : prefs_(prefs), network_task_runner_(network_task_runner) { + scoped_refptr network_task_runner, + net::NetLog* net_log, + data_reduction_proxy::DataReductionProxyEventStore* event_store) + : prefs_(prefs), + network_task_runner_(network_task_runner), + net_log_(net_log), + data_reduction_proxy_event_store_(event_store) { + DCHECK(prefs); + DCHECK(network_task_runner.get()); + DCHECK(net_log); + DCHECK(event_store); } DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { @@ -101,6 +111,9 @@ void DataReductionProxyChromeConfigurator::Enable( // config will return invalid. net::ProxyConfig::ID unused_id = 1; config.set_id(unused_id); + data_reduction_proxy_event_store_->AddProxyEnabledEvent( + net_log_, primary_restricted, fallback_restricted, primary_origin, + fallback_origin, ssl_origin); network_task_runner_->PostTask( FROM_HERE, base::Bind( @@ -112,6 +125,7 @@ void DataReductionProxyChromeConfigurator::Enable( void DataReductionProxyChromeConfigurator::Disable() { DisableInProxyConfigPref(prefs_); net::ProxyConfig config = net::ProxyConfig::CreateDirect(); + data_reduction_proxy_event_store_->AddProxyDisabledEvent(net_log_); network_task_runner_->PostTask( FROM_HERE, base::Bind( diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h index 9dbb280033ad..c84ddccc1e9a 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h @@ -17,7 +17,12 @@ namespace base { class SequencedTaskRunner; } +namespace data_reduction_proxy { +class DataReductionProxyEventStore; +} + namespace net { +class NetLog; class ProxyInfo; class ProxyService; } @@ -29,8 +34,10 @@ class DataReductionProxyChromeConfigurator public: explicit DataReductionProxyChromeConfigurator( PrefService* prefs, - scoped_refptr network_task_runner); - ~DataReductionProxyChromeConfigurator() override; + scoped_refptr network_task_runner, + net::NetLog* net_log, + data_reduction_proxy::DataReductionProxyEventStore* event_store); + ~DataReductionProxyChromeConfigurator() override; // Removes the data reduction proxy configuration from the proxy preference. // This disables use of the data reduction proxy. This method is public to @@ -75,6 +82,9 @@ class DataReductionProxyChromeConfigurator std::vector bypass_rules_; net::ProxyConfig config_; + net::NetLog* net_log_; + data_reduction_proxy::DataReductionProxyEventStore* + data_reduction_proxy_event_store_; DISALLOW_COPY_AND_ASSIGN(DataReductionProxyChromeConfigurator); }; diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc index e24e76bbd700..797b68038027 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc @@ -13,7 +13,9 @@ #include "base/test/test_simple_task_runner.h" #include "base/values.h" #include "chrome/common/pref_names.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" +#include "net/base/capturing_net_log.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -22,9 +24,15 @@ class DataReductionProxyConfigTest : public testing::Test { void SetUp() override { PrefRegistrySimple* registry = pref_service_.registry(); registry->RegisterDictionaryPref(prefs::kProxy); + net_log_.reset(new net::CapturingNetLog()); + data_reduction_proxy_event_store_.reset( + new data_reduction_proxy::DataReductionProxyEventStore( + new base::TestSimpleTaskRunner())); config_.reset(new DataReductionProxyChromeConfigurator( &pref_service_, - new base::TestSimpleTaskRunner())); + new base::TestSimpleTaskRunner(), + net_log_.get(), + data_reduction_proxy_event_store_.get())); } void CheckProxyConfig( @@ -47,6 +55,9 @@ class DataReductionProxyConfigTest : public testing::Test { scoped_ptr config_; TestingPrefServiceSimple pref_service_; + scoped_ptr net_log_; + scoped_ptr + data_reduction_proxy_event_store_; }; TEST_F(DataReductionProxyConfigTest, TestUnrestricted) { diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc index 7a3d619b25e9..163e2eedad3f 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc @@ -32,11 +32,15 @@ void DataReductionProxyChromeSettings::InitDataReductionProxySettings( data_reduction_proxy::DataReductionProxyConfigurator* configurator, PrefService* profile_prefs, PrefService* local_state_prefs, - net::URLRequestContextGetter* request_context) { + net::URLRequestContextGetter* request_context, + net::NetLog* net_log, + data_reduction_proxy::DataReductionProxyEventStore* event_store) { SetProxyConfigurator(configurator); DataReductionProxySettings::InitDataReductionProxySettings( profile_prefs, - request_context); + request_context, + net_log, + event_store); DataReductionProxySettings::SetOnDataReductionEnabledCallback( base::Bind(&DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial, base::Unretained(this))); diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h index 9c338790bf27..92130cbd082a 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h @@ -16,10 +16,12 @@ class PrefService; namespace data_reduction_proxy { class DataReductionProxyConfigurator; +class DataReductionProxyEventStore; class DataReductionProxyParams; } namespace net { +class NetLog; class URLRequestContextGetter; } @@ -45,7 +47,9 @@ class DataReductionProxyChromeSettings data_reduction_proxy::DataReductionProxyConfigurator* configurator, PrefService* profile_prefs, PrefService* local_state_prefs, - net::URLRequestContextGetter* request_context); + net::URLRequestContextGetter* request_context, + net::NetLog* net_log, + data_reduction_proxy::DataReductionProxyEventStore* event_store); // Gets the client type for the data reduction proxy. static data_reduction_proxy::Client GetClient(); diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index e737c3a46d2c..9314c39b5de1 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -38,6 +38,7 @@ #include "chrome/browser/download/download_service.h" #include "chrome/browser/download/download_service_factory.h" #include "chrome/browser/history/top_sites.h" +#include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/net_pref_observer.h" #include "chrome/browser/net/predictor.h" #include "chrome/browser/net/pref_proxy_config_tracker.h" @@ -630,12 +631,15 @@ void ProfileImpl::DoFinalInit() { session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES; } + ChromeNetLog* const net_log = g_browser_process->io_thread()->net_log(); + base::Callback data_reduction_proxy_unavailable; scoped_ptr data_reduction_proxy_params; scoped_ptr chrome_configurator; scoped_ptr data_reduction_proxy_statistics_prefs; + scoped_ptr event_store; DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings = DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this); data_reduction_proxy_params = @@ -644,6 +648,13 @@ void ProfileImpl::DoFinalInit() { base::Bind( &data_reduction_proxy::DataReductionProxySettings::SetUnreachable, base::Unretained(data_reduction_proxy_chrome_settings)); + // The event_store is used by DataReductionProxyChromeSettings, configurator, + // and ProfileIOData. Ownership is passed to the latter via + // ProfileIOData::Handle, which is only destroyed after + // BrowserContextKeyedServices, including DataReductionProxyChromeSettings + event_store.reset( + new data_reduction_proxy::DataReductionProxyEventStore( + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); // The configurator is used by DataReductionProxyChromeSettings and // ProfileIOData. Ownership is passed to the latter via ProfileIOData::Handle, // which is only destroyed after BrowserContextKeyedServices, @@ -651,7 +662,13 @@ void ProfileImpl::DoFinalInit() { chrome_configurator.reset( new DataReductionProxyChromeConfigurator( prefs_.get(), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), + net_log, + event_store.get())); + // Retain a raw pointer to use for initialization of data reduction proxy + // settings after ownership is passed + data_reduction_proxy::DataReductionProxyEventStore* + data_reduction_proxy_event_store = event_store.get(); // Retain a raw pointer to use for initialization of data reduction proxy // settings after ownership is passed. DataReductionProxyChromeConfigurator* @@ -689,12 +706,15 @@ void ProfileImpl::DoFinalInit() { data_reduction_proxy_unavailable, chrome_configurator.Pass(), data_reduction_proxy_params.Pass(), - data_reduction_proxy_statistics_prefs.Pass()); + data_reduction_proxy_statistics_prefs.Pass(), + event_store.Pass()); data_reduction_proxy_chrome_settings->InitDataReductionProxySettings( data_reduction_proxy_chrome_configurator, prefs_.get(), g_browser_process->local_state(), - GetRequestContext()); + GetRequestContext(), + net_log, + data_reduction_proxy_event_store); #if defined(ENABLE_PLUGINS) ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index 437a8dfdd4fd..04dbdf2f0867 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -142,7 +142,9 @@ void ProfileImplIOData::Handle::Init( scoped_ptr data_reduction_proxy_params, scoped_ptr - data_reduction_proxy_statistics_prefs) { + data_reduction_proxy_statistics_prefs, + scoped_ptr + data_reduction_proxy_event_store) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!io_data_->lazy_params_); DCHECK(predictor); @@ -182,6 +184,8 @@ void ProfileImplIOData::Handle::Init( io_data_->set_data_reduction_proxy_params(data_reduction_proxy_params.Pass()); io_data_->set_data_reduction_proxy_statistics_prefs( data_reduction_proxy_statistics_prefs.Pass()); + io_data_->set_data_reduction_proxy_event_store( + data_reduction_proxy_event_store.Pass()); } content::ResourceContext* @@ -576,7 +580,8 @@ void ProfileImplIOData::InitializeInternal( request_interceptors.begin(), new data_reduction_proxy::DataReductionProxyInterceptor( data_reduction_proxy_params(), - data_reduction_proxy_usage_stats())); + data_reduction_proxy_usage_stats(), + data_reduction_proxy_event_store())); main_job_factory_ = SetUpJobFactoryDefaults( main_job_factory.Pass(), request_interceptors.Pass(), @@ -736,7 +741,8 @@ net::URLRequestContext* ProfileImplIOData::InitializeAppRequestContext( request_interceptors.begin(), new data_reduction_proxy::DataReductionProxyInterceptor( data_reduction_proxy_params(), - data_reduction_proxy_usage_stats())); + data_reduction_proxy_usage_stats(), + data_reduction_proxy_event_store())); scoped_ptr top_job_factory( SetUpJobFactoryDefaults(job_factory.Pass(), request_interceptors.Pass(), diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h index ca6ccaf99ced..50570632f33c 100644 --- a/chrome/browser/profiles/profile_impl_io_data.h +++ b/chrome/browser/profiles/profile_impl_io_data.h @@ -71,7 +71,9 @@ class ProfileImplIOData : public ProfileIOData { scoped_ptr data_reduction_proxy_params, scoped_ptr - data_reduction_proxy_statistics_prefs); + data_reduction_proxy_statistics_prefs, + scoped_ptr + data_reduction_proxy_event_store); // These Create*ContextGetter() functions are only exposed because the // circular relationship between Profile, ProfileIOData::Handle, and the diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index 9695bab88b60..48a59e7c2d85 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -26,6 +26,7 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/resource_context.h" #include "net/cookies/cookie_monster.h" @@ -438,6 +439,18 @@ class ProfileIOData { data_reduction_proxy_auth_request_handler.Pass(); } + data_reduction_proxy::DataReductionProxyEventStore* + data_reduction_proxy_event_store() const { + return data_reduction_proxy_event_store_.get(); + } + + void set_data_reduction_proxy_event_store( + scoped_ptr + data_reduction_proxy_event_store) const { + data_reduction_proxy_event_store_ = + data_reduction_proxy_event_store.Pass(); + } + ChromeNetworkDelegate* network_delegate() const { return network_delegate_.get(); } @@ -653,6 +666,8 @@ class ProfileIOData { data_reduction_proxy_chrome_configurator_; mutable scoped_ptr data_reduction_proxy_auth_request_handler_; + mutable scoped_ptr + data_reduction_proxy_event_store_; mutable scoped_ptr network_delegate_; mutable scoped_ptr diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 1302ce92df82..04ecbb180844 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -103,6 +103,7 @@ 'data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs_unittest.cc', 'data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection_unittest.cc', 'data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc', + 'data_reduction_proxy/core/common/data_reduction_proxy_event_store_unittest.cc', 'data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc', 'data_reduction_proxy/core/common/data_reduction_proxy_params_unittest.cc', 'dom_distiller/core/article_entry_unittest.cc', diff --git a/components/data_reduction_proxy.gypi b/components/data_reduction_proxy.gypi index 6195bfb22b8e..eda9490d30e8 100644 --- a/components/data_reduction_proxy.gypi +++ b/components/data_reduction_proxy.gypi @@ -66,6 +66,8 @@ ], 'sources': [ # Note: sources list duplicated in GN build. + 'data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc', + 'data_reduction_proxy/core/common/data_reduction_proxy_event_store.h', 'data_reduction_proxy/core/common/data_reduction_proxy_headers.cc', 'data_reduction_proxy/core/common/data_reduction_proxy_headers.h', 'data_reduction_proxy/core/common/data_reduction_proxy_params.cc', diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.cc index 6ce7f7b36df9..36373a21e1fb 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.cc @@ -19,9 +19,11 @@ namespace data_reduction_proxy { DataReductionProxyInterceptor::DataReductionProxyInterceptor( DataReductionProxyParams* params, - DataReductionProxyUsageStats* stats) + DataReductionProxyUsageStats* stats, + DataReductionProxyEventStore* event_store) : params_(params), - usage_stats_(stats) { + usage_stats_(stats), + event_store_(event_store) { } DataReductionProxyInterceptor::~DataReductionProxyInterceptor() { @@ -40,7 +42,7 @@ net::URLRequestJob* DataReductionProxyInterceptor::MaybeInterceptResponse( return nullptr; DataReductionProxyBypassType bypass_type = BYPASS_EVENT_TYPE_MAX; bool should_retry = data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry( - params_, request, &bypass_type); + params_, request, &bypass_type, event_store_); if (usage_stats_ && bypass_type != BYPASS_EVENT_TYPE_MAX) usage_stats_->SetBypassType(bypass_type); if (!should_retry) diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h index e31f92e2d9b5..1f0acc4a99ff 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h @@ -8,6 +8,7 @@ #include "net/url_request/url_request_interceptor.h" namespace data_reduction_proxy { +class DataReductionProxyEventStore; class DataReductionProxyParams; class DataReductionProxyUsageStats; @@ -17,10 +18,11 @@ class DataReductionProxyUsageStats; // without use of the proxy. class DataReductionProxyInterceptor : public net::URLRequestInterceptor { public: - // Constructs the interceptor. |params| and |stats| must outlive |this|. - // |stats| may be NULL. + // Constructs the interceptor. |params|, |stats|, and |event_store| must + // outlive |this|. |stats| may be NULL. DataReductionProxyInterceptor(DataReductionProxyParams* params, - DataReductionProxyUsageStats* stats); + DataReductionProxyUsageStats* stats, + DataReductionProxyEventStore* event_store); // Destroys the interceptor. ~DataReductionProxyInterceptor() override; @@ -46,6 +48,9 @@ class DataReductionProxyInterceptor : public net::URLRequestInterceptor { // Must outlive |this| if non-NULL. DataReductionProxyUsageStats* usage_stats_; + // Must outlive |this|. + DataReductionProxyEventStore* event_store_; + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyInterceptor); }; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc index f88b9a2264bc..9047018c20d8 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc @@ -5,9 +5,11 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h" #include "base/memory/ref_counted.h" +#include "base/strings/string_number_conversions.h" #include "base/time/time.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" #include "net/base/load_flags.h" @@ -43,7 +45,8 @@ namespace data_reduction_proxy { bool MaybeBypassProxyAndPrepareToRetry( const DataReductionProxyParams* data_reduction_proxy_params, net::URLRequest* request, - DataReductionProxyBypassType* proxy_bypass_type) { + DataReductionProxyBypassType* proxy_bypass_type, + DataReductionProxyEventStore* event_store) { DCHECK(request); if (!data_reduction_proxy_params) return false; @@ -80,10 +83,14 @@ bool MaybeBypassProxyAndPrepareToRetry( response_headers, data_reduction_proxy_type_info.proxy_servers.first.SchemeIsSecure()); + // GetDataReductionProxyBypassType will only log a net_log event if a bypass + // command was sent via the data reduction proxy headers + bool event_logged; DataReductionProxyInfo data_reduction_proxy_info; DataReductionProxyBypassType bypass_type = - GetDataReductionProxyBypassType(response_headers, - &data_reduction_proxy_info); + GetDataReductionProxyBypassType( + response_headers, request->url(), request->net_log(), + &data_reduction_proxy_info, event_store, &event_logged); if (bypass_type == BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_OTHER && DataReductionProxyParams:: @@ -98,6 +105,12 @@ bool MaybeBypassProxyAndPrepareToRetry( if (bypass_type == BYPASS_EVENT_TYPE_MAX) return false; + if (!event_logged) { + event_store->AddBypassTypeEvent( + request->net_log(), bypass_type, request->url(), + data_reduction_proxy_info.bypass_duration); + } + DCHECK(request->context()); DCHECK(request->context()->proxy_service()); net::ProxyServer proxy_server; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h index be2deacca614..84ab2bc429f4 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h @@ -25,6 +25,7 @@ class GURL; namespace data_reduction_proxy { +class DataReductionProxyEventStore; class DataReductionProxyParams; // Decides whether to mark the data reduction proxy as temporarily bad and @@ -34,7 +35,8 @@ class DataReductionProxyParams; bool MaybeBypassProxyAndPrepareToRetry( const DataReductionProxyParams* params, net::URLRequest* request, - DataReductionProxyBypassType* proxy_bypass_type); + DataReductionProxyBypassType* proxy_bypass_type, + DataReductionProxyEventStore* event_store); // Adds data reduction proxies to |result|, where applicable, if result // otherwise uses a direct connection for |url|, the proxy service's effective diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc index c61b4f7e184c..febbeec98833 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc @@ -8,11 +8,14 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop.h" +#include "base/message_loop/message_loop_proxy.h" #include "base/metrics/field_trial.h" #include "base/run_loop.h" #include "base/strings/stringprintf.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" @@ -101,9 +104,12 @@ class DataReductionProxyProtocolTest : public testing::Test { context_->set_http_user_agent_settings(&http_user_agent_settings_); usage_stats_.reset(new DataReductionProxyUsageStats( proxy_params_.get(), base::MessageLoopProxy::current())); + event_store_.reset(new DataReductionProxyEventStore( + base::MessageLoopProxy::current())); DataReductionProxyInterceptor* interceptor = new DataReductionProxyInterceptor(proxy_params_.get(), - usage_stats_.get()); + usage_stats_.get(), + event_store_.get()); scoped_ptr job_factory_impl( new net::URLRequestJobFactoryImpl()); @@ -306,6 +312,7 @@ class DataReductionProxyProtocolTest : public testing::Test { scoped_ptr proxy_service_; scoped_ptr proxy_params_; scoped_ptr usage_stats_; + scoped_ptr event_store_; net::StaticHttpUserAgentSettings http_user_agent_settings_; scoped_ptr job_factory_; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc index 9d9b55b48cd1..e6e7c7246fec 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc @@ -16,9 +16,11 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" +#include "base/values.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" @@ -94,6 +96,8 @@ DataReductionProxySettings::DataReductionProxySettings( unreachable_(false), prefs_(NULL), url_request_context_getter_(NULL), + net_log_(NULL), + event_store_(NULL), configurator_(NULL) { DCHECK(params); params_.reset(params); @@ -122,12 +126,17 @@ void DataReductionProxySettings::InitPrefMembers() { void DataReductionProxySettings::InitDataReductionProxySettings( PrefService* prefs, - net::URLRequestContextGetter* url_request_context_getter) { + net::URLRequestContextGetter* url_request_context_getter, + net::NetLog* net_log, + DataReductionProxyEventStore* event_store) { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(prefs); DCHECK(url_request_context_getter); + DCHECK(event_store); prefs_ = prefs; url_request_context_getter_ = url_request_context_getter; + net_log_ = net_log; + event_store_ = event_store; InitPrefMembers(); RecordDataReductionInit(); @@ -229,6 +238,11 @@ void DataReductionProxySettings::OnURLFetchComplete( DCHECK(source == fetcher_.get()); net::URLRequestStatus status = source->GetStatus(); + + if (event_store_) { + event_store_->EndCanaryRequest(bound_net_log_, status.error()); + } + if (status.status() == net::URLRequestStatus::FAILED) { if (status.error() == net::ERR_INTERNET_DISCONNECTED) { RecordProbeURLFetchResult(INTERNET_DISCONNECTED); @@ -544,6 +558,14 @@ void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { if (!fetcher) return; fetcher_.reset(fetcher); + + bound_net_log_ = net::BoundNetLog::Make( + net_log_, net::NetLog::SOURCE_DATA_REDUCTION_PROXY); + if (event_store_) { + event_store_->BeginCanaryRequest(bound_net_log_, + fetcher_->GetOriginalURL()); + } + fetcher_->Start(); } diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h index 07a6ced69454..86a0a7e5246e 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h @@ -17,6 +17,7 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" +#include "net/base/net_log.h" #include "net/base/net_util.h" #include "net/base/network_change_notifier.h" #include "net/url_request/url_fetcher_delegate.h" @@ -33,6 +34,8 @@ class URLRequestContextGetter; namespace data_reduction_proxy { +class DataReductionProxyEventStore; + // The number of days of bandwidth usage statistics that are tracked. const unsigned int kNumDaysInHistory = 60; @@ -104,7 +107,9 @@ class DataReductionProxySettings // |DataReductionProxySettings| instance. void InitDataReductionProxySettings( PrefService* prefs, - net::URLRequestContextGetter* url_request_context_getter); + net::URLRequestContextGetter* url_request_context_getter, + net::NetLog* net_log, + DataReductionProxyEventStore* event_store); // Sets the |statistics_prefs_| to be used for data reduction proxy pref reads // and writes. @@ -291,6 +296,10 @@ class DataReductionProxySettings scoped_ptr fetcher_; + // A new BoundNetLog is created for each canary check so that we can correlate + // the request begin/end phases. + net::BoundNetLog bound_net_log_; + BooleanPrefMember spdy_proxy_auth_enabled_; BooleanPrefMember data_reduction_proxy_alternative_enabled_; @@ -299,6 +308,14 @@ class DataReductionProxySettings net::URLRequestContextGetter* url_request_context_getter_; + // The caller must ensure that the |net_log_|, if set, outlives this instance. + // It is used to create new instances of |bound_net_log_| on canary + // requests. + net::NetLog* net_log_; + + // The caller must ensure that the |event_store_| outlives this instance. + DataReductionProxyEventStore* event_store_; + base::Callback on_data_reduction_proxy_enabled_; DataReductionProxyConfigurator* configurator_; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc index 26ec584a92a9..89288674feb4 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc @@ -14,6 +14,7 @@ #include "base/time/time.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" @@ -94,6 +95,9 @@ void DataReductionProxySettingsTestBase::SetUp() { scoped_refptr( new base::TestSimpleTaskRunner()), base::TimeDelta())); + event_store_.reset(new DataReductionProxyEventStore( + scoped_refptr( + new base::TestSimpleTaskRunner()))); //AddProxyToCommandLine(); ResetSettings(true, true, false, true, false); @@ -283,7 +287,9 @@ void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy( settings_->InitDataReductionProxySettings( &pref_service_, - request_context.get()); + request_context.get(), + &net_log_, + event_store_.get()); settings_->SetOnDataReductionEnabledCallback( base::Bind(&DataReductionProxySettingsTestBase:: RegisterSyntheticFieldTrialCallback, diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h index 7df9773c25c7..6127c84a027c 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h @@ -11,6 +11,7 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" +#include "net/base/capturing_net_log.h" #include "net/base/net_util.h" #include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/url_request_test_util.h" @@ -167,6 +168,8 @@ class DataReductionProxySettingsTestBase : public testing::Test { base::Time last_update_time_; bool proxy_enabled_; scoped_ptr statistics_prefs_; + net::CapturingNetLog net_log_; + scoped_ptr event_store_; }; // Test implementations should be subclasses of an instantiation of this diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc index 023637fff3f4..f0c7bbfc6ea2 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc @@ -415,7 +415,9 @@ TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); settings_->InitDataReductionProxySettings( &pref_service_, - request_context.get()); + request_context.get(), + &net_log_, + event_store_.get()); settings_->SetOnDataReductionEnabledCallback( base::Bind(&DataReductionProxySettingsTestBase:: RegisterSyntheticFieldTrialCallback, diff --git a/components/data_reduction_proxy/core/common/BUILD.gn b/components/data_reduction_proxy/core/common/BUILD.gn index 36933967c2e5..b11ca2e5ef2d 100644 --- a/components/data_reduction_proxy/core/common/BUILD.gn +++ b/components/data_reduction_proxy/core/common/BUILD.gn @@ -6,6 +6,8 @@ import("//components/data_reduction_proxy/core/common/version.gni") static_library("common") { sources = [ + "data_reduction_proxy_event_store.cc", + "data_reduction_proxy_event_store.h", "data_reduction_proxy_headers.cc", "data_reduction_proxy_headers.h", "data_reduction_proxy_params.cc", @@ -42,6 +44,7 @@ static_library("test_support") { source_set("unit_tests") { testonly = true sources = [ + "data_reduction_proxy_event_store_unittest.cc", "data_reduction_proxy_headers_unittest.cc", "data_reduction_proxy_params_unittest.cc", ] diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc new file mode 100644 index 000000000000..3e164a67a1b5 --- /dev/null +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc @@ -0,0 +1,233 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" + +#include "base/bind.h" +#include "base/location.h" +#include "base/memory/scoped_ptr.h" +#include "base/single_thread_task_runner.h" +#include "base/stl_util.h" +#include "base/strings/string_number_conversions.h" +#include "base/time/time.h" +#include "base/values.h" +#include "net/base/net_log.h" + +namespace { + +const size_t kMaxEventsToStore = 100; + +scoped_ptr BuildDataReductionProxyEvent( + net::NetLog::EventType type, + const net::NetLog::Source& source, + net::NetLog::EventPhase phase, + const net::NetLog::ParametersCallback& parameters_callback) { + base::TimeTicks ticks_now = base::TimeTicks::Now(); + net::NetLog::EntryData entry_data( + type, source, phase, ticks_now, ¶meters_callback); + net::NetLog::Entry entry(&entry_data, net::NetLog::LOG_ALL); + scoped_ptr entry_value(entry.ToValue()); + + return entry_value; +} + +std::string GetExpirationTicks(int bypass_seconds) { + base::TimeTicks ticks_now = base::TimeTicks::Now(); + return net::NetLog::TickCountToString( + ticks_now + base::TimeDelta::FromSeconds(bypass_seconds)); +} + +// The following callbacks create a base::Value which contains information +// about various data reduction proxy events. Ownership of the base::Value is +// passed to the caller. +base::Value* EnableDataReductionProxyCallback( + bool primary_restricted, + bool fallback_restricted, + const std::string& primary_origin, + const std::string& fallback_origin, + const std::string& ssl_origin, + net::NetLog::LogLevel /* log_level */) { + base::DictionaryValue* dict = new base::DictionaryValue(); + dict->SetBoolean("enabled", true); + dict->SetBoolean("primary_restricted", primary_restricted); + dict->SetBoolean("fallback_restricted", fallback_restricted); + dict->SetString("primary_origin", primary_origin); + dict->SetString("fallback_origin", fallback_origin); + dict->SetString("ssl_origin", ssl_origin); + return dict; +} + +base::Value* DisableDataReductionProxyCallback( + net::NetLog::LogLevel /* log_level */) { + base::DictionaryValue* dict = new base::DictionaryValue(); + dict->SetBoolean("enabled", false); + return dict; +} + +base::Value* UrlBypassActionCallback(const std::string& action, + const GURL& url, + const base::TimeDelta& bypass_duration, + net::NetLog::LogLevel /* log_level */) { + base::DictionaryValue* dict = new base::DictionaryValue(); + int bypass_seconds = bypass_duration.InSeconds(); + dict->SetString("action", action); + dict->SetString("url", url.spec()); + dict->SetString("bypass_duration_seconds", + base::Int64ToString(bypass_seconds)); + dict->SetString("expiration", GetExpirationTicks(bypass_seconds)); + return dict; +} + +base::Value* UrlBypassTypeCallback( + data_reduction_proxy::DataReductionProxyBypassType bypass_type, + const GURL& url, + const base::TimeDelta& bypass_duration, + net::NetLog::LogLevel /* log_level */) { + base::DictionaryValue* dict = new base::DictionaryValue(); + int bypass_seconds = bypass_duration.InSeconds(); + dict->SetInteger("bypass_type", bypass_type); + dict->SetString("url", url.spec()); + dict->SetString("bypass_duration_seconds", + base::Int64ToString(bypass_seconds)); + dict->SetString("expiration", GetExpirationTicks(bypass_seconds)); + return dict; +} + +} // namespace + +namespace data_reduction_proxy { + +DataReductionProxyEventStore::DataReductionProxyEventStore( + const scoped_refptr& network_task_runner) + : network_task_runner_(network_task_runner) { +} + +DataReductionProxyEventStore::~DataReductionProxyEventStore() { + STLDeleteElements(&stored_events_); + stored_events_.clear(); +} + +void DataReductionProxyEventStore::AddProxyEnabledEvent( + net::NetLog* net_log, + bool primary_restricted, + bool fallback_restricted, + const std::string& primary_origin, + const std::string& fallback_origin, + const std::string& ssl_origin) { + const net::NetLog::ParametersCallback& parameters_callback = + base::Bind(&EnableDataReductionProxyCallback, primary_restricted, + fallback_restricted, primary_origin, fallback_origin, + ssl_origin); + PostGlobalNetLogEvent(net_log, + net::NetLog::TYPE_DATA_REDUCTION_PROXY_ENABLED, + parameters_callback); +} + +void DataReductionProxyEventStore::AddProxyDisabledEvent( + net::NetLog* net_log) { + const net::NetLog::ParametersCallback& parameters_callback = + base::Bind(&DisableDataReductionProxyCallback); + PostGlobalNetLogEvent(net_log, + net::NetLog::TYPE_DATA_REDUCTION_PROXY_ENABLED, + parameters_callback); +} + +void DataReductionProxyEventStore::AddBypassActionEvent( + const net::BoundNetLog& net_log, + const std::string& bypass_action, + const GURL& url, + const base::TimeDelta& bypass_duration) { + const net::NetLog::ParametersCallback& parameters_callback = + base::Bind(&UrlBypassActionCallback, bypass_action, url, bypass_duration); + PostBoundNetLogEvent(net_log, + net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED, + net::NetLog::PHASE_NONE, + parameters_callback); +} + +void DataReductionProxyEventStore::AddBypassTypeEvent( + const net::BoundNetLog& net_log, + DataReductionProxyBypassType bypass_type, + const GURL& url, + const base::TimeDelta& bypass_duration) { + const net::NetLog::ParametersCallback& parameters_callback = + base::Bind(&UrlBypassTypeCallback, bypass_type, url, bypass_duration); + PostBoundNetLogEvent(net_log, + net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED, + net::NetLog::PHASE_NONE, + parameters_callback); +} + +void DataReductionProxyEventStore::BeginCanaryRequest( + const net::BoundNetLog& net_log, + const GURL& url) { + // This callback must be invoked synchronously + const net::NetLog::ParametersCallback& parameters_callback = + net::NetLog::StringCallback("url", &url.spec()); + PostBoundNetLogEvent(net_log, + net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST, + net::NetLog::PHASE_BEGIN, + parameters_callback); +} + +void DataReductionProxyEventStore::EndCanaryRequest( + const net::BoundNetLog& net_log, + int net_error) { + const net::NetLog::ParametersCallback& parameters_callback = + net::NetLog::IntegerCallback("net_error", net_error); + PostBoundNetLogEvent(net_log, + net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST, + net::NetLog::PHASE_END, + parameters_callback); +} + +void DataReductionProxyEventStore::PostGlobalNetLogEvent( + net::NetLog* net_log, + net::NetLog::EventType type, + const net::NetLog::ParametersCallback& callback) { + scoped_ptr event = BuildDataReductionProxyEvent( + type, net::NetLog::Source(), net::NetLog::PHASE_NONE, callback); + if (event.get()) { + network_task_runner_->PostTask( + FROM_HERE, + base::Bind(&DataReductionProxyEventStore::AddEventOnIOThread, + base::Unretained(this), + base::Passed(&event))); + } + + if (net_log) + net_log->AddGlobalEntry(type, callback); +} + +void DataReductionProxyEventStore::PostBoundNetLogEvent( + const net::BoundNetLog& net_log, + net::NetLog::EventType type, + net::NetLog::EventPhase phase, + const net::NetLog::ParametersCallback& callback) { + scoped_ptr event = BuildDataReductionProxyEvent( + type, net_log.source(), phase, callback); + if (event.get()) { + network_task_runner_->PostTask( + FROM_HERE, + base::Bind(&DataReductionProxyEventStore::AddEventOnIOThread, + base::Unretained(this), + base::Passed(&event))); + } + + net_log.AddEntry(type, phase, callback); +} + +void DataReductionProxyEventStore::AddEventOnIOThread( + scoped_ptr entry) { + DCHECK(network_task_runner_->BelongsToCurrentThread()); + if (stored_events_.size() == kMaxEventsToStore) { + base::Value* head = stored_events_.front(); + stored_events_.pop_front(); + delete head; + } + + stored_events_.push_back(entry.release()); +} + +} // namespace data_reduction_proxy diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h new file mode 100644 index 000000000000..f8517a4e8f5d --- /dev/null +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h @@ -0,0 +1,119 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_COMMON_DATA_REDUCTION_PROXY_EVENT_STORE_H_ +#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_COMMON_DATA_REDUCTION_PROXY_EVENT_STORE_H_ + +#include +#include + +#include "base/gtest_prod_util.h" +#include "base/memory/ref_counted.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" + +class GURL; + +namespace base { +class SingleThreadTaskRunner; +class TimeDelta; +class Value; +} + +namespace net { +class BoundNetLog; +class NetLog; +} + +namespace data_reduction_proxy { + +class DataReductionProxyEventStore { + public: + // Constructs a DataReductionProxyEventStore object with the given network + // task runner. + explicit DataReductionProxyEventStore( + const scoped_refptr& network_task_runner); + + ~DataReductionProxyEventStore(); + + // Adds the DATA_REDUCTION_PROXY_ENABLED event (with enabled=true) to the + // event store. + void AddProxyEnabledEvent( + net::NetLog* net_log, + bool primary_restricted, + bool fallback_restricted, + const std::string& primary_origin, + const std::string& fallback_origin, + const std::string& ssl_origin); + + // Adds the DATA_REDUCTION_PROXY_ENABLED event (with enabled=false) to the + // event store. + void AddProxyDisabledEvent(net::NetLog* net_log); + + // Adds a DATA_REDUCTION_PROXY_BYPASS_REQUESTED event to the event store + // when the bypass reason is initiated by the data reduction proxy. + void AddBypassActionEvent( + const net::BoundNetLog& net_log, + const std::string& bypass_action, + const GURL& gurl, + const base::TimeDelta& bypass_duration); + + // Adds a DATA_REDUCTION_PROXY_BYPASS_REQUESTED event to the event store + // when the bypass reason is not initiated by the data reduction proxy, such + // as network errors. + void AddBypassTypeEvent( + const net::BoundNetLog& net_log, + DataReductionProxyBypassType bypass_type, + const GURL& gurl, + const base::TimeDelta& bypass_duration); + + // Adds a DATA_REDUCTION_PROXY_CANARY_REQUEST event to the event store + // when the canary request has started. + void BeginCanaryRequest(const net::BoundNetLog& net_log, const GURL& gurl); + + // Adds a DATA_REDUCTION_PROXY_CANARY_REQUEST event to the event store + // when the canary request has ended. + void EndCanaryRequest(const net::BoundNetLog& net_log, int net_error); + + private: + friend class DataReductionProxyEventStoreTest; + FRIEND_TEST_ALL_PREFIXES(DataReductionProxyEventStoreTest, + TestAddProxyEnabledEvent); + FRIEND_TEST_ALL_PREFIXES(DataReductionProxyEventStoreTest, + TestAddProxyDisabledEvent); + FRIEND_TEST_ALL_PREFIXES(DataReductionProxyEventStoreTest, + TestAddBypassActionEvent); + FRIEND_TEST_ALL_PREFIXES(DataReductionProxyEventStoreTest, + TestAddBypassTypeEvent); + FRIEND_TEST_ALL_PREFIXES(DataReductionProxyEventStoreTest, + TestBeginCanaryRequest); + FRIEND_TEST_ALL_PREFIXES(DataReductionProxyEventStoreTest, + TestEndCanaryRequest); + + // Prepare and post an event for the event_store on the global net_log. + void PostGlobalNetLogEvent(net::NetLog* net_log, + net::NetLog::EventType type, + const net::NetLog::ParametersCallback& callback); + + // Prepare and post an event for the event_store on a BoundNetLog. + void PostBoundNetLogEvent(const net::BoundNetLog& net_log, + net::NetLog::EventType type, + net::NetLog::EventPhase phase, + const net::NetLog::ParametersCallback& callback); + + // Put |entry| on a deque of events to store + void AddEventOnIOThread(scoped_ptr entry); + + // A task runner to ensure that all reads/writes to |stored_events_| takes + // place on the IO thread. + scoped_refptr network_task_runner_; + // A deque of data reduction proxy related events. It is used as a circular + // buffer to prevent unbounded memory utilization. + std::deque stored_events_; + + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyEventStore); +}; + +} // namespace data_reduction_proxy + +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_COMMON_DATA_REDUCTION_PROXY_EVENT_STORE_H_ diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store_unittest.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store_unittest.cc new file mode 100644 index 000000000000..2f4b60300830 --- /dev/null +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store_unittest.cc @@ -0,0 +1,132 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" + +#include "base/bind.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/strings/string_number_conversions.h" +#include "base/test/test_simple_task_runner.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" +#include "net/base/capturing_net_log.h" +#include "net/base/net_log.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace data_reduction_proxy { + +class DataReductionProxyEventStoreTest : public testing::Test { + public: + DataReductionProxyEventStoreTest() + : task_runner_(scoped_refptr( + new base::TestSimpleTaskRunner())), + net_log_(new net::CapturingNetLog()) { + bound_net_log_ = net::BoundNetLog::Make( + net_log_.get(), net::NetLog::SOURCE_DATA_REDUCTION_PROXY); + } + + void SetUp() override { + proxy_.reset(new DataReductionProxyEventStore(task_runner_)); + } + + net::CapturingNetLog::CapturedEntry GetSingleEntry() const { + net::CapturingNetLog::CapturedEntryList entries; + net_log_->GetEntries(&entries); + EXPECT_EQ(1u, entries.size()); + return entries[0]; + } + + DataReductionProxyEventStore* proxy() { + return proxy_.get(); + } + + base::TestSimpleTaskRunner* task_runner() { + return task_runner_.get(); + } + + net::CapturingNetLog* net_log() { + return net_log_.get(); + } + + const net::BoundNetLog& bound_net_log() { + return bound_net_log_; + } + + private: + scoped_refptr task_runner_; + scoped_ptr net_log_; + scoped_ptr proxy_; + net::BoundNetLog bound_net_log_; +}; + +TEST_F(DataReductionProxyEventStoreTest, TestAddProxyEnabledEvent) { + EXPECT_EQ(0u, proxy()->stored_events_.size()); + proxy()->AddProxyEnabledEvent( + net_log(), false, false, + TestDataReductionProxyParams::DefaultOrigin(), + TestDataReductionProxyParams::DefaultFallbackOrigin(), + TestDataReductionProxyParams::DefaultSSLOrigin()); + task_runner()->RunPendingTasks(); + EXPECT_EQ(1u, proxy()->stored_events_.size()); + net::CapturingNetLog::CapturedEntry entry = GetSingleEntry(); + EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_ENABLED, + entry.type); +} + +TEST_F(DataReductionProxyEventStoreTest, TestAddProxyDisabledEvent) { + EXPECT_EQ(0u, proxy()->stored_events_.size()); + proxy()->AddProxyDisabledEvent(net_log()); + task_runner()->RunPendingTasks(); + EXPECT_EQ(1u, proxy()->stored_events_.size()); + net::CapturingNetLog::CapturedEntry entry = GetSingleEntry(); + EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_ENABLED, + entry.type); +} + +TEST_F(DataReductionProxyEventStoreTest, TestAddBypassActionEvent) { + EXPECT_EQ(0u, proxy()->stored_events_.size()); + proxy()->AddBypassActionEvent(bound_net_log(), "bypass", GURL(), + base::TimeDelta::FromMinutes(1)); + task_runner()->RunPendingTasks(); + EXPECT_EQ(1u, proxy()->stored_events_.size()); + net::CapturingNetLog::CapturedEntry entry = GetSingleEntry(); + EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED, + entry.type); +} + +TEST_F(DataReductionProxyEventStoreTest, TestAddBypassTypeEvent) { + EXPECT_EQ(0u, proxy()->stored_events_.size()); + proxy()->AddBypassTypeEvent(bound_net_log(), BYPASS_EVENT_TYPE_LONG, GURL(), + base::TimeDelta::FromMinutes(1)); + task_runner()->RunPendingTasks(); + EXPECT_EQ(1u, proxy()->stored_events_.size()); + EXPECT_EQ(1u, net_log()->GetSize()); + net::CapturingNetLog::CapturedEntry entry = GetSingleEntry(); + EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED, + entry.type); +} + +TEST_F(DataReductionProxyEventStoreTest, TestBeginCanaryRequest) { + EXPECT_EQ(0u, proxy()->stored_events_.size()); + proxy()->BeginCanaryRequest(bound_net_log(), GURL()); + task_runner()->RunPendingTasks(); + EXPECT_EQ(1u, proxy()->stored_events_.size()); + EXPECT_EQ(1u, net_log()->GetSize()); + net::CapturingNetLog::CapturedEntry entry = GetSingleEntry(); + EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST, + entry.type); +} + +TEST_F(DataReductionProxyEventStoreTest, TestEndCanaryRequest) { + EXPECT_EQ(0u, proxy()->stored_events_.size()); + proxy()->EndCanaryRequest(bound_net_log(), 0); + task_runner()->RunPendingTasks(); + EXPECT_EQ(1u, proxy()->stored_events_.size()); + EXPECT_EQ(1u, net_log()->GetSize()); + net::CapturingNetLog::CapturedEntry entry = GetSingleEntry(); + EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST, + entry.type); +} + +} // namespace data_reduction_proxy diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc index 4c6a6afe614d..2e820c2a1265 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc @@ -12,6 +12,7 @@ #include "base/strings/string_piece.h" #include "base/strings/string_util.h" #include "base/time/time.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "net/http/http_response_headers.h" #include "net/http/http_status_code.h" @@ -111,8 +112,12 @@ bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers, } bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders* headers, - DataReductionProxyInfo* proxy_info) { + const GURL& url, + const net::BoundNetLog& bound_net_log, + DataReductionProxyInfo* proxy_info, + DataReductionProxyEventStore* event_store) { DCHECK(proxy_info); + DCHECK(event_store); // Support header of the form Chrome-Proxy: bypass|block=, where // is the number of seconds to wait before retrying @@ -129,6 +134,8 @@ bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders* headers, headers, kChromeProxyActionBlock, &proxy_info->bypass_duration)) { proxy_info->bypass_all = true; proxy_info->mark_proxies_as_bad = true; + event_store->AddBypassActionEvent(bound_net_log, kChromeProxyActionBlock, + url, proxy_info->bypass_duration); return true; } @@ -137,6 +144,8 @@ bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders* headers, headers, kChromeProxyActionBypass, &proxy_info->bypass_duration)) { proxy_info->bypass_all = false; proxy_info->mark_proxies_as_bad = true; + event_store->AddBypassActionEvent(bound_net_log, kChromeProxyActionBypass, + url, proxy_info->bypass_duration); return true; } @@ -150,6 +159,9 @@ bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders* headers, proxy_info->bypass_all = true; proxy_info->mark_proxies_as_bad = false; proxy_info->bypass_duration = TimeDelta(); + event_store->AddBypassActionEvent(bound_net_log, + kChromeProxyActionBlockOnce, url, + proxy_info->bypass_duration); return true; } @@ -194,9 +206,19 @@ bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers, DataReductionProxyBypassType GetDataReductionProxyBypassType( const net::HttpResponseHeaders* headers, - DataReductionProxyInfo* data_reduction_proxy_info) { + const GURL& url, + const net::BoundNetLog& bound_net_log, + DataReductionProxyInfo* data_reduction_proxy_info, + DataReductionProxyEventStore* event_store, + bool* event_logged) { DCHECK(data_reduction_proxy_info); - if (ParseHeadersAndSetProxyInfo(headers, data_reduction_proxy_info)) { + if (ParseHeadersAndSetProxyInfo(headers, + url, + bound_net_log, + data_reduction_proxy_info, + event_store)) { + *event_logged = true; + // A chrome-proxy response header is only present in a 502. For proper // reporting, this check must come before the 5xx checks below. if (!data_reduction_proxy_info->mark_proxies_as_bad) diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h index 13bcc54ae030..b4d8ec8c1a37 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h @@ -11,6 +11,8 @@ #include "base/time/time.h" #include "net/proxy/proxy_service.h" +class GURL; + namespace net { class HttpResponseHeaders; @@ -19,6 +21,8 @@ class HttpResponseHeaders; namespace data_reduction_proxy { +class DataReductionProxyEventStore; + // Values of the UMA DataReductionProxy.BypassType{Primary|Fallback} // and DataReductionProxy.BlockType{Primary|Fallback} histograms. // This enum must remain synchronized with the enum of the same @@ -86,7 +90,10 @@ struct DataReductionProxyInfo { // If all available data reduction proxies should by bypassed, |bypass_all| is // set to true. |proxy_info| must be non-NULL. bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders* headers, - DataReductionProxyInfo* proxy_info); + const GURL& url, + const net::BoundNetLog& bound_net_log, + DataReductionProxyInfo* proxy_info, + DataReductionProxyEventStore* event_store); // Returns true if the response contains the data reduction proxy Via header // value. If non-NULL, sets |has_intermediary| to true if another server added @@ -101,7 +108,11 @@ bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers, // applicable. DataReductionProxyBypassType GetDataReductionProxyBypassType( const net::HttpResponseHeaders* headers, - DataReductionProxyInfo* proxy_info); + const GURL& url, + const net::BoundNetLog& bound_net_log, + DataReductionProxyInfo* proxy_info, + DataReductionProxyEventStore* event_store, + bool* event_logged); // Searches for the specified Chrome-Proxy action, and if present saves its // value as a string in |action_value|. Only returns the first one and ignores diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc index 6bbe07cf0863..70a0c1b44dfc 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc @@ -6,6 +6,8 @@ #include +#include "base/test/test_simple_task_runner.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h" #include "net/http/http_response_headers.h" #include "net/proxy/proxy_service.h" @@ -13,7 +15,19 @@ namespace data_reduction_proxy { -class DataReductionProxyHeadersTest : public testing::Test {}; +class DataReductionProxyHeadersTest : public testing::Test { + public: + DataReductionProxyHeadersTest() + : task_runner_(scoped_refptr( + new base::TestSimpleTaskRunner())) {} + + void SetUp() override { + event_store_.reset(new DataReductionProxyEventStore(task_runner_)); + } + + scoped_refptr task_runner_; + scoped_ptr event_store_; +}; TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) { const struct { @@ -352,7 +366,11 @@ TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { DataReductionProxyInfo data_reduction_proxy_info; EXPECT_EQ( tests[i].expected_result, - ParseHeadersAndSetProxyInfo(parsed.get(), &data_reduction_proxy_info)); + ParseHeadersAndSetProxyInfo(parsed.get(), + GURL(), + net::BoundNetLog(), + &data_reduction_proxy_info, + event_store_.get())); EXPECT_EQ(tests[i].expected_retry_delay, data_reduction_proxy_info.bypass_duration.InSeconds()); EXPECT_EQ(tests[i].expected_bypass_all, @@ -374,7 +392,11 @@ TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) { DataReductionProxyInfo data_reduction_proxy_info; EXPECT_TRUE( - ParseHeadersAndSetProxyInfo(parsed.get(), &data_reduction_proxy_info)); + ParseHeadersAndSetProxyInfo(parsed.get(), + GURL(), + net::BoundNetLog(), + &data_reduction_proxy_info, + event_store_.get())); EXPECT_LE(60, data_reduction_proxy_info.bypass_duration.InSeconds()); EXPECT_GE(5 * 60, data_reduction_proxy_info.bypass_duration.InSeconds()); EXPECT_FALSE(data_reduction_proxy_info.bypass_all); @@ -624,9 +646,16 @@ TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { scoped_refptr parsed( new net::HttpResponseHeaders(headers)); DataReductionProxyInfo chrome_proxy_info; + bool event_was_logged; EXPECT_EQ( tests[i].expected_result, - GetDataReductionProxyBypassType(parsed.get(), &chrome_proxy_info)); + GetDataReductionProxyBypassType( + parsed.get(), + GURL(), + net::BoundNetLog(), + &chrome_proxy_info, + event_store_.get(), + &event_was_logged)); } } diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h index d6e61878acb0..ce303600417b 100644 --- a/net/base/net_log_event_type_list.h +++ b/net/base/net_log_event_type_list.h @@ -2418,3 +2418,64 @@ EVENT_TYPE(SDCH_DICTIONARY_FETCH) // "net_error": // } EVENT_TYPE(SDCH_DICTIONARY_FETCH_IMPLIED_ERROR) + +// ----------------------------------------------------------------------------- +// Data Reduction Proxy events. +// ----------------------------------------------------------------------------- + +// This event is created when the data reduction proxy has been turned on or +// off. It always contains the parameter: +// { +// "enabled": +// } +// +// If it is enabled, it contains additional parameters: +// { +// "primary_restricted": , +// "fallback_restricted": , +// "primary_origin": , +// "fallback_origin": , +// "ssl_origin": , +// } +EVENT_TYPE(DATA_REDUCTION_PROXY_ENABLED) + +// The start/end of a canary request is sent to the data reduction proxy. +// +// The BEGIN phase contains the following parameters: +// { +// "url": , +// } +// +// The END phase contains the following parameters: +// { +// "net_error": , +// } +EVENT_TYPE(DATA_REDUCTION_PROXY_CANARY_REQUEST) + +// This event is created when a response to the canary request has been +// received with the following parameters: +// { +// "headers": , +// } +EVENT_TYPE(DATA_REDUCTION_PROXY_CANARY_RESPONSE_RECEIVED) + +// This event is created when a bypass event takes place with the following +// parameters: +// { +// "action": , +// "bypass_type": , +// "url": , +// "bypass_duration_seconds": , +// } +EVENT_TYPE(DATA_REDUCTION_PROXY_BYPASS_REQUESTED) + +// This event is created when the data reduction proxy configuration changes +// (i.e. a switch between primary and fallback) with the following parameters: +// { +// "proxy_server": , +// "net_error": , +// } +EVENT_TYPE(DATA_REDUCTION_PROXY_FALLBACK) diff --git a/net/base/net_log_source_type_list.h b/net/base/net_log_source_type_list.h index dc553a45141c..dbad470cc5dd 100644 --- a/net/base/net_log_source_type_list.h +++ b/net/base/net_log_source_type_list.h @@ -27,3 +27,4 @@ SOURCE_TYPE(DNS_PROBER) SOURCE_TYPE(PROXY_CLIENT_SOCKET) SOURCE_TYPE(IPV6_REACHABILITY_CHECK) SOURCE_TYPE(ASYNC_REVALIDATION) +SOURCE_TYPE(DATA_REDUCTION_PROXY) -- 2.11.4.GIT