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 17c2e528708945e6b71c79af549ff665ec73a807..f5b70a466c3a497dead6286b4ea8bdcb063d3254 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 |
@@ -14,28 +14,16 @@ |
#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 DataReductionProxyService; |
class DataReductionProxyStatisticsPrefs; |
// The number of days of bandwidth usage statistics that are tracked. |
@@ -63,39 +51,20 @@ 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 |
- // 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, |
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, |
- net::URLRequestContextGetter* url_request_context_getter, |
- net::NetLog* net_log, |
- DataReductionProxyEventStore* event_store, |
- bool enable_quic); |
- |
- // Constructs statistics prefs. This should not be called if a valid |
- // statistics prefs is passed into the constructor. |
- void EnableCompressionStatisticsLogging( |
- PrefService* prefs, |
- scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
- const base::TimeDelta& commit_delay); |
+ DataReductionProxyIOData* io_data, |
+ scoped_ptr<DataReductionProxyService> data_reduction_proxy_service); |
base::WeakPtr<DataReductionProxyStatisticsPrefs> statistics_prefs(); |
@@ -104,11 +73,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(); |
@@ -118,9 +82,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. |
@@ -156,11 +118,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); |
@@ -170,69 +128,60 @@ class DataReductionProxySettings |
return event_store_; |
} |
- // Used for testing. |
- void SetDataReductionProxyStatisticsPrefs( |
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs); |
+ // 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 std::string PrimaryOrigin() const { |
+ return primary_origin_; |
+ } |
+ |
+ DataReductionProxyService* data_reduction_proxy_service() { |
+ return data_reduction_proxy_service_.get(); |
+ } |
+ |
+ // 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 class DataReductionProxyTestContext; |
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); |
@@ -243,78 +192,45 @@ 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_; |
+ std::string primary_origin_; |
BooleanPrefMember spdy_proxy_auth_enabled_; |
BooleanPrefMember data_reduction_proxy_alternative_enabled_; |
- PrefService* prefs_; |
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs_; |
- |
- net::URLRequestContextGetter* url_request_context_getter_; |
+ scoped_ptr<DataReductionProxyService> data_reduction_proxy_service_; |
- // 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_; |
+ PrefService* prefs_; |
// 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); |
}; |