Chromium Code Reviews| 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..f59c8eb13c3b0f192a1697fe389df3dbc9e087df 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,17 @@ |
| #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 DataReductionProxyStatisticsPrefs; |
| // The number of days of bandwidth usage statistics that are tracked. |
| const unsigned int kNumDaysInHistory = 60; |
| @@ -62,29 +48,21 @@ 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; |
| - |
| - DataReductionProxyParams* params() const { |
| - return config_->params(); |
| - } |
| + DataReductionProxySettings(); |
| + virtual ~DataReductionProxySettings(); |
| // Initializes the data reduction proxy with profile and local state prefs, |
| - // and a |UrlRequestContextGetter| for canary probes. The caller must ensure |
| + // a |DataReductionProxyConfig| for retrieving configuration information and |
| + // a |DataReductionProxyEventStore| for event logging. 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, |
| + DataReductionProxyConfig* config, |
| DataReductionProxyEventStore* event_store); |
| // Sets the |statistics_prefs_| to be used for data reduction proxy pref reads |
| @@ -97,11 +75,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 +84,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 +120,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 +130,47 @@ class DataReductionProxySettings |
| return event_store_; |
| } |
| + // Returns true if the data reduction proxy configuration may be used. |
| + bool Allowed() const { return allowed_; } |
|
bengr
2015/02/03 21:51:58
Move return to new line here and below.
jeremyim
2015/02/04 01:31:21
Done.
|
| + |
| + // 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 +181,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 +209,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); |
| }; |