Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc |
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 88aa3176d0f6ae6ec6f3c7122300840a353426b4..233ba217d0eac4a147fc4dec3e6c7b7998c4c8df 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 |
@@ -6,66 +6,24 @@ |
#include "base/bind.h" |
#include "base/command_line.h" |
-#include "base/metrics/field_trial.h" |
#include "base/metrics/histogram.h" |
-#include "base/metrics/sparse_histogram.h" |
#include "base/prefs/pref_member.h" |
#include "base/prefs/pref_service.h" |
-#include "base/prefs/scoped_user_pref_update.h" |
#include "base/strings/string_number_conversions.h" |
-#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_config.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 "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" |
-#include "net/base/host_port_pair.h" |
-#include "net/base/load_flags.h" |
-#include "net/base/net_errors.h" |
-#include "net/base/net_util.h" |
-#include "net/http/http_network_session.h" |
-#include "net/http/http_response_headers.h" |
-#include "net/url_request/url_fetcher.h" |
-#include "net/url_request/url_fetcher_delegate.h" |
-#include "net/url_request/url_request_context_getter.h" |
-#include "net/url_request/url_request_status.h" |
-#include "url/gurl.h" |
- |
- |
-using base::StringPrintf; |
namespace { |
-// Values of the UMA DataReductionProxy.NetworkChangeEvents histograms. |
-// This enum must remain synchronized with the enum of the same |
-// name in metrics/histograms/histograms.xml. |
-enum DataReductionProxyNetworkChangeEvent { |
- IP_CHANGED = 0, // The client IP address changed. |
- DISABLED_ON_VPN = 1, // The proxy is disabled because a VPN is running. |
- CHANGE_EVENT_COUNT = 2 // This must always be last. |
-}; |
- |
// Key of the UMA DataReductionProxy.StartupState histogram. |
const char kUMAProxyStartupStateHistogram[] = |
"DataReductionProxy.StartupState"; |
-// Key of the UMA DataReductionProxy.ProbeURL histogram. |
-const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL"; |
- |
-// Key of the UMA DataReductionProxy.ProbeURLNetError histogram. |
-const char kUMAProxyProbeURLNetError[] = "DataReductionProxy.ProbeURLNetError"; |
- |
-// Record a network change event. |
-void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) { |
- UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents", |
- event, |
- CHANGE_EVENT_COUNT); |
-} |
- |
int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) { |
int64 val = 0; |
std::string pref_value; |
@@ -89,25 +47,19 @@ bool IsEnabledOnCommandLine() { |
namespace data_reduction_proxy { |
-DataReductionProxySettings::DataReductionProxySettings( |
- scoped_ptr<DataReductionProxyParams> params) |
- : restricted_by_carrier_(false), |
- enabled_by_user_(false), |
- disabled_on_vpn_(false), |
- unreachable_(false), |
+DataReductionProxySettings::DataReductionProxySettings() |
+ : unreachable_(false), |
+ allowed_(false), |
+ alternative_allowed_(false), |
+ promo_allowed_(false), |
prefs_(NULL), |
- url_request_context_getter_(NULL), |
- net_log_(NULL), |
event_store_(NULL), |
- configurator_(NULL) { |
- DCHECK(params.get()); |
- config_.reset(new DataReductionProxyConfig(params.Pass())); |
+ config_(nullptr) { |
} |
DataReductionProxySettings::~DataReductionProxySettings() { |
- if (params()->allowed()) |
+ if (allowed_) |
spdy_proxy_auth_enabled_.Destroy(); |
- net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
} |
void DataReductionProxySettings::InitPrefMembers() { |
@@ -125,28 +77,28 @@ void DataReductionProxySettings::InitPrefMembers() { |
base::Unretained(this))); |
} |
+void DataReductionProxySettings::UpdateConfigValues() { |
+ DCHECK(config_); |
+ allowed_ = config_->params()->allowed(); |
+ alternative_allowed_ = config_->params()->alternative_allowed(); |
bengr
2015/02/03 21:51:58
Why do we have these members if they are directly
jeremyim
2015/02/04 01:31:21
In a world where Config does all of its operations
bengr
2015/02/05 00:46:02
Acknowledged.
|
+ promo_allowed_ = config_->params()->promo_allowed(); |
+ primary_origin_ = config_->params()->origin(); |
+} |
+ |
void DataReductionProxySettings::InitDataReductionProxySettings( |
PrefService* prefs, |
- net::URLRequestContextGetter* url_request_context_getter, |
- net::NetLog* net_log, |
+ DataReductionProxyConfig* config, |
DataReductionProxyEventStore* event_store) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK(prefs); |
- DCHECK(url_request_context_getter); |
+ DCHECK(config); |
DCHECK(event_store); |
prefs_ = prefs; |
- url_request_context_getter_ = url_request_context_getter; |
- net_log_ = net_log; |
+ config_ = config; |
event_store_ = event_store; |
InitPrefMembers(); |
+ UpdateConfigValues(); |
RecordDataReductionInit(); |
- |
- // Disable the proxy if it is not allowed to be used. |
- if (!params()->allowed()) |
- return; |
- |
- AddDefaultProxyBypassRules(); |
- net::NetworkChangeNotifier::AddIPAddressObserver(this); |
} |
void DataReductionProxySettings::SetDataReductionProxyStatisticsPrefs( |
@@ -160,12 +112,6 @@ void DataReductionProxySettings::SetOnDataReductionEnabledCallback( |
on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled()); |
} |
-void DataReductionProxySettings::SetProxyConfigurator( |
- DataReductionProxyConfigurator* configurator) { |
- DCHECK(configurator); |
- configurator_ = configurator; |
-} |
- |
bool DataReductionProxySettings::IsDataReductionProxyEnabled() { |
return spdy_proxy_auth_enabled_.GetValue() || IsEnabledOnCommandLine(); |
} |
@@ -182,7 +128,7 @@ bool DataReductionProxySettings::IsDataReductionProxyManaged() { |
void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
// Prevent configuring the proxy when it is not allowed to be used. |
- if (!params()->allowed()) |
+ if (!allowed_) |
return; |
if (spdy_proxy_auth_enabled_.GetValue() != enabled) { |
@@ -195,7 +141,7 @@ void DataReductionProxySettings::SetDataReductionProxyAlternativeEnabled( |
bool enabled) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
// Prevent configuring the proxy when it is not allowed to be used. |
- if (!params()->alternative_allowed()) |
+ if (!alternative_allowed_) |
return; |
if (data_reduction_proxy_alternative_enabled_.GetValue() != enabled) { |
data_reduction_proxy_alternative_enabled_.SetValue(enabled); |
@@ -233,146 +179,23 @@ DataReductionProxySettings::GetDailyReceivedContentLengths() { |
return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); |
} |
-void DataReductionProxySettings::OnURLFetchComplete( |
- const net::URLFetcher* source) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- |
- 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); |
- return; |
- } |
- // TODO(bengr): Remove once we understand the reasons probes are failing. |
- // Probe errors are either due to fetcher-level errors or modified |
- // responses. This only tracks the former. |
- UMA_HISTOGRAM_SPARSE_SLOWLY( |
- kUMAProxyProbeURLNetError, std::abs(status.error())); |
- } |
- |
- std::string response; |
- source->GetResponseAsString(&response); |
- |
- if ("OK" == response.substr(0, 2)) { |
- DVLOG(1) << "The data reduction proxy is unrestricted."; |
- |
- if (enabled_by_user_) { |
- if (restricted_by_carrier_) { |
- // The user enabled the proxy, but sometime previously in the session, |
- // the network operator had blocked the canary and restricted the user. |
- // The current network doesn't block the canary, so don't restrict the |
- // proxy configurations. |
- SetProxyConfigs(true /* enabled */, |
- IsDataReductionProxyAlternativeEnabled(), |
- false /* restricted */, |
- false /* at_startup */); |
- RecordProbeURLFetchResult(SUCCEEDED_PROXY_ENABLED); |
- } else { |
- RecordProbeURLFetchResult(SUCCEEDED_PROXY_ALREADY_ENABLED); |
- } |
- } |
- restricted_by_carrier_ = false; |
- return; |
- } |
- DVLOG(1) << "The data reduction proxy is restricted to the configured " |
- << "fallback proxy."; |
- if (enabled_by_user_) { |
- if (!restricted_by_carrier_) { |
- // Restrict the proxy. |
- SetProxyConfigs(true /* enabled */, |
- IsDataReductionProxyAlternativeEnabled(), |
- true /* restricted */, |
- false /* at_startup */); |
- RecordProbeURLFetchResult(FAILED_PROXY_DISABLED); |
- } else { |
- RecordProbeURLFetchResult(FAILED_PROXY_ALREADY_DISABLED); |
- } |
- } |
- restricted_by_carrier_ = true; |
-} |
- |
PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
return prefs_; |
} |
-void DataReductionProxySettings::AddDefaultProxyBypassRules() { |
- // localhost |
- DCHECK(configurator_); |
- configurator_->AddHostPatternToBypass("<local>"); |
- // RFC6890 loopback addresses. |
- // TODO(tbansal): Remove this once crbug/446705 is fixed. |
- configurator_->AddHostPatternToBypass("127.0.0.0/8"); |
- |
- // RFC6890 current network (only valid as source address). |
- configurator_->AddHostPatternToBypass("0.0.0.0/8"); |
- |
- // RFC1918 private addresses. |
- configurator_->AddHostPatternToBypass("10.0.0.0/8"); |
- configurator_->AddHostPatternToBypass("172.16.0.0/12"); |
- configurator_->AddHostPatternToBypass("192.168.0.0/16"); |
- |
- // RFC3513 unspecified address. |
- configurator_->AddHostPatternToBypass("::/128"); |
- |
- // RFC4193 private addresses. |
- configurator_->AddHostPatternToBypass("fc00::/7"); |
- // IPV6 probe addresses. |
- configurator_->AddHostPatternToBypass("*-ds.metric.gstatic.com"); |
- configurator_->AddHostPatternToBypass("*-v4.metric.gstatic.com"); |
-} |
- |
-void DataReductionProxySettings::LogProxyState( |
- bool enabled, bool restricted, bool at_startup) { |
- // This must stay a LOG(WARNING); the output is used in processing customer |
- // feedback. |
- const char kAtStartup[] = "at startup"; |
- const char kByUser[] = "by user action"; |
- const char kOn[] = "ON"; |
- const char kOff[] = "OFF"; |
- const char kRestricted[] = "(Restricted)"; |
- const char kUnrestricted[] = "(Unrestricted)"; |
- |
- std::string annotated_on = |
- kOn + std::string(" ") + (restricted ? kRestricted : kUnrestricted); |
- |
- LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff) |
- << " " << (at_startup ? kAtStartup : kByUser); |
-} |
- |
-void DataReductionProxySettings::OnIPAddressChanged() { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- if (enabled_by_user_) { |
- DCHECK(params()->allowed()); |
- RecordNetworkChangeEvent(IP_CHANGED); |
- if (DisableIfVPN()) |
- return; |
- if (IsDataReductionProxyAlternativeEnabled() && |
- !params()->alternative_fallback_allowed()) { |
- return; |
- } |
- ProbeWhetherDataReductionProxyIsAvailable(); |
- } |
-} |
- |
void DataReductionProxySettings::OnProxyEnabledPrefChange() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
if (!on_data_reduction_proxy_enabled_.is_null()) |
on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled()); |
- if (!params()->allowed()) |
+ if (!allowed_) |
return; |
MaybeActivateDataReductionProxy(false); |
} |
void DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- if (!params()->alternative_allowed()) |
+ if (!alternative_allowed_) |
return; |
MaybeActivateDataReductionProxy(false); |
} |
@@ -409,54 +232,15 @@ void DataReductionProxySettings::MaybeActivateDataReductionProxy( |
ResetDataReductionStatistics(); |
} |
// Configure use of the data reduction proxy if it is enabled. |
- enabled_by_user_= IsDataReductionProxyEnabled(); |
- SetProxyConfigs(enabled_by_user_ && !disabled_on_vpn_, |
- IsDataReductionProxyAlternativeEnabled(), |
- restricted_by_carrier_, |
- at_startup); |
- |
- // Check if the proxy has been restricted explicitly by the carrier. |
- if (enabled_by_user_ && !disabled_on_vpn_ && |
- !(IsDataReductionProxyAlternativeEnabled() && |
- !params()->alternative_fallback_allowed())) { |
- ProbeWhetherDataReductionProxyIsAvailable(); |
- } |
-} |
- |
-void DataReductionProxySettings::SetProxyConfigs(bool enabled, |
- bool alternative_enabled, |
- bool restricted, |
- bool at_startup) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- DCHECK(configurator_); |
- |
- LogProxyState(enabled, restricted, at_startup); |
- // The alternative is only configured if the standard configuration is |
- // is enabled. |
- if (enabled & !params()->holdback()) { |
- if (alternative_enabled) { |
- configurator_->Enable(restricted, |
- !params()->alternative_fallback_allowed(), |
- params()->alt_origin().spec(), |
- std::string(), |
- params()->ssl_origin().spec()); |
- } else { |
- configurator_->Enable(restricted, |
- !params()->fallback_allowed(), |
- params()->origin().spec(), |
- params()->fallback_origin().spec(), |
- std::string()); |
- } |
- } else { |
- configurator_->Disable(); |
- } |
+ config_->SetProxyPrefs(IsDataReductionProxyEnabled(), |
+ IsDataReductionProxyAlternativeEnabled(), at_startup); |
} |
// Metrics methods |
void DataReductionProxySettings::RecordDataReductionInit() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
ProxyStartupState state = PROXY_NOT_AVAILABLE; |
- if (params()->allowed()) { |
+ if (allowed_) { |
if (IsDataReductionProxyEnabled()) |
state = PROXY_ENABLED; |
else |
@@ -466,25 +250,12 @@ void DataReductionProxySettings::RecordDataReductionInit() { |
RecordStartupState(state); |
} |
-void DataReductionProxySettings::RecordProbeURLFetchResult( |
- ProbeURLFetchResult result) { |
- UMA_HISTOGRAM_ENUMERATION(kUMAProxyProbeURL, |
- result, |
- PROBE_URL_FETCH_RESULT_COUNT); |
-} |
- |
void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) { |
UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram, |
state, |
PROXY_STARTUP_STATE_COUNT); |
} |
-void DataReductionProxySettings::GetNetworkList( |
- net::NetworkInterfaceList* interfaces, |
- int policy) { |
- net::GetNetworkList(interfaces, policy); |
-} |
- |
DataReductionProxySettings::ContentLengthList |
DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -535,77 +306,4 @@ void DataReductionProxySettings::GetContentLengths( |
statistics_prefs_->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); |
} |
-net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher( |
- const GURL& gurl, |
- int load_flags) { |
- |
- net::URLFetcher* fetcher = net::URLFetcher::Create(gurl, |
- net::URLFetcher::GET, |
- this); |
- fetcher->SetLoadFlags(load_flags); |
- DCHECK(url_request_context_getter_); |
- fetcher->SetRequestContext(url_request_context_getter_); |
- // Configure max retries to be at most kMaxRetries times for 5xx errors. |
- static const int kMaxRetries = 5; |
- fetcher->SetMaxRetriesOn5xx(kMaxRetries); |
- fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); |
- return fetcher; |
-} |
- |
- |
-net::URLFetcher* |
-DataReductionProxySettings::GetURLFetcherForAvailabilityCheck() { |
- return GetBaseURLFetcher(params()->probe_url(), |
- net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY); |
-} |
- |
- |
-void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { |
- net::URLFetcher* fetcher = GetURLFetcherForAvailabilityCheck(); |
- 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(); |
-} |
- |
-bool DataReductionProxySettings::DisableIfVPN() { |
- net::NetworkInterfaceList network_interfaces; |
- GetNetworkList(&network_interfaces, 0); |
- // VPNs use a "tun" interface, so the presence of a "tun" interface indicates |
- // a VPN is in use. |
- // TODO(kundaji): Verify this works on Windows. |
- const std::string vpn_interface_name_prefix = "tun"; |
- for (size_t i = 0; i < network_interfaces.size(); ++i) { |
- std::string interface_name = network_interfaces[i].name; |
- if (LowerCaseEqualsASCII( |
- interface_name.begin(), |
- interface_name.begin() + vpn_interface_name_prefix.size(), |
- vpn_interface_name_prefix.c_str())) { |
- SetProxyConfigs(false, |
- IsDataReductionProxyAlternativeEnabled(), |
- false, |
- false); |
- disabled_on_vpn_ = true; |
- RecordNetworkChangeEvent(DISABLED_ON_VPN); |
- return true; |
- } |
- } |
- if (disabled_on_vpn_) { |
- SetProxyConfigs(enabled_by_user_, |
- IsDataReductionProxyAlternativeEnabled(), |
- restricted_by_carrier_, |
- false); |
- } |
- disabled_on_vpn_ = false; |
- return false; |
-} |
- |
} // namespace data_reduction_proxy |