| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h
|
| 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 911668705fed33cf74bf7068c2e001c537e635ec..5059ee057999fa3b2ca6e8d8ba0751582ae7ac4b 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
|
| @@ -11,31 +11,18 @@
|
| #include "base/callback.h"
|
| #include "base/compiler_specific.h"
|
| #include "base/gtest_prod_util.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| #include "base/prefs/pref_member.h"
|
| #include "base/threading/thread_checker.h"
|
| -#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
|
| -#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
|
| -#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"
|
| +#include "url/gurl.h"
|
|
|
| class PrefService;
|
|
|
| -namespace net {
|
| -class HostPortPair;
|
| -class HttpNetworkSession;
|
| -class HttpResponseHeaders;
|
| -class URLFetcher;
|
| -class URLRequestContextGetter;
|
| -}
|
| -
|
| namespace data_reduction_proxy {
|
|
|
| +class DataReductionProxyConfig;
|
| class DataReductionProxyEventStore;
|
| +class DataReductionProxyIOData;
|
| +class DataReductionProxyStatisticsPrefs;
|
|
|
| // The number of days of bandwidth usage statistics that are tracked.
|
| const unsigned int kNumDaysInHistory = 60;
|
| @@ -62,30 +49,18 @@ enum ProxyStartupState {
|
| // be called from there.
|
| // TODO(marq): Convert this to be a KeyedService with an
|
| // associated factory class, and refactor the Java call sites accordingly.
|
| -class DataReductionProxySettings
|
| - : public net::URLFetcherDelegate,
|
| - public net::NetworkChangeNotifier::IPAddressObserver {
|
| +class DataReductionProxySettings {
|
| public:
|
| typedef std::vector<long long> ContentLengthList;
|
|
|
| - static bool IsProxyKeySetOnCommandLine();
|
| -
|
| - DataReductionProxySettings(scoped_ptr<DataReductionProxyParams> params);
|
| - ~DataReductionProxySettings() override;
|
| + DataReductionProxySettings();
|
| + virtual ~DataReductionProxySettings();
|
|
|
| - DataReductionProxyParams* params() const {
|
| - return config_->params();
|
| - }
|
| -
|
| - // Initializes the data reduction proxy with profile and local state prefs,
|
| - // and a |UrlRequestContextGetter| for canary probes. The caller must ensure
|
| - // that all parameters remain alive for the lifetime of the
|
| - // |DataReductionProxySettings| instance.
|
| + // Initializes the data reduction proxy with profile prefs and a
|
| + // |DataReductionProxyIOData|. The caller must ensure that all parameters
|
| + // remain alive for the lifetime of the |DataReductionProxySettings| instance.
|
| void InitDataReductionProxySettings(
|
| - PrefService* prefs,
|
| - net::URLRequestContextGetter* url_request_context_getter,
|
| - net::NetLog* net_log,
|
| - DataReductionProxyEventStore* event_store);
|
| + PrefService* prefs, DataReductionProxyIOData* io_data);
|
|
|
| // Sets the |statistics_prefs_| to be used for data reduction proxy pref reads
|
| // and writes.
|
| @@ -97,11 +72,6 @@ class DataReductionProxySettings
|
| void SetOnDataReductionEnabledCallback(
|
| const base::Callback<void(bool)>& on_data_reduction_proxy_enabled);
|
|
|
| - // Sets the logic the embedder uses to set the networking configuration that
|
| - // causes traffic to be proxied.
|
| - void SetProxyConfigurator(
|
| - DataReductionProxyConfigurator* configurator);
|
| -
|
| // Returns true if the proxy is enabled.
|
| bool IsDataReductionProxyEnabled();
|
|
|
| @@ -111,9 +81,7 @@ class DataReductionProxySettings
|
| // Returns true if the proxy is managed by an adminstrator's policy.
|
| bool IsDataReductionProxyManaged();
|
|
|
| - // Enables or disables the data reduction proxy. If a probe URL is available,
|
| - // and a probe request fails at some point, the proxy won't be used until a
|
| - // probe succeeds.
|
| + // Enables or disables the data reduction proxy.
|
| void SetDataReductionProxyEnabled(bool enabled);
|
|
|
| // Enables or disables the alternative data reduction proxy configuration.
|
| @@ -149,11 +117,7 @@ class DataReductionProxySettings
|
|
|
| ContentLengthList GetDailyContentLengths(const char* pref_name);
|
|
|
| - // net::URLFetcherDelegate:
|
| - void OnURLFetchComplete(const net::URLFetcher* source) override;
|
| -
|
| - // Configures data reduction proxy and makes a request to the probe URL to
|
| - // determine server availability. |at_startup| is true when this method is
|
| + // Configures data reduction proxy. |at_startup| is true when this method is
|
| // called in response to creating or loading a new profile.
|
| void MaybeActivateDataReductionProxy(bool at_startup);
|
|
|
| @@ -163,64 +127,55 @@ class DataReductionProxySettings
|
| return event_store_;
|
| }
|
|
|
| + // Returns true if the data reduction proxy configuration may be used.
|
| + bool Allowed() const {
|
| + return allowed_;
|
| + }
|
| +
|
| + // Returns true if the alternative data reduction proxy configuration may be
|
| + // used.
|
| + bool AlternativeAllowed() const {
|
| + return alternative_allowed_;
|
| + }
|
| +
|
| + // Returns true if the data reduction proxy promo may be shown.
|
| + // This is idependent of whether the data reduction proxy is allowed.
|
| + bool PromoAllowed() const {
|
| + return promo_allowed_;
|
| + }
|
| +
|
| + // The data reduction proxy primary origin
|
| + const GURL& PrimaryOrigin() const {
|
| + return primary_origin_;
|
| + }
|
| +
|
| + // Permits changing the underlying |DataReductionProxyConfig| without running
|
| + // the initialization loop.
|
| + void ResetConfigForTest(DataReductionProxyConfig* config) {
|
| + config_ = config;
|
| + }
|
| +
|
| protected:
|
| void InitPrefMembers();
|
|
|
| - // Returns a fetcher for the probe to check if OK for the proxy to use SPDY.
|
| - // Virtual for testing.
|
| - virtual net::URLFetcher* GetURLFetcherForAvailabilityCheck();
|
| + void UpdateConfigValues();
|
|
|
| // Virtualized for unit test support.
|
| virtual PrefService* GetOriginalProfilePrefs();
|
|
|
| - // Sets the proxy configs, enabling or disabling the proxy according to
|
| - // the value of |enabled| and |alternative_enabled|. Use the alternative
|
| - // configuration only if |enabled| and |alternative_enabled| are true. If
|
| - // |restricted| is true, only enable the fallback proxy. |at_startup| is true
|
| - // when this method is called from InitDataReductionProxySettings.
|
| - virtual void SetProxyConfigs(bool enabled,
|
| - bool alternative_enabled,
|
| - bool restricted,
|
| - bool at_startup);
|
| -
|
| // Metrics method. Subclasses should override if they wish to provide
|
| // alternatives.
|
| virtual void RecordDataReductionInit();
|
|
|
| - virtual void AddDefaultProxyBypassRules();
|
| -
|
| - // Writes a warning to the log that is used in backend processing of
|
| - // customer feedback. Virtual so tests can mock it for verification.
|
| - virtual void LogProxyState(bool enabled, bool restricted, bool at_startup);
|
| -
|
| - // Virtualized for mocking. Records UMA containing the result of requesting
|
| - // the probe URL.
|
| - virtual void RecordProbeURLFetchResult(
|
| - data_reduction_proxy::ProbeURLFetchResult result);
|
| -
|
| // Virtualized for mocking. Records UMA specifying whether the proxy was
|
| // enabled or disabled at startup.
|
| virtual void RecordStartupState(
|
| data_reduction_proxy::ProxyStartupState state);
|
|
|
| - // Virtualized for mocking. Returns the list of network interfaces in use.
|
| - virtual void GetNetworkList(net::NetworkInterfaceList* interfaces,
|
| - int policy);
|
| -
|
| - DataReductionProxyConfigurator* configurator() {
|
| - return configurator_;
|
| - }
|
| -
|
| private:
|
| friend class DataReductionProxySettingsTestBase;
|
| friend class DataReductionProxySettingsTest;
|
| FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| - TestAuthenticationInit);
|
| - FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| - TestAuthHashGeneration);
|
| - FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| - TestAuthHashGenerationWithOriginSetViaSwitch);
|
| - FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| TestResetDataReductionStatistics);
|
| FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| TestIsProxyEnabledOrManaged);
|
| @@ -231,53 +186,27 @@ class DataReductionProxySettings
|
| FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| TestMaybeActivateDataReductionProxy);
|
| FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| - TestOnIPAddressChanged);
|
| - FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| TestOnProxyEnabledPrefChange);
|
| FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| TestInitDataReductionProxyOn);
|
| FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| TestInitDataReductionProxyOff);
|
| FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| - TestBypassList);
|
| - FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| CheckInitMetricsWhenNotAllowed);
|
| - FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| - TestSetProxyConfigs);
|
| - FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
|
| - TestSetProxyConfigsHoldback);
|
| -
|
| - // NetworkChangeNotifier::IPAddressObserver:
|
| - void OnIPAddressChanged() override;
|
|
|
| void OnProxyEnabledPrefChange();
|
| void OnProxyAlternativeEnabledPrefChange();
|
|
|
| void ResetDataReductionStatistics();
|
|
|
| - // Requests the proxy probe URL, if one is set. If unable to do so, disables
|
| - // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe
|
| - // failure.
|
| - void ProbeWhetherDataReductionProxyIsAvailable();
|
| -
|
| - // Disables use of the data reduction proxy on VPNs. Returns true if the
|
| - // data reduction proxy has been disabled.
|
| - bool DisableIfVPN();
|
| -
|
| - // Generic method to get a URL fetcher.
|
| - net::URLFetcher* GetBaseURLFetcher(const GURL& gurl, int load_flags);
|
| -
|
| - std::string key_;
|
| - bool restricted_by_carrier_;
|
| - bool enabled_by_user_;
|
| - bool disabled_on_vpn_;
|
| bool unreachable_;
|
|
|
| - scoped_ptr<net::URLFetcher> 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_;
|
| + // The following values are cached in order to access the values on the
|
| + // correct thread.
|
| + bool allowed_;
|
| + bool alternative_allowed_;
|
| + bool promo_allowed_;
|
| + GURL primary_origin_;
|
|
|
| BooleanPrefMember spdy_proxy_auth_enabled_;
|
| BooleanPrefMember data_reduction_proxy_alternative_enabled_;
|
| @@ -285,24 +214,16 @@ class DataReductionProxySettings
|
| PrefService* prefs_;
|
| DataReductionProxyStatisticsPrefs* statistics_prefs_;
|
|
|
| - 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<void(bool)> on_data_reduction_proxy_enabled_;
|
| + // The caller must ensure that the |config_| outlives this instance.
|
| + DataReductionProxyConfig* config_;
|
|
|
| - DataReductionProxyConfigurator* configurator_;
|
| + base::Callback<void(bool)> on_data_reduction_proxy_enabled_;
|
|
|
| base::ThreadChecker thread_checker_;
|
|
|
| - scoped_ptr<DataReductionProxyConfig> config_;
|
| -
|
| DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings);
|
| };
|
|
|
|
|