diff options
author | jeremyim <jeremyim@chromium.org> | 2015-04-27 14:38:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-27 21:38:36 +0000 |
commit | a0ad227fe2d8630e34c1bc7c752957b2666c01ff (patch) | |
tree | 6052bfc4ba1bb489faa06b6ac4aa2c5cc6bc84bd /components/data_reduction_proxy | |
parent | 9313fe919a3ff8457bddb2fa1cb04784156a0823 (diff) | |
download | chromium_src-a0ad227fe2d8630e34c1bc7c752957b2666c01ff.zip chromium_src-a0ad227fe2d8630e34c1bc7c752957b2666c01ff.tar.gz chromium_src-a0ad227fe2d8630e34c1bc7c752957b2666c01ff.tar.bz2 |
Remove BooleanPrefMember usage from Data Reduction Proxy IO classes.
The UI objects (specifically DataReductionProxySettings) already creates
a BooleanPrefMember for kDataReductionProxyEnabled and checks for changes
on it, then propagates this information to DataReductionProxyIOData via
DataReductionProxyIOData::SetProxyPrefs.
It also negates the need to pass a BooleanPrefMember to BypassStats when
ultimately all we care about is the boolean value.
BUG=472290
Review URL: https://codereview.chromium.org/1057473003
Cr-Commit-Position: refs/heads/master@{#327138}
Diffstat (limited to 'components/data_reduction_proxy')
12 files changed, 45 insertions, 79 deletions
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.cc index 87e94d2..d179657 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.cc @@ -7,7 +7,6 @@ #include "base/callback.h" #include "base/metrics/histogram.h" #include "base/metrics/sparse_histogram.h" -#include "base/prefs/pref_member.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" @@ -170,7 +169,7 @@ DataReductionProxyBypassStats::GetBypassType() const { void DataReductionProxyBypassStats::RecordBytesHistograms( const net::URLRequest& request, - const BooleanPrefMember& data_reduction_proxy_enabled, + bool data_reduction_proxy_enabled, const net::ProxyConfig& data_reduction_proxy_config) { RecordBypassedBytesHistograms(request, data_reduction_proxy_enabled, data_reduction_proxy_config); @@ -226,12 +225,12 @@ void DataReductionProxyBypassStats::OnConnectComplete( void DataReductionProxyBypassStats::RecordBypassedBytesHistograms( const net::URLRequest& request, - const BooleanPrefMember& data_reduction_proxy_enabled, + bool data_reduction_proxy_enabled, const net::ProxyConfig& data_reduction_proxy_config) { int64 content_length = request.received_response_content_length(); // Only record histograms when the data reduction proxy is enabled. - if (!data_reduction_proxy_enabled.GetValue()) + if (!data_reduction_proxy_enabled) return; // TODO(bengr): Add histogram(s) for byte counts of unsupported schemes, e.g., diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.h index efff8d1..dcec95e 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.h @@ -6,7 +6,6 @@ #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_BYPASS_STATS_H_ #include "base/callback.h" -#include "base/prefs/pref_member.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" #include "net/base/host_port_pair.h" #include "net/base/network_change_notifier.h" @@ -68,7 +67,7 @@ class DataReductionProxyBypassStats // completed URLRequest |request|. void RecordBytesHistograms( const net::URLRequest& request, - const BooleanPrefMember& data_reduction_proxy_enabled, + bool data_reduction_proxy_enabled, const net::ProxyConfig& data_reduction_proxy_config); // Called by |ChromeNetworkDelegate| when a proxy is put into the bad proxy @@ -104,7 +103,7 @@ class DataReductionProxyBypassStats // tells us the state of the kDataReductionProxyEnabled preference. void RecordBypassedBytesHistograms( const net::URLRequest& request, - const BooleanPrefMember& data_reduction_proxy_enabled, + bool data_reduction_proxy_enabled, const net::ProxyConfig& data_reduction_proxy_config); // Records UMA of the number of response bytes of responses that are expected diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc index 5a4c5d8..37ecf96 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc @@ -5,11 +5,8 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h" #include "base/bind.h" -#include "base/command_line.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "base/prefs/pref_member.h" -#include "base/single_thread_task_runner.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h" @@ -93,13 +90,14 @@ DataReductionProxyIOData::DataReductionProxyIOData( net::NetLog* net_log, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + bool enabled, bool enable_quic, const std::string& user_agent) : client_(client), net_log_(net_log), io_task_runner_(io_task_runner), ui_task_runner_(ui_task_runner), - shutdown_on_ui_(false), + enabled_(enabled), url_request_context_getter_(nullptr), basic_url_request_context_getter_( new BasicHTTPURLRequestContextGetter(user_agent, io_task_runner)), @@ -148,26 +146,14 @@ DataReductionProxyIOData::DataReductionProxyIOData( } DataReductionProxyIOData::DataReductionProxyIOData() - : shutdown_on_ui_(false), - url_request_context_getter_(nullptr), - weak_factory_(this) { + : url_request_context_getter_(nullptr), weak_factory_(this) { } DataReductionProxyIOData::~DataReductionProxyIOData() { - DCHECK(shutdown_on_ui_); -} - -void DataReductionProxyIOData::InitOnUIThread(PrefService* pref_service) { - DCHECK(ui_task_runner_->BelongsToCurrentThread()); - enabled_.Init(prefs::kDataReductionProxyEnabled, pref_service); - enabled_.MoveToThread(io_task_runner_); } void DataReductionProxyIOData::ShutdownOnUIThread() { - DCHECK(!shutdown_on_ui_); DCHECK(ui_task_runner_->BelongsToCurrentThread()); - enabled_.Destroy(); - shutdown_on_ui_ = true; } void DataReductionProxyIOData::SetDataReductionProxyService( @@ -197,9 +183,7 @@ void DataReductionProxyIOData::InitializeOnIOThread() { bool DataReductionProxyIOData::IsEnabled() const { DCHECK(io_task_runner_->BelongsToCurrentThread()); - return enabled_.GetValue() || - base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableDataReductionProxy); + return enabled_; } void DataReductionProxyIOData::RetrieveConfig() { @@ -225,7 +209,7 @@ DataReductionProxyIOData::CreateNetworkDelegate( wrapped_network_delegate.Pass(), config_.get(), request_options_.get(), configurator_.get())); if (track_proxy_bypass_statistics) - network_delegate->InitIODataAndUMA(this, &enabled_, bypass_stats_.get()); + network_delegate->InitIODataAndUMA(this, bypass_stats_.get()); return network_delegate.Pass(); } @@ -233,6 +217,7 @@ void DataReductionProxyIOData::SetProxyPrefs(bool enabled, bool alternative_enabled, bool at_startup) { DCHECK(io_task_runner_->BelongsToCurrentThread()); + enabled_ = enabled; config_->SetProxyConfig(enabled, alternative_enabled, at_startup); } diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h index 9a6f3b8..4acbc48 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h @@ -9,7 +9,7 @@ #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/prefs/pref_member.h" +#include "base/single_thread_task_runner.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_debug_ui_service.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h" @@ -42,23 +42,21 @@ class DataReductionProxyIOData : public DataReductionProxyEventStorageDelegate { public: // Constructs a DataReductionProxyIOData object. |param_flags| is used to // set information about the DNS names used by the proxy, and allowable - // configurations. + // configurations. |enabled| sets the initial state of the Data Reduction + // Proxy. DataReductionProxyIOData( const Client& client, int param_flags, net::NetLog* net_log, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + bool enabled, bool enable_quic, const std::string& user_agent); virtual ~DataReductionProxyIOData(); - // Initializes preferences, including a preference to track whether the - // Data Reduction Proxy is enabled. - void InitOnUIThread(PrefService* pref_service); - - // Destroys the statistics preferences. + // Performs UI thread specific shutdown logic. void ShutdownOnUIThread(); // Sets the Data Reduction Proxy service after it has been created. @@ -205,12 +203,9 @@ class DataReductionProxyIOData : public DataReductionProxyEventStorageDelegate { scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; - // Used - bool shutdown_on_ui_; - - // Preference that determines if the Data Reduction Proxy has been enabled - // by the user. In practice, this can be overridden by the command line. - BooleanPrefMember enabled_; + // Whether the Data Reduction Proxy has been enabled or not by the user. In + // practice, this can be overridden by the command line. + bool enabled_; // The net::URLRequestContextGetter used for making URL requests. net::URLRequestContextGetter* url_request_context_getter_; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc index 4caf215..24fc634 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc @@ -94,8 +94,8 @@ class DataReductionProxyIODataTest : public testing::Test { TEST_F(DataReductionProxyIODataTest, TestConstruction) { scoped_ptr<DataReductionProxyIOData> io_data(new DataReductionProxyIOData( Client::UNKNOWN, DataReductionProxyParams::kAllowed, net_log(), - message_loop_proxy(), message_loop_proxy(), false /* enable_quic */, - std::string() /* user_agent */)); + message_loop_proxy(), message_loop_proxy(), false /* enabled */, + false /* enable_quic */, std::string() /* user_agent */)); // Check that the SimpleURLRequestContextGetter uses vanilla HTTP. net::URLRequestContext* request_context = @@ -141,9 +141,6 @@ TEST_F(DataReductionProxyIODataTest, TestConstruction) { true); EXPECT_NE(nullptr, io_data->bypass_stats()); - // The Data Reduction Proxy isn't actually enabled here. - io_data->InitOnUIThread(prefs()); - EXPECT_FALSE(io_data->IsEnabled()); io_data->ShutdownOnUIThread(); } diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc index 6ef70dc..9a66acd 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/metrics/histogram.h" -#include "base/prefs/pref_service.h" #include "base/strings/string_number_conversions.h" #include "base/time/time.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.h" @@ -81,7 +80,6 @@ DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate( : LayeredNetworkDelegate(network_delegate.Pass()), received_content_length_(0), original_content_length_(0), - data_reduction_proxy_enabled_(nullptr), data_reduction_proxy_config_(config), data_reduction_proxy_bypass_stats_(nullptr), data_reduction_proxy_request_options_(request_options), @@ -96,12 +94,9 @@ DataReductionProxyNetworkDelegate::~DataReductionProxyNetworkDelegate() { void DataReductionProxyNetworkDelegate::InitIODataAndUMA( DataReductionProxyIOData* io_data, - BooleanPrefMember* data_reduction_proxy_enabled, DataReductionProxyBypassStats* bypass_stats) { - DCHECK(data_reduction_proxy_enabled); DCHECK(bypass_stats); data_reduction_proxy_io_data_ = io_data; - data_reduction_proxy_enabled_ = data_reduction_proxy_enabled; data_reduction_proxy_bypass_stats_ = bypass_stats; } @@ -191,10 +186,9 @@ void DataReductionProxyNetworkDelegate::OnCompletedInternal( original_content_length, freshness_lifetime); - if (data_reduction_proxy_enabled_ && - data_reduction_proxy_bypass_stats_) { + if (data_reduction_proxy_io_data_ && data_reduction_proxy_bypass_stats_) { data_reduction_proxy_bypass_stats_->RecordBytesHistograms( - *request, *data_reduction_proxy_enabled_, + *request, data_reduction_proxy_io_data_->IsEnabled(), configurator_->GetProxyConfig()); } DVLOG(2) << __FUNCTION__ @@ -210,10 +204,10 @@ void DataReductionProxyNetworkDelegate::AccumulateContentLength( DataReductionProxyRequestType request_type) { DCHECK_GE(received_content_length, 0); DCHECK_GE(original_content_length, 0); - if (data_reduction_proxy_enabled_) { + if (data_reduction_proxy_io_data_) { data_reduction_proxy_io_data_->UpdateContentLengths( received_content_length, original_content_length, - data_reduction_proxy_enabled_->GetValue(), request_type); + data_reduction_proxy_io_data_->IsEnabled(), request_type); } received_content_length_ += received_content_length; original_content_length_ += original_content_length; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h index 8cb016e..0290d6e 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h @@ -13,12 +13,7 @@ #include "net/base/layered_network_delegate.h" #include "net/proxy/proxy_retry_info.h" -template<class T> class PrefMember; - -typedef PrefMember<bool> BooleanPrefMember; - class GURL; -class PrefService; namespace net { class HttpResponseHeaders; @@ -64,7 +59,6 @@ class DataReductionProxyNetworkDelegate : public net::LayeredNetworkDelegate { // report UMA. void InitIODataAndUMA( DataReductionProxyIOData* io_data, - BooleanPrefMember* data_reduction_proxy_enabled, DataReductionProxyBypassStats* bypass_stats); // Creates a |Value| summary of the state of the network session. The caller @@ -117,9 +111,6 @@ class DataReductionProxyNetworkDelegate : public net::LayeredNetworkDelegate { // Total original size of all content before it was transferred. int64 original_content_length_; - // Weak, owned by our owner. - BooleanPrefMember* data_reduction_proxy_enabled_; - // All raw Data Reduction Proxy pointers must outlive |this|. DataReductionProxyConfig* data_reduction_proxy_config_; 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 57f18bb..0c5b802b 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 @@ -13,6 +13,7 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.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" @@ -21,13 +22,6 @@ namespace { const char kUMAProxyStartupStateHistogram[] = "DataReductionProxy.StartupState"; -bool IsEnabledOnCommandLine() { - const base::CommandLine& command_line = - *base::CommandLine::ForCurrentProcess(); - return command_line.HasSwitch( - data_reduction_proxy::switches::kEnableDataReductionProxy); -} - bool IsLoFiEnabledOnCommandLine() { const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); @@ -116,7 +110,8 @@ void DataReductionProxySettings::SetCallbackToRegisterSyntheticFieldTrial( } bool DataReductionProxySettings::IsDataReductionProxyEnabled() const { - return spdy_proxy_auth_enabled_.GetValue() || IsEnabledOnCommandLine(); + return spdy_proxy_auth_enabled_.GetValue() || + DataReductionProxyParams::ShouldForceEnableDataReductionProxy(); } bool DataReductionProxySettings::CanUseDataReductionProxy( diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc index c784796..f71ce8d 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc @@ -177,7 +177,8 @@ TestDataReductionProxyIOData::TestDataReductionProxyIOData( scoped_ptr<DataReductionProxyEventCreator> event_creator, scoped_ptr<DataReductionProxyRequestOptions> request_options, scoped_ptr<DataReductionProxyConfigurator> configurator, - scoped_ptr<DataReductionProxyConfigServiceClient> config_client) + scoped_ptr<DataReductionProxyConfigServiceClient> config_client, + bool enabled) : DataReductionProxyIOData() { io_task_runner_ = task_runner; ui_task_runner_ = task_runner; @@ -191,10 +192,10 @@ TestDataReductionProxyIOData::TestDataReductionProxyIOData( base::Unretained(this)))); io_task_runner_ = task_runner; ui_task_runner_ = task_runner; + enabled_ = enabled; } TestDataReductionProxyIOData::~TestDataReductionProxyIOData() { - shutdown_on_ui_ = true; } DataReductionProxyTestContext::Builder::Builder() @@ -386,8 +387,8 @@ DataReductionProxyTestContext::Builder::Build() { scoped_ptr<TestDataReductionProxyIOData> io_data( new TestDataReductionProxyIOData( task_runner, config.Pass(), event_creator.Pass(), - request_options.Pass(), configurator.Pass(), config_client.Pass())); - io_data->InitOnUIThread(pref_service.get()); + request_options.Pass(), configurator.Pass(), config_client.Pass(), + true /* enabled */)); io_data->SetSimpleURLRequestContextGetter(request_context_getter); scoped_ptr<DataReductionProxyTestContext> test_context( diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h index e199098..81a8984 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h @@ -167,7 +167,8 @@ class TestDataReductionProxyIOData : public DataReductionProxyIOData { scoped_ptr<DataReductionProxyEventCreator> event_creator, scoped_ptr<DataReductionProxyRequestOptions> request_options, scoped_ptr<DataReductionProxyConfigurator> configurator, - scoped_ptr<DataReductionProxyConfigServiceClient> config_client); + scoped_ptr<DataReductionProxyConfigServiceClient> config_client, + bool enabled); ~TestDataReductionProxyIOData() override; DataReductionProxyConfigurator* configurator() const { diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc index 79205a2..d62b73b 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc @@ -102,7 +102,6 @@ bool DataReductionProxyParams::IsIncludedInAndroidOnePromoFieldTrial( bool DataReductionProxyParams::IsLoFiEnabled() { return base::CommandLine::ForCurrentProcess()->HasSwitch( data_reduction_proxy::switches::kEnableDataReductionProxyLoFi); - } //static @@ -136,6 +135,12 @@ bool DataReductionProxyParams::IsConfigClientEnabled() { data_reduction_proxy::switches::kEnableDataReductionProxyConfigClient); } +// static +bool DataReductionProxyParams::ShouldForceEnableDataReductionProxy() { + return base::CommandLine::ForCurrentProcess()->HasSwitch( + data_reduction_proxy::switches::kEnableDataReductionProxy); +} + void DataReductionProxyParams::EnableQuic(bool enable) { quic_enabled_ = enable; DCHECK(!quic_enabled_ || IsIncludedInQuicFieldTrial()); diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h index 0f6aea8..fe345ec 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h @@ -116,6 +116,10 @@ class DataReductionProxyParams : public DataReductionProxyConfigValues { // Returns true if the Data Reduction Proxy config client should be used. static bool IsConfigClientEnabled(); + // Returns true if the Data Reduction Proxy is forced to be enabled from the + // command line. + static bool ShouldForceEnableDataReductionProxy(); + // Constructs configuration parameters. If |kAllowed|, then the standard // data reduction proxy configuration is allowed to be used. If // |kfallbackAllowed| a fallback proxy can be used if the primary proxy is |