Commit 191c0cae authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Add the state of non-core data saver proxies to the network properties manager

State of the core data saver proxies are now independent from
the state of the non-core data saver proxies.

Bug: 779219
Change-Id: Id765548736f96ec85db9720a1eb73af95b525b32
Reviewed-on: https://chromium-review.googlesource.com/770146
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521528}
parent 41145444
...@@ -186,10 +186,8 @@ void DataReductionProxyConfig::ReloadConfig() { ...@@ -186,10 +186,8 @@ void DataReductionProxyConfig::ReloadConfig() {
if (enabled_by_user_ && !params::IsIncludedInHoldbackFieldTrial() && if (enabled_by_user_ && !params::IsIncludedInHoldbackFieldTrial() &&
!config_values_->proxies_for_http().empty()) { !config_values_->proxies_for_http().empty()) {
configurator_->Enable( configurator_->Enable(*network_properties_manager_,
!network_properties_manager_->IsSecureProxyAllowed(), config_values_->proxies_for_http());
!network_properties_manager_->IsInsecureProxyAllowed(),
config_values_->proxies_for_http());
} else { } else {
configurator_->Disable(); configurator_->Disable();
} }
...@@ -403,7 +401,11 @@ void DataReductionProxyConfig::UpdateConfigForTesting( ...@@ -403,7 +401,11 @@ void DataReductionProxyConfig::UpdateConfigForTesting(
network_properties_manager_->SetIsSecureProxyDisallowedByCarrier( network_properties_manager_->SetIsSecureProxyDisallowedByCarrier(
!secure_proxies_allowed); !secure_proxies_allowed);
network_properties_manager_->SetHasWarmupURLProbeFailed( network_properties_manager_->SetHasWarmupURLProbeFailed(
false, !insecure_proxies_allowed); false /* secure_proxy */, false /* is_core_proxy */,
!insecure_proxies_allowed);
network_properties_manager_->SetHasWarmupURLProbeFailed(
false /* secure_proxy */, true /* is_core_proxy */,
!insecure_proxies_allowed);
} }
void DataReductionProxyConfig::SetNetworkPropertiesManagerForTesting( void DataReductionProxyConfig::SetNetworkPropertiesManagerForTesting(
...@@ -626,34 +628,26 @@ base::TimeTicks DataReductionProxyConfig::GetTicksNow() const { ...@@ -626,34 +628,26 @@ base::TimeTicks DataReductionProxyConfig::GetTicksNow() const {
} }
void DataReductionProxyConfig::OnInsecureProxyWarmupURLProbeStatusChange( void DataReductionProxyConfig::OnInsecureProxyWarmupURLProbeStatusChange(
bool insecure_proxies_allowed) { bool insecure_proxies_allowed,
bool is_core_proxy) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
bool old_status = network_properties_manager_->IsInsecureProxyAllowed(); bool old_status =
network_properties_manager_->IsInsecureProxyAllowed(is_core_proxy);
network_properties_manager_->SetHasWarmupURLProbeFailed( network_properties_manager_->SetHasWarmupURLProbeFailed(
false, !insecure_proxies_allowed); false, is_core_proxy, !insecure_proxies_allowed);
if (old_status == network_properties_manager_->IsInsecureProxyAllowed()) if (old_status ==
network_properties_manager_->IsInsecureProxyAllowed(is_core_proxy)) {
return; return;
}
ReloadConfig(); ReloadConfig();
} }
net::ProxyConfig DataReductionProxyConfig::ProxyConfigIgnoringHoldback() const { net::ProxyConfig DataReductionProxyConfig::ProxyConfigIgnoringHoldback() const {
if (!enabled_by_user_ || config_values_->proxies_for_http().empty()) if (!enabled_by_user_ || config_values_->proxies_for_http().empty())
return net::ProxyConfig::CreateDirect(); return net::ProxyConfig::CreateDirect();
return configurator_->CreateProxyConfig( return configurator_->CreateProxyConfig(*network_properties_manager_,
!network_properties_manager_->IsSecureProxyAllowed(), config_values_->proxies_for_http());
!network_properties_manager_->IsInsecureProxyAllowed(),
config_values_->proxies_for_http());
}
bool DataReductionProxyConfig::secure_proxy_allowed() const {
DCHECK(thread_checker_.CalledOnValidThread());
return network_properties_manager_->IsSecureProxyAllowed();
}
bool DataReductionProxyConfig::insecure_proxies_allowed() const {
DCHECK(thread_checker_.CalledOnValidThread());
return network_properties_manager_->IsInsecureProxyAllowed();
} }
std::vector<DataReductionProxyServer> std::vector<DataReductionProxyServer>
...@@ -714,4 +708,10 @@ std::string DataReductionProxyConfig::GetCurrentNetworkID() const { ...@@ -714,4 +708,10 @@ std::string DataReductionProxyConfig::GetCurrentNetworkID() const {
NOTREACHED(); NOTREACHED();
} }
const NetworkPropertiesManager&
DataReductionProxyConfig::GetNetworkPropertiesManager() const {
DCHECK(thread_checker_.CalledOnValidThread());
return *network_properties_manager_;
}
} // namespace data_reduction_proxy } // namespace data_reduction_proxy
...@@ -190,12 +190,6 @@ class DataReductionProxyConfig ...@@ -190,12 +190,6 @@ class DataReductionProxyConfig
// This should only be used for logging purposes. // This should only be used for logging purposes.
net::ProxyConfig ProxyConfigIgnoringHoldback() const; net::ProxyConfig ProxyConfigIgnoringHoldback() const;
// Returns true if secure data saver proxies are allowed.
bool secure_proxy_allowed() const;
// Returns true if insecure data saver proxies are allowed.
bool insecure_proxies_allowed() const;
std::vector<DataReductionProxyServer> GetProxiesForHttp() const; std::vector<DataReductionProxyServer> GetProxiesForHttp() const;
// Called when a new client config has been fetched. // Called when a new client config has been fetched.
...@@ -203,10 +197,17 @@ class DataReductionProxyConfig ...@@ -203,10 +197,17 @@ class DataReductionProxyConfig
void SetNetworkPropertiesManagerForTesting(NetworkPropertiesManager* manager); void SetNetworkPropertiesManagerForTesting(NetworkPropertiesManager* manager);
// Returns the network properties manager which manages whether a given data
// saver proxy is currently allowed or not.
const NetworkPropertiesManager& GetNetworkPropertiesManager() const;
protected: protected:
// Should be called when there is a change in the status of the availability // Should be called when there is a change in the status of the availability
// of the insecure data saver proxies triggered due to warmup URL. // of the insecure data saver proxies triggered due to fetching of the warmup
void OnInsecureProxyWarmupURLProbeStatusChange(bool insecure_proxies_allowed); // URL. |is_core_proxy| indicates if the warmup URL was fetched over a core
// data saver proxy or not.
void OnInsecureProxyWarmupURLProbeStatusChange(bool insecure_proxies_allowed,
bool is_core_proxy);
virtual base::TimeTicks GetTicksNow() const; virtual base::TimeTicks GetTicksNow() const;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/browser/network_properties_manager.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
...@@ -595,8 +596,12 @@ TEST_F(DataReductionProxyConfigServiceClientTest, ...@@ -595,8 +596,12 @@ TEST_F(DataReductionProxyConfigServiceClientTest,
ProxyServer::CORE)); ProxyServer::CORE));
// Secure check failed. // Secure check failed.
configurator()->Enable(true /* secure_transport_restricted */, false, TestingPrefServiceSimple test_prefs;
http_proxies); test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
manager.SetIsSecureProxyDisallowedByCarrier(true);
configurator()->Enable(manager, http_proxies);
VerifyRemoteSuccess(false); VerifyRemoteSuccess(false);
} }
...@@ -730,8 +735,12 @@ TEST_F(DataReductionProxyConfigServiceClientTest, ...@@ -730,8 +735,12 @@ TEST_F(DataReductionProxyConfigServiceClientTest,
ProxyServer::CORE)); ProxyServer::CORE));
// Secure check failed. // Secure check failed.
configurator()->Enable(true /* secure_transport_restricted */, false, TestingPrefServiceSimple test_prefs;
http_proxies); test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
manager.SetIsSecureProxyDisallowedByCarrier(true);
configurator()->Enable(manager, http_proxies);
VerifyRemoteSuccess(false); VerifyRemoteSuccess(false);
} }
......
...@@ -306,17 +306,18 @@ TEST_F(DataReductionProxyConfigTest, ...@@ -306,17 +306,18 @@ TEST_F(DataReductionProxyConfigTest,
GetConfiguredProxiesForHttp()); GetConfiguredProxiesForHttp());
// Calling OnInsecureProxyWarmupURLProbeStatusChange should reload the config. // Calling OnInsecureProxyWarmupURLProbeStatusChange should reload the config.
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(false); test_config()->OnInsecureProxyWarmupURLProbeStatusChange(
false /* insecure_proxies_allowed */, false /* is_core_proxy */);
EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy}), EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy}),
GetConfiguredProxiesForHttp()); GetConfiguredProxiesForHttp());
// Calling OnInsecureProxyWarmupURLProbeStatusChange again with the same // Calling OnInsecureProxyWarmupURLProbeStatusChange again with the same
// status has no effect. // status has no effect.
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(false); test_config()->OnInsecureProxyWarmupURLProbeStatusChange(false, false);
EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy}), EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy}),
GetConfiguredProxiesForHttp()); GetConfiguredProxiesForHttp());
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(true); test_config()->OnInsecureProxyWarmupURLProbeStatusChange(true, false);
EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy, kHttpProxy}), EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy, kHttpProxy}),
GetConfiguredProxiesForHttp()); GetConfiguredProxiesForHttp());
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/values.h" #include "base/values.h"
#include "components/data_reduction_proxy/core/browser/network_properties_manager.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_util.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_util.h"
#include "net/proxy/proxy_config.h" #include "net/proxy/proxy_config.h"
...@@ -31,22 +32,19 @@ DataReductionProxyConfigurator::~DataReductionProxyConfigurator() { ...@@ -31,22 +32,19 @@ DataReductionProxyConfigurator::~DataReductionProxyConfigurator() {
} }
void DataReductionProxyConfigurator::Enable( void DataReductionProxyConfigurator::Enable(
bool secure_transport_restricted, const NetworkPropertiesManager& network_properties_manager,
bool insecure_proxies_restricted,
const std::vector<DataReductionProxyServer>& proxies_for_http) { const std::vector<DataReductionProxyServer>& proxies_for_http) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
net::ProxyConfig config = net::ProxyConfig config =
CreateProxyConfig(secure_transport_restricted, CreateProxyConfig(network_properties_manager, proxies_for_http);
insecure_proxies_restricted, proxies_for_http);
data_reduction_proxy_event_creator_->AddProxyEnabledEvent( data_reduction_proxy_event_creator_->AddProxyEnabledEvent(
net_log_, secure_transport_restricted, net_log_, network_properties_manager.IsSecureProxyDisallowedByCarrier(),
DataReductionProxyServer::ConvertToNetProxyServers(proxies_for_http)); DataReductionProxyServer::ConvertToNetProxyServers(proxies_for_http));
config_ = config; config_ = config;
} }
net::ProxyConfig DataReductionProxyConfigurator::CreateProxyConfig( net::ProxyConfig DataReductionProxyConfigurator::CreateProxyConfig(
bool secure_transport_restricted, const NetworkPropertiesManager& network_properties_manager,
bool insecure_proxies_restricted,
const std::vector<DataReductionProxyServer>& proxies_for_http) const { const std::vector<DataReductionProxyServer>& proxies_for_http) const {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
...@@ -56,14 +54,29 @@ net::ProxyConfig DataReductionProxyConfigurator::CreateProxyConfig( ...@@ -56,14 +54,29 @@ net::ProxyConfig DataReductionProxyConfigurator::CreateProxyConfig(
net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
for (const auto& http_proxy : proxies_for_http) { for (const auto& http_proxy : proxies_for_http) {
if (secure_transport_restricted && if (!network_properties_manager.IsSecureProxyAllowed(true) &&
(http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTPS || (http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTPS ||
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_QUIC)) { http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_QUIC) &&
http_proxy.GetProxyTypeForTesting() == ProxyServer_ProxyType_CORE) {
continue; continue;
} }
if (insecure_proxies_restricted && if (!network_properties_manager.IsInsecureProxyAllowed(true) &&
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTP) { http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTP &&
http_proxy.GetProxyTypeForTesting() == ProxyServer_ProxyType_CORE) {
continue;
}
if (!network_properties_manager.IsSecureProxyAllowed(false) &&
(http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTPS ||
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_QUIC) &&
http_proxy.GetProxyTypeForTesting() != ProxyServer_ProxyType_CORE) {
continue;
}
if (!network_properties_manager.IsInsecureProxyAllowed(false) &&
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTP &&
http_proxy.GetProxyTypeForTesting() != ProxyServer_ProxyType_CORE) {
continue; continue;
} }
......
...@@ -22,6 +22,7 @@ class ProxyServer; ...@@ -22,6 +22,7 @@ class ProxyServer;
namespace data_reduction_proxy { namespace data_reduction_proxy {
class DataReductionProxyEventCreator; class DataReductionProxyEventCreator;
class NetworkPropertiesManager;
class DataReductionProxyConfigurator { class DataReductionProxyConfigurator {
public: public:
...@@ -34,14 +35,10 @@ class DataReductionProxyConfigurator { ...@@ -34,14 +35,10 @@ class DataReductionProxyConfigurator {
virtual ~DataReductionProxyConfigurator(); virtual ~DataReductionProxyConfigurator();
// Enables data reduction using the proxy servers in |proxies_for_http|. // Enables data reduction using the proxy servers in |proxies_for_http|.
// |secure_transport_restricted| indicates that proxies going over secure
// transports can not be used. |insecure_proxies_restricted| indicates that
// insecure proxies can not be used.
// TODO: crbug.com/675764: Pass a vector of DataReductionProxyServer // TODO: crbug.com/675764: Pass a vector of DataReductionProxyServer
// instead of net::ProxyServer. // instead of net::ProxyServer.
virtual void Enable( virtual void Enable(
bool secure_transport_restricted, const NetworkPropertiesManager& network_properties_manager,
bool insecure_proxies_restricted,
const std::vector<DataReductionProxyServer>& proxies_for_http); const std::vector<DataReductionProxyServer>& proxies_for_http);
// Constructs a proxy configuration suitable for disabling the Data Reduction // Constructs a proxy configuration suitable for disabling the Data Reduction
...@@ -60,12 +57,9 @@ class DataReductionProxyConfigurator { ...@@ -60,12 +57,9 @@ class DataReductionProxyConfigurator {
const net::ProxyConfig& GetProxyConfig() const; const net::ProxyConfig& GetProxyConfig() const;
// Constructs a proxy configuration suitable for enabling the Data Reduction // Constructs a proxy configuration suitable for enabling the Data Reduction
// proxy. If true, |secure_transport_restricted| indicates that proxies going // proxy.
// over secure transports (HTTPS, QUIC) should/can not be used. If true,
// |insecure_proxies_restricted| indicates that HTTP proxies cannot be used.
net::ProxyConfig CreateProxyConfig( net::ProxyConfig CreateProxyConfig(
bool secure_transport_restricted, const NetworkPropertiesManager& network_properties_manager,
bool insecure_proxies_restricted,
const std::vector<DataReductionProxyServer>& proxies_for_http) const; const std::vector<DataReductionProxyServer>& proxies_for_http) const;
private: private:
......
...@@ -98,8 +98,7 @@ void DataReductionProxyDelegate::OnResolveProxy( ...@@ -98,8 +98,7 @@ void DataReductionProxyDelegate::OnResolveProxy(
proxies_for_http.end()); proxies_for_http.end());
net::ProxyConfig proxy_config = configurator_->CreateProxyConfig( net::ProxyConfig proxy_config = configurator_->CreateProxyConfig(
!config_->secure_proxy_allowed(), !config_->insecure_proxies_allowed(), config_->GetNetworkPropertiesManager(), proxies_for_http);
proxies_for_http);
OnResolveProxyHandler(url, method, proxy_config, proxy_retry_info, *config_, OnResolveProxyHandler(url, method, proxy_config, proxy_retry_info, *config_,
io_data_, result); io_data_, result);
......
...@@ -225,18 +225,17 @@ NetworkPropertiesManager::ConvertDictionaryValueToParsedPrefs( ...@@ -225,18 +225,17 @@ NetworkPropertiesManager::ConvertDictionaryValueToParsedPrefs(
return read_prefs; return read_prefs;
} }
bool NetworkPropertiesManager::IsSecureProxyAllowed() const { bool NetworkPropertiesManager::IsSecureProxyAllowed(bool is_core_proxy) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return !network_properties_.secure_proxy_disallowed_by_carrier() && return !network_properties_.secure_proxy_disallowed_by_carrier() &&
!network_properties_.has_captive_portal() && !network_properties_.has_captive_portal() &&
!network_properties_.secure_proxy_flags() !HasWarmupURLProbeFailed(true, is_core_proxy);
.disallowed_due_to_warmup_probe_failure();
} }
bool NetworkPropertiesManager::IsInsecureProxyAllowed() const { bool NetworkPropertiesManager::IsInsecureProxyAllowed(
bool is_core_proxy) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return !network_properties_.insecure_proxy_flags() return !HasWarmupURLProbeFailed(false, is_core_proxy);
.disallowed_due_to_warmup_probe_failure();
} }
bool NetworkPropertiesManager::IsSecureProxyDisallowedByCarrier() const { bool NetworkPropertiesManager::IsSecureProxyDisallowedByCarrier() const {
...@@ -264,24 +263,45 @@ void NetworkPropertiesManager::SetIsCaptivePortal(bool is_captive_portal) { ...@@ -264,24 +263,45 @@ void NetworkPropertiesManager::SetIsCaptivePortal(bool is_captive_portal) {
} }
bool NetworkPropertiesManager::HasWarmupURLProbeFailed( bool NetworkPropertiesManager::HasWarmupURLProbeFailed(
bool secure_proxy) const { bool secure_proxy,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); bool is_core_proxy) const {
return secure_proxy ? network_properties_.secure_proxy_flags() if (secure_proxy && is_core_proxy) {
.disallowed_due_to_warmup_probe_failure() return network_properties_.secure_proxy_flags()
: network_properties_.insecure_proxy_flags() .disallowed_due_to_warmup_probe_failure();
.disallowed_due_to_warmup_probe_failure(); }
if (secure_proxy && !is_core_proxy) {
return network_properties_.secure_non_core_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
}
if (!secure_proxy && is_core_proxy) {
return network_properties_.insecure_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
}
if (!secure_proxy && !is_core_proxy) {
return network_properties_.insecure_non_core_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
}
NOTREACHED();
return false;
} }
void NetworkPropertiesManager::SetHasWarmupURLProbeFailed( void NetworkPropertiesManager::SetHasWarmupURLProbeFailed(
bool secure_proxy, bool secure_proxy,
bool is_core_proxy,
bool warmup_url_probe_failed) { bool warmup_url_probe_failed) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (secure_proxy) { if (secure_proxy && is_core_proxy) {
network_properties_.mutable_secure_proxy_flags() network_properties_.mutable_secure_proxy_flags()
->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed); ->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed);
} else { } else if (secure_proxy && !is_core_proxy) {
network_properties_.mutable_secure_non_core_proxy_flags()
->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed);
} else if (!secure_proxy && is_core_proxy) {
network_properties_.mutable_insecure_proxy_flags() network_properties_.mutable_insecure_proxy_flags()
->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed); ->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed);
} else {
network_properties_.mutable_insecure_non_core_proxy_flags()
->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed);
} }
OnChangeInNetworkPropertyOnIOThread(); OnChangeInNetworkPropertyOnIOThread();
} }
......
...@@ -41,11 +41,13 @@ class NetworkPropertiesManager { ...@@ -41,11 +41,13 @@ class NetworkPropertiesManager {
void OnChangeInNetworkID(const std::string& network_id); void OnChangeInNetworkID(const std::string& network_id);
// Returns true if usage of secure proxies are allowed on the current network. // Returns true if usage of secure proxies are allowed on the current network.
bool IsSecureProxyAllowed() const; // Returns the status of core secure proxies if |is_core_proxy| is true.
bool IsSecureProxyAllowed(bool is_core_proxy) const;
// Returns true if usage of insecure proxies are allowed on the current // Returns true if usage of insecure proxies are allowed on the current
// network. // network. Returns the status of core non-secure proxies if |is_core_proxy|
bool IsInsecureProxyAllowed() const; // is true.
bool IsInsecureProxyAllowed(bool is_core_proxy) const;
// Returns true if usage of secure proxies has been disallowed by the carrier // Returns true if usage of secure proxies has been disallowed by the carrier
// on the current network. // on the current network.
...@@ -63,15 +65,16 @@ class NetworkPropertiesManager { ...@@ -63,15 +65,16 @@ class NetworkPropertiesManager {
// disallowed. // disallowed.
void SetIsCaptivePortal(bool is_captive_portal); void SetIsCaptivePortal(bool is_captive_portal);
// If secure_proxy is true, returns true if the warmup URL probe has failed // Returns true if the warmup URL probe has failed
// on secure proxies on the current network. Otherwise, returns true if the // on secure (or insecure), core (or non-core) data saver proxies on the
// warmup URL probe has failed on insecure proxies. // current network.
bool HasWarmupURLProbeFailed(bool secure_proxy) const; bool HasWarmupURLProbeFailed(bool secure_proxy, bool is_core_proxy) const;
// Sets the status of whether the fetching of warmup URL failed on the current // Sets the status of whether the fetching of warmup URL failed on the current
// network. Sets the status for secure proxies if |secure_proxy| is true. // network. Sets the status for secure (or insecure), core (or non-core) data
// Otherwise, sets the status for the insecure proxies. // saver proxies.
void SetHasWarmupURLProbeFailed(bool secure_proxy, void SetHasWarmupURLProbeFailed(bool secure_proxy,
bool is_core_proxy,
bool warmup_url_probe_failed); bool warmup_url_probe_failed);
private: private:
......
...@@ -79,6 +79,8 @@ static_library("test_support") { ...@@ -79,6 +79,8 @@ static_library("test_support") {
] ]
deps = [ deps = [
"//base", "//base",
"//components/prefs",
"//components/prefs:test_support",
"//net", "//net",
"//net:test_support", "//net:test_support",
"//testing/gmock", "//testing/gmock",
...@@ -100,6 +102,8 @@ source_set("unit_tests") { ...@@ -100,6 +102,8 @@ source_set("unit_tests") {
":test_support", ":test_support",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/prefs",
"//components/prefs:test_support",
# TODO this dependency seems wrong, but # TODO this dependency seems wrong, but
# data_reduction_proxy_event_store_unittest.cc includes a file from it. # data_reduction_proxy_event_store_unittest.cc includes a file from it.
......
...@@ -13,13 +13,18 @@ ...@@ -13,13 +13,18 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/browser/network_properties_manager.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "net/base/host_port_pair.h" #include "net/base/host_port_pair.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
...@@ -217,6 +222,11 @@ TEST_F(DataReductionProxyEventStoreTest, TestEndSecureProxyCheckFailed) { ...@@ -217,6 +222,11 @@ TEST_F(DataReductionProxyEventStoreTest, TestEndSecureProxyCheckFailed) {
} }
TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) { TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) {
base::MessageLoopForIO loop;
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
DataReductionProxyConfigurator configurator(net_log(), event_creator()); DataReductionProxyConfigurator configurator(net_log(), event_creator());
EXPECT_EQ(std::string(), event_store()->GetHttpProxyList()); EXPECT_EQ(std::string(), event_store()->GetHttpProxyList());
EXPECT_EQ(std::string(), event_store()->SanitizedLastBypassEvent()); EXPECT_EQ(std::string(), event_store()->SanitizedLastBypassEvent());
...@@ -230,7 +240,7 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) { ...@@ -230,7 +240,7 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) {
net::ProxyServer(net::ProxyServer::SCHEME_HTTPS, net::ProxyServer(net::ProxyServer::SCHEME_HTTPS,
net::HostPortPair("bar.com", 443)), net::HostPortPair("bar.com", 443)),
ProxyServer::CORE)); ProxyServer::CORE));
configurator.Enable(false, false, http_proxies); configurator.Enable(manager, http_proxies);
EXPECT_EQ("foo.com:80;https://bar.com:443", EXPECT_EQ("foo.com:80;https://bar.com:443",
event_store()->GetHttpProxyList()); event_store()->GetHttpProxyList());
...@@ -239,9 +249,14 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) { ...@@ -239,9 +249,14 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) {
} }
TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventFullURL) { TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventFullURL) {
base::MessageLoopForIO loop;
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
DataReductionProxyConfigurator configurator(net_log(), event_creator()); DataReductionProxyConfigurator configurator(net_log(), event_creator());
std::vector<DataReductionProxyServer> http_proxies; std::vector<DataReductionProxyServer> http_proxies;
configurator.Enable(false, false, http_proxies); configurator.Enable(manager, http_proxies);
std::unique_ptr<base::DictionaryValue> bypass_event( std::unique_ptr<base::DictionaryValue> bypass_event(
new base::DictionaryValue()); new base::DictionaryValue());
...@@ -272,9 +287,14 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventFullURL) { ...@@ -272,9 +287,14 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventFullURL) {
} }
TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventHostOnly) { TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventHostOnly) {
base::MessageLoopForIO loop;
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
DataReductionProxyConfigurator configurator(net_log(), event_creator()); DataReductionProxyConfigurator configurator(net_log(), event_creator());
std::vector<DataReductionProxyServer> http_proxies; std::vector<DataReductionProxyServer> http_proxies;
configurator.Enable(false, false, http_proxies); configurator.Enable(manager, http_proxies);
std::unique_ptr<base::DictionaryValue> bypass_event( std::unique_ptr<base::DictionaryValue> bypass_event(
new base::DictionaryValue()); new base::DictionaryValue());
......
...@@ -15,9 +15,18 @@ message ProxyFlags { ...@@ -15,9 +15,18 @@ message ProxyFlags {
// State of different proxy schemes on a given network. // State of different proxy schemes on a given network.
message NetworkProperties { message NetworkProperties {
// True if the usage of secure proxy has been disallowed by the carrier.
optional bool secure_proxy_disallowed_by_carrier = 1; optional bool secure_proxy_disallowed_by_carrier = 1;
// True if the network has a captive portal.
optional bool has_captive_portal = 2; optional bool has_captive_portal = 2;
// State of the secure core data saver proxies.
optional ProxyFlags secure_proxy_flags = 3; optional ProxyFlags secure_proxy_flags = 3;
// State of the insecure core data saver proxies.
optional ProxyFlags insecure_proxy_flags = 4; optional ProxyFlags insecure_proxy_flags = 4;
// Time when this network property was last modified.
optional int64 last_modified = 5; optional int64 last_modified = 5;
// State of the secure non-core data saver proxies.
optional ProxyFlags secure_non_core_proxy_flags = 6;
// State of the insecure non-core data saver proxies.
optional ProxyFlags insecure_non_core_proxy_flags = 7;
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment