Commit dc5d51ed authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adds the functionality for the config service to ignore the blacklist

When the DRP config service sends a bool to ignore the previews
blacklist for server previews, the long term (host and user) rules will
be ignored for server previews. Client previews will still respect those
rules.

Bug: 849328
Change-Id: I4ef5f6b3e71592cba1eaa9c6e0006780191de6b5
Reviewed-on: https://chromium-review.googlesource.com/1086364Reviewed-by: default avatarPeter Williamson <petewil@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565690}
parent a3856a13
...@@ -260,8 +260,8 @@ class TestPreviewsDecider : public previews::PreviewsDecider { ...@@ -260,8 +260,8 @@ class TestPreviewsDecider : public previews::PreviewsDecider {
const net::URLRequest& request, const net::URLRequest& request,
previews::PreviewsType type, previews::PreviewsType type,
net::EffectiveConnectionType effective_connection_type_threshold, net::EffectiveConnectionType effective_connection_type_threshold,
const std::vector<std::string>& host_blacklist_from_server) const std::vector<std::string>& host_blacklist_from_server,
const override { bool ignore_long_term_black_list_rules) const override {
return should_allow_preview_; return should_allow_preview_;
} }
......
...@@ -196,6 +196,7 @@ DataReductionProxyConfig::DataReductionProxyConfig( ...@@ -196,6 +196,7 @@ DataReductionProxyConfig::DataReductionProxyConfig(
configurator_(configurator), configurator_(configurator),
event_creator_(event_creator), event_creator_(event_creator),
connection_type_(net::NetworkChangeNotifier::GetConnectionType()), connection_type_(net::NetworkChangeNotifier::GetConnectionType()),
ignore_long_term_black_list_rules_(false),
network_properties_manager_(nullptr), network_properties_manager_(nullptr),
weak_factory_(this) { weak_factory_(this) {
DCHECK(io_task_runner_); DCHECK(io_task_runner_);
...@@ -766,7 +767,7 @@ bool DataReductionProxyConfig::IsBlackListedOrDisabled( ...@@ -766,7 +767,7 @@ bool DataReductionProxyConfig::IsBlackListedOrDisabled(
// TODO(crbug.com/720102): Consider new method to just check blacklist. // TODO(crbug.com/720102): Consider new method to just check blacklist.
return !previews_decider.ShouldAllowPreviewAtECT( return !previews_decider.ShouldAllowPreviewAtECT(
request, previews_type, net::EFFECTIVE_CONNECTION_TYPE_4G, request, previews_type, net::EFFECTIVE_CONNECTION_TYPE_4G,
std::vector<std::string>()); std::vector<std::string>(), ignore_long_term_black_list_rules_);
} }
bool DataReductionProxyConfig::ShouldAcceptServerPreview( bool DataReductionProxyConfig::ShouldAcceptServerPreview(
...@@ -852,4 +853,15 @@ void DataReductionProxyConfig::EnableGetNetworkIdAsynchronously() { ...@@ -852,4 +853,15 @@ void DataReductionProxyConfig::EnableGetNetworkIdAsynchronously() {
} }
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
void DataReductionProxyConfig::SetIgnoreLongTermBlackListRules(
bool ignore_long_term_black_list_rules) {
DCHECK(thread_checker_.CalledOnValidThread());
ignore_long_term_black_list_rules_ = ignore_long_term_black_list_rules;
}
bool DataReductionProxyConfig::IgnoreBlackListLongTermRulesForTesting() const {
DCHECK(thread_checker_.CalledOnValidThread());
return ignore_long_term_black_list_rules_;
}
} // namespace data_reduction_proxy } // namespace data_reduction_proxy
...@@ -202,6 +202,12 @@ class DataReductionProxyConfig ...@@ -202,6 +202,12 @@ class DataReductionProxyConfig
void EnableGetNetworkIdAsynchronously(); void EnableGetNetworkIdAsynchronously();
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
// When triggering previews, prevent long term black list rules.
void SetIgnoreLongTermBlackListRules(bool ignore_long_term_black_list_rules);
// Returns the value set in SetIgnoreLongTermBlackListRules.
bool IgnoreBlackListLongTermRulesForTesting() const;
protected: protected:
virtual base::TimeTicks GetTicksNow() const; virtual base::TimeTicks GetTicksNow() const;
...@@ -363,6 +369,9 @@ class DataReductionProxyConfig ...@@ -363,6 +369,9 @@ class DataReductionProxyConfig
bool warmup_url_fetch_in_flight_secure_proxy_; bool warmup_url_fetch_in_flight_secure_proxy_;
bool warmup_url_fetch_in_flight_core_proxy_; bool warmup_url_fetch_in_flight_core_proxy_;
// When triggerring previews, prevent long term black list rules.
bool ignore_long_term_black_list_rules_;
// Should be accessed only on the IO thread. Guaranteed to be non-null during // Should be accessed only on the IO thread. Guaranteed to be non-null during
// the lifetime of |this| if accessed on the IO thread. // the lifetime of |this| if accessed on the IO thread.
NetworkPropertiesManager* network_properties_manager_; NetworkPropertiesManager* network_properties_manager_;
......
...@@ -590,6 +590,9 @@ bool DataReductionProxyConfigServiceClient::ParseAndApplyProxyConfig( ...@@ -590,6 +590,9 @@ bool DataReductionProxyConfigServiceClient::ParseAndApplyProxyConfig(
if (!config.has_proxy_config()) if (!config.has_proxy_config())
return false; return false;
config_->SetIgnoreLongTermBlackListRules(
config.ignore_long_term_black_list_rules());
// An empty proxy config is OK, and allows the server to effectively turn off // An empty proxy config is OK, and allows the server to effectively turn off
// DataSaver if needed. See http://crbug.com/840978. // DataSaver if needed. See http://crbug.com/840978.
std::vector<DataReductionProxyServer> proxies = std::vector<DataReductionProxyServer> proxies =
......
...@@ -91,7 +91,8 @@ ClientConfig CreateConfig(const std::string& session_key, ...@@ -91,7 +91,8 @@ ClientConfig CreateConfig(const std::string& session_key,
const std::string& secondary_host, const std::string& secondary_host,
int secondary_port, int secondary_port,
const ProxyServer_ProxyType& secondary_proxy_type, const ProxyServer_ProxyType& secondary_proxy_type,
float reporting_fraction) { float reporting_fraction,
bool ignore_long_term_black_list_rules) {
ClientConfig config; ClientConfig config;
config.set_session_key(session_key); config.set_session_key(session_key);
...@@ -104,6 +105,8 @@ ClientConfig CreateConfig(const std::string& session_key, ...@@ -104,6 +105,8 @@ ClientConfig CreateConfig(const std::string& session_key,
config.mutable_pageload_metrics_config()->set_reporting_fraction( config.mutable_pageload_metrics_config()->set_reporting_fraction(
reporting_fraction); reporting_fraction);
} }
config.set_ignore_long_term_black_list_rules(
ignore_long_term_black_list_rules);
ProxyServer* primary_proxy = ProxyServer* primary_proxy =
config.mutable_proxy_config()->add_http_proxy_servers(); config.mutable_proxy_config()->add_http_proxy_servers();
primary_proxy->set_scheme(primary_scheme); primary_proxy->set_scheme(primary_scheme);
...@@ -172,11 +175,11 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test { ...@@ -172,11 +175,11 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
ASSERT_NE(nullptr, context_->network_delegate()); ASSERT_NE(nullptr, context_->network_delegate());
// Set up the various test ClientConfigs. // Set up the various test ClientConfigs.
ClientConfig config = ClientConfig config = CreateConfig(
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0, kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer::CORE,
ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP, ProxyServer_ProxyScheme_HTTP, "fallback.net", 80,
"fallback.net", 80, ProxyServer::UNSPECIFIED_TYPE, 0.5f); ProxyServer::UNSPECIFIED_TYPE, 0.5f, false);
config.SerializeToString(&config_); config.SerializeToString(&config_);
encoded_config_ = EncodeConfig(config); encoded_config_ = EncodeConfig(config);
...@@ -184,21 +187,21 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test { ...@@ -184,21 +187,21 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
kOldSuccessSessionKey, kConfigRefreshDurationSeconds, 0, kOldSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "old.origin.net", 443, ProxyServer::CORE, ProxyServer_ProxyScheme_HTTPS, "old.origin.net", 443, ProxyServer::CORE,
ProxyServer_ProxyScheme_HTTP, "old.fallback.net", 80, ProxyServer_ProxyScheme_HTTP, "old.fallback.net", 80,
ProxyServer::UNSPECIFIED_TYPE, 0.0f); ProxyServer::UNSPECIFIED_TYPE, 0.0f, false);
previous_config.SerializeToString(&previous_config_); previous_config.SerializeToString(&previous_config_);
ClientConfig persisted = ClientConfig persisted = CreateConfig(
CreateConfig(kPersistedSessionKey, kConfigRefreshDurationSeconds, 0, kPersistedSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "persisted.net", 443, ProxyServer_ProxyScheme_HTTPS, "persisted.net", 443, ProxyServer::CORE,
ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP, ProxyServer_ProxyScheme_HTTP, "persisted.net", 80,
"persisted.net", 80, ProxyServer::UNSPECIFIED_TYPE, 0.0f); ProxyServer::UNSPECIFIED_TYPE, 0.0f, false);
loaded_config_ = EncodeConfig(persisted); loaded_config_ = EncodeConfig(persisted);
ClientConfig zero_reporting_fraction_config = ClientConfig zero_reporting_fraction_config = CreateConfig(
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0, kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer::CORE,
ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP, ProxyServer_ProxyScheme_HTTP, "origin.net", 0,
"origin.net", 0, ProxyServer::UNSPECIFIED_TYPE, 0.0f); ProxyServer::UNSPECIFIED_TYPE, 0.0f, false);
zero_reporting_fraction_encoded_config_ = zero_reporting_fraction_encoded_config_ =
EncodeConfig(zero_reporting_fraction_config); EncodeConfig(zero_reporting_fraction_config);
...@@ -206,29 +209,36 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test { ...@@ -206,29 +209,36 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0, CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "", 443, ProxyServer::CORE, ProxyServer_ProxyScheme_HTTPS, "", 443, ProxyServer::CORE,
ProxyServer_ProxyScheme_HTTP, "", 0, ProxyServer_ProxyScheme_HTTP, "", 0,
ProxyServer::UNSPECIFIED_TYPE, 1.0f); ProxyServer::UNSPECIFIED_TYPE, 1.0f, false);
one_reporting_fraction_encoded_config_ = one_reporting_fraction_encoded_config_ =
EncodeConfig(one_reporting_fraction_config); EncodeConfig(one_reporting_fraction_config);
// Passing in -1.0f as the reporting fraction causes the // Passing in -1.0f as the reporting fraction causes the
// |empty_reporting_fraction_config| to have no pageload_metrics_config() // |empty_reporting_fraction_config| to have no pageload_metrics_config()
// set. // set.
ClientConfig empty_reporting_fraction_config = ClientConfig empty_reporting_fraction_config = CreateConfig(
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0, kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer::CORE,
ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP, ProxyServer_ProxyScheme_HTTP, "origin.net", 0,
"origin.net", 0, ProxyServer::UNSPECIFIED_TYPE, -1.0f); ProxyServer::UNSPECIFIED_TYPE, -1.0f, false);
empty_reporting_fraction_encoded_config_ = empty_reporting_fraction_encoded_config_ =
EncodeConfig(empty_reporting_fraction_config); EncodeConfig(empty_reporting_fraction_config);
ClientConfig half_reporting_fraction_config = ClientConfig half_reporting_fraction_config = CreateConfig(
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0, kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer::CORE,
ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP, ProxyServer_ProxyScheme_HTTP, "origin.net", 0,
"origin.net", 0, ProxyServer::UNSPECIFIED_TYPE, 0.5f); ProxyServer::UNSPECIFIED_TYPE, 0.5f, false);
half_reporting_fraction_encoded_config_ = half_reporting_fraction_encoded_config_ =
EncodeConfig(half_reporting_fraction_config); EncodeConfig(half_reporting_fraction_config);
ClientConfig ignore_black_list_config = CreateConfig(
kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer::CORE,
ProxyServer_ProxyScheme_HTTP, "origin.net", 0,
ProxyServer::UNSPECIFIED_TYPE, 0.5f, true);
ignore_black_list_encoded_config_ = EncodeConfig(ignore_black_list_config);
ClientConfig no_proxies_config; ClientConfig no_proxies_config;
no_proxies_config.set_session_key(kSuccessSessionKey); no_proxies_config.set_session_key(kSuccessSessionKey);
no_proxies_config.mutable_refresh_duration()->set_seconds( no_proxies_config.mutable_refresh_duration()->set_seconds(
...@@ -454,6 +464,9 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test { ...@@ -454,6 +464,9 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
const std::string& half_reporting_fraction_encoded_config() const { const std::string& half_reporting_fraction_encoded_config() const {
return half_reporting_fraction_encoded_config_; return half_reporting_fraction_encoded_config_;
} }
const std::string& ignore_black_list_encoded_config() const {
return ignore_black_list_encoded_config_;
}
const std::string& no_proxies_config() const { return no_proxies_config_; } const std::string& no_proxies_config() const { return no_proxies_config_; }
const std::string& loaded_config() const { return loaded_config_; } const std::string& loaded_config() const { return loaded_config_; }
...@@ -498,6 +511,9 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test { ...@@ -498,6 +511,9 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
// A configuration where the pingback reporting fraction is set to 0.5f. // A configuration where the pingback reporting fraction is set to 0.5f.
std::string half_reporting_fraction_encoded_config_; std::string half_reporting_fraction_encoded_config_;
// A configuration where the black list rules are ignored.
std::string ignore_black_list_encoded_config_;
// A configuration where no proxies are configured. // A configuration where no proxies are configured.
std::string no_proxies_config_; std::string no_proxies_config_;
...@@ -1249,11 +1265,11 @@ TEST_F(DataReductionProxyConfigServiceClientTest, HTTPRequests) { ...@@ -1249,11 +1265,11 @@ TEST_F(DataReductionProxyConfigServiceClientTest, HTTPRequests) {
TEST_F(DataReductionProxyConfigServiceClientTest, ApplyClientConfigOverride) { TEST_F(DataReductionProxyConfigServiceClientTest, ApplyClientConfigOverride) {
const std::string override_key = "OverrideSecureSession"; const std::string override_key = "OverrideSecureSession";
std::string encoded_config; std::string encoded_config;
ClientConfig config = ClientConfig config = CreateConfig(
CreateConfig(override_key, kConfigRefreshDurationSeconds, 0, override_key, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer_ProxyScheme_HTTPS, "origin.net", 443, ProxyServer::CORE,
ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP, ProxyServer_ProxyScheme_HTTP, "fallback.net", 80,
"fallback.net", 80, ProxyServer::UNSPECIFIED_TYPE, 0.5f); ProxyServer::UNSPECIFIED_TYPE, 0.5f, false);
config.SerializeToString(&encoded_config); config.SerializeToString(&encoded_config);
base::Base64Encode(encoded_config, &encoded_config); base::Base64Encode(encoded_config, &encoded_config);
...@@ -1395,6 +1411,15 @@ TEST_F(DataReductionProxyConfigServiceClientTest, ...@@ -1395,6 +1411,15 @@ TEST_F(DataReductionProxyConfigServiceClientTest,
config_client()->ApplySerializedConfig( config_client()->ApplySerializedConfig(
half_reporting_fraction_encoded_config()); half_reporting_fraction_encoded_config());
EXPECT_EQ(0.5f, pingback_reporting_fraction()); EXPECT_EQ(0.5f, pingback_reporting_fraction());
EXPECT_FALSE(config()->IgnoreBlackListLongTermRulesForTesting());
}
TEST_F(DataReductionProxyConfigServiceClientTest,
ApplySerializedConfigIgnoreBlackList) {
Init(true);
config_client()->ApplySerializedConfig(ignore_black_list_encoded_config());
EXPECT_TRUE(config()->IgnoreBlackListLongTermRulesForTesting());
} }
TEST_F(DataReductionProxyConfigServiceClientTest, EmptyConfigDisablesDRP) { TEST_F(DataReductionProxyConfigServiceClientTest, EmptyConfigDisablesDRP) {
......
...@@ -27,6 +27,9 @@ message ClientConfig { ...@@ -27,6 +27,9 @@ message ClientConfig {
optional Duration refresh_duration = 4; optional Duration refresh_duration = 4;
// Configuration information for reporting pageload metrics. // Configuration information for reporting pageload metrics.
optional PageloadMetricsConfig pageload_metrics_config = 5; optional PageloadMetricsConfig pageload_metrics_config = 5;
// Prevents the host base and user base blacklisting behaviors for lite pages
// and server LoFi.
optional bool ignore_long_term_black_list_rules = 7;
} }
// The configuration for reporting pageload metrics. // The configuration for reporting pageload metrics.
...@@ -169,4 +172,4 @@ message VersionInfo { ...@@ -169,4 +172,4 @@ message VersionInfo {
// The production channel, e.g. "canary", "dev", "beta", "stable". // The production channel, e.g. "canary", "dev", "beta", "stable".
optional string channel = 4; optional string channel = 4;
} }
\ No newline at end of file
...@@ -42,7 +42,8 @@ content::PreviewsState DetermineEnabledClientPreviewsState( ...@@ -42,7 +42,8 @@ content::PreviewsState DetermineEnabledClientPreviewsState(
previews_decider->ShouldAllowPreviewAtECT( previews_decider->ShouldAllowPreviewAtECT(
url_request, previews::PreviewsType::LOFI, url_request, previews::PreviewsType::LOFI,
previews::params::EffectiveConnectionTypeThresholdForClientLoFi(), previews::params::EffectiveConnectionTypeThresholdForClientLoFi(),
previews::params::GetBlackListedHostsForClientLoFiFieldTrial())) { previews::params::GetBlackListedHostsForClientLoFiFieldTrial(),
false)) {
previews_state |= content::CLIENT_LOFI_ON; previews_state |= content::CLIENT_LOFI_ON;
return previews_state; return previews_state;
} }
......
...@@ -31,8 +31,8 @@ class PreviewEnabledPreviewsDecider : public PreviewsDecider { ...@@ -31,8 +31,8 @@ class PreviewEnabledPreviewsDecider : public PreviewsDecider {
const net::URLRequest& request, const net::URLRequest& request,
PreviewsType type, PreviewsType type,
net::EffectiveConnectionType effective_connection_type_threshold, net::EffectiveConnectionType effective_connection_type_threshold,
const std::vector<std::string>& host_blacklist_from_server) const std::vector<std::string>& host_blacklist_from_server,
const override { bool ignore_long_term_black_list_rules) const override {
return IsEnabled(type); return IsEnabled(type);
} }
...@@ -40,7 +40,7 @@ class PreviewEnabledPreviewsDecider : public PreviewsDecider { ...@@ -40,7 +40,7 @@ class PreviewEnabledPreviewsDecider : public PreviewsDecider {
PreviewsType type) const override { PreviewsType type) const override {
return ShouldAllowPreviewAtECT(request, type, return ShouldAllowPreviewAtECT(request, type,
params::GetECTThresholdForPreview(type), params::GetECTThresholdForPreview(type),
std::vector<std::string>()); std::vector<std::string>(), false);
} }
bool IsURLAllowedForPreview(const net::URLRequest& request, bool IsURLAllowedForPreview(const net::URLRequest& request,
......
...@@ -206,16 +206,20 @@ void PreviewsIOData::SetIgnorePreviewsBlacklistDecision(bool ignored) { ...@@ -206,16 +206,20 @@ void PreviewsIOData::SetIgnorePreviewsBlacklistDecision(bool ignored) {
bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request, bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request,
PreviewsType type) const { PreviewsType type) const {
DCHECK(type == PreviewsType::OFFLINE || type == PreviewsType::NOSCRIPT);
// Consumers that need to specify a blacklist or ignore flag should use
// ShouldAllowPreviewAtECT directly.
return ShouldAllowPreviewAtECT(request, type, return ShouldAllowPreviewAtECT(request, type,
params::GetECTThresholdForPreview(type), params::GetECTThresholdForPreview(type),
std::vector<std::string>()); std::vector<std::string>(), false);
} }
bool PreviewsIOData::ShouldAllowPreviewAtECT( bool PreviewsIOData::ShouldAllowPreviewAtECT(
const net::URLRequest& request, const net::URLRequest& request,
PreviewsType type, PreviewsType type,
net::EffectiveConnectionType effective_connection_type_threshold, net::EffectiveConnectionType effective_connection_type_threshold,
const std::vector<std::string>& host_blacklist_from_server) const { const std::vector<std::string>& host_blacklist_from_server,
bool ignore_long_term_black_list_rules) const {
if (!previews::params::ArePreviewsAllowed()) { if (!previews::params::ArePreviewsAllowed()) {
return false; return false;
} }
...@@ -243,7 +247,9 @@ bool PreviewsIOData::ShouldAllowPreviewAtECT( ...@@ -243,7 +247,9 @@ bool PreviewsIOData::ShouldAllowPreviewAtECT(
// The blacklist will disallow certain hosts for periods of time based on // The blacklist will disallow certain hosts for periods of time based on
// user's opting out of the preview. // user's opting out of the preview.
PreviewsEligibilityReason status = previews_black_list_->IsLoadedAndAllowed( PreviewsEligibilityReason status = previews_black_list_->IsLoadedAndAllowed(
request.url(), type, &passed_reasons); request.url(), type, ignore_long_term_black_list_rules,
&passed_reasons);
if (status != PreviewsEligibilityReason::ALLOWED) { if (status != PreviewsEligibilityReason::ALLOWED) {
if (type == PreviewsType::LITE_PAGE) { if (type == PreviewsType::LITE_PAGE) {
PreviewsUserData::GetData(request)->set_black_listed_for_lite_page( PreviewsUserData::GetData(request)->set_black_listed_for_lite_page(
...@@ -343,12 +349,13 @@ bool PreviewsIOData::ShouldAllowPreviewAtECT( ...@@ -343,12 +349,13 @@ bool PreviewsIOData::ShouldAllowPreviewAtECT(
bool PreviewsIOData::IsURLAllowedForPreview(const net::URLRequest& request, bool PreviewsIOData::IsURLAllowedForPreview(const net::URLRequest& request,
PreviewsType type) const { PreviewsType type) const {
DCHECK_EQ(PreviewsType::NOSCRIPT, type);
if (previews_black_list_ && !blacklist_ignored_) { if (previews_black_list_ && !blacklist_ignored_) {
std::vector<PreviewsEligibilityReason> passed_reasons; std::vector<PreviewsEligibilityReason> passed_reasons;
// The blacklist will disallow certain hosts for periods of time based on // The blacklist will disallow certain hosts for periods of time based on
// user's opting out of the preview. // user's opting out of the preview.
PreviewsEligibilityReason status = previews_black_list_->IsLoadedAndAllowed( PreviewsEligibilityReason status = previews_black_list_->IsLoadedAndAllowed(
request.url(), type, &passed_reasons); request.url(), type, false, &passed_reasons);
if (status != PreviewsEligibilityReason::ALLOWED) { if (status != PreviewsEligibilityReason::ALLOWED) {
if (type == PreviewsType::LITE_PAGE) { if (type == PreviewsType::LITE_PAGE) {
PreviewsUserData::GetData(request)->set_black_listed_for_lite_page( PreviewsUserData::GetData(request)->set_black_listed_for_lite_page(
......
...@@ -107,8 +107,8 @@ class PreviewsIOData : public PreviewsDecider, ...@@ -107,8 +107,8 @@ class PreviewsIOData : public PreviewsDecider,
const net::URLRequest& request, const net::URLRequest& request,
PreviewsType type, PreviewsType type,
net::EffectiveConnectionType effective_connection_type_threshold, net::EffectiveConnectionType effective_connection_type_threshold,
const std::vector<std::string>& host_blacklist_from_server) const std::vector<std::string>& host_blacklist_from_server,
const override; bool ignore_long_term_black_list_rules) const override;
bool IsURLAllowedForPreview(const net::URLRequest& request, bool IsURLAllowedForPreview(const net::URLRequest& request,
PreviewsType type) const override; PreviewsType type) const override;
......
...@@ -147,6 +147,7 @@ void PreviewsBlackList::AddPreviewNavigationSync(const GURL& url, ...@@ -147,6 +147,7 @@ void PreviewsBlackList::AddPreviewNavigationSync(const GURL& url,
PreviewsEligibilityReason PreviewsBlackList::IsLoadedAndAllowed( PreviewsEligibilityReason PreviewsBlackList::IsLoadedAndAllowed(
const GURL& url, const GURL& url,
PreviewsType type, PreviewsType type,
bool ignore_long_term_black_list_rules,
std::vector<PreviewsEligibilityReason>* passed_reasons) const { std::vector<PreviewsEligibilityReason>* passed_reasons) const {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(url.has_host()); DCHECK(url.has_host());
...@@ -161,6 +162,8 @@ PreviewsEligibilityReason PreviewsBlackList::IsLoadedAndAllowed( ...@@ -161,6 +162,8 @@ PreviewsEligibilityReason PreviewsBlackList::IsLoadedAndAllowed(
return PreviewsEligibilityReason::USER_RECENTLY_OPTED_OUT; return PreviewsEligibilityReason::USER_RECENTLY_OPTED_OUT;
} }
passed_reasons->push_back(PreviewsEligibilityReason::USER_RECENTLY_OPTED_OUT); passed_reasons->push_back(PreviewsEligibilityReason::USER_RECENTLY_OPTED_OUT);
if (ignore_long_term_black_list_rules)
return PreviewsEligibilityReason::ALLOWED;
if (host_indifferent_black_list_item_->IsBlackListed(clock_->Now())) if (host_indifferent_black_list_item_->IsBlackListed(clock_->Now()))
return PreviewsEligibilityReason::USER_BLACKLISTED; return PreviewsEligibilityReason::USER_BLACKLISTED;
passed_reasons->push_back(PreviewsEligibilityReason::USER_BLACKLISTED); passed_reasons->push_back(PreviewsEligibilityReason::USER_BLACKLISTED);
......
...@@ -108,6 +108,7 @@ class PreviewsBlackList { ...@@ -108,6 +108,7 @@ class PreviewsBlackList {
virtual PreviewsEligibilityReason IsLoadedAndAllowed( virtual PreviewsEligibilityReason IsLoadedAndAllowed(
const GURL& url, const GURL& url,
PreviewsType type, PreviewsType type,
bool ignore_long_term_black_list_rules,
std::vector<PreviewsEligibilityReason>* passed_reasons) const; std::vector<PreviewsEligibilityReason>* passed_reasons) const;
// Asynchronously deletes all entries in the in-memory black list. Informs // Asynchronously deletes all entries in the in-memory black list. Informs
......
...@@ -30,7 +30,8 @@ class PreviewsDecider { ...@@ -30,7 +30,8 @@ class PreviewsDecider {
const net::URLRequest& request, const net::URLRequest& request,
PreviewsType type, PreviewsType type,
net::EffectiveConnectionType effective_connection_type_threshold, net::EffectiveConnectionType effective_connection_type_threshold,
const std::vector<std::string>& host_blacklist_from_server) const = 0; const std::vector<std::string>& host_blacklist_from_server,
bool ignore_long_term_black_list_rules) const = 0;
// Same as ShouldAllowPreviewAtECT, but uses the previews default // Same as ShouldAllowPreviewAtECT, but uses the previews default
// EffectiveConnectionType and no blacklisted hosts from the server. // EffectiveConnectionType and no blacklisted hosts from the server.
......
...@@ -15,7 +15,8 @@ bool TestPreviewsDecider::ShouldAllowPreviewAtECT( ...@@ -15,7 +15,8 @@ bool TestPreviewsDecider::ShouldAllowPreviewAtECT(
const net::URLRequest& request, const net::URLRequest& request,
previews::PreviewsType type, previews::PreviewsType type,
net::EffectiveConnectionType effective_connection_type_threshold, net::EffectiveConnectionType effective_connection_type_threshold,
const std::vector<std::string>& host_blacklist_from_server) const { const std::vector<std::string>& host_blacklist_from_server,
bool ignore_long_term_black_list_rules) const {
return allow_previews_; return allow_previews_;
} }
......
...@@ -20,8 +20,8 @@ class TestPreviewsDecider : public previews::PreviewsDecider { ...@@ -20,8 +20,8 @@ class TestPreviewsDecider : public previews::PreviewsDecider {
const net::URLRequest& request, const net::URLRequest& request,
previews::PreviewsType type, previews::PreviewsType type,
net::EffectiveConnectionType effective_connection_type_threshold, net::EffectiveConnectionType effective_connection_type_threshold,
const std::vector<std::string>& host_blacklist_from_server) const std::vector<std::string>& host_blacklist_from_server,
const override; bool ignore_long_term_black_list_rules) const override;
bool ShouldAllowPreview(const net::URLRequest& request, bool ShouldAllowPreview(const net::URLRequest& request,
previews::PreviewsType type) const override; previews::PreviewsType type) const override;
bool IsURLAllowedForPreview(const net::URLRequest& request, bool IsURLAllowedForPreview(const net::URLRequest& request,
......
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