Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc |
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc |
index 54bcda83261d17f3cb7e89582f11fac82a8cb368..098e7c69ec8b7ab08b0e182b89278e3055bbf346 100644 |
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc |
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc |
@@ -27,6 +27,7 @@ |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h" |
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
#include "components/data_use_measurement/core/data_use_user_data.h" |
#include "components/previews/core/previews_decider.h" |
@@ -965,6 +966,10 @@ bool DataReductionProxyConfig::ShouldEnableLoFi( |
DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); |
DCHECK(!request.url().SchemeIsCryptographic()); |
+ if (base::FeatureList::IsEnabled( |
+ features::kDataReductionProxyDecidesTransform)) |
+ return ShouldAcceptServerLoFi(request, previews_decider); |
+ |
bool enable_lofi = ShouldEnableLoFiInternal(request, previews_decider); |
if (params::IsLoFiSlowConnectionsOnlyViaFlags() || |
@@ -985,6 +990,10 @@ bool DataReductionProxyConfig::ShouldEnableLitePages( |
DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); |
DCHECK(!request.url().SchemeIsCryptographic()); |
+ if (base::FeatureList::IsEnabled( |
+ features::kDataReductionProxyDecidesTransform)) |
+ return ShouldAcceptLitePages(request, previews_decider); |
+ |
return ShouldEnableLitePagesInternal(request, previews_decider); |
} |
@@ -993,10 +1002,101 @@ bool DataReductionProxyConfig::enabled_by_user_and_reachable() const { |
return enabled_by_user_ && !unreachable_; |
} |
+bool DataReductionProxyConfig::ShouldAcceptServerLoFi( |
+ const net::URLRequest& request, |
+ previews::PreviewsDecider* previews_decider) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ DCHECK(base::FeatureList::IsEnabled( |
+ features::kDataReductionProxyDecidesTransform)); |
+ |
+ // LitePages overrides Server Lo-Fi. Server will direct Server Lo-Fi for |
+ // resources if applicable. |
+ if (ShouldEnableLitePages(request, previews_decider)) { |
+ return false; |
+ } |
+ |
+ // Make sure request is not locally blacklisted. |
bengr
2017/05/19 20:20:47
These functions have a lot of duplicate code, whic
dougarnett
2017/05/19 21:43:58
I agree on merit of refactoring along with cleanin
dougarnett
2017/05/19 22:29:58
Ok, have factored just this blacklist and loff_off
|
+ if (params::IsBlackListEnabledForServerPreviews()) { |
+ // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network |
+ // speed is checked in IsNetworkQualityProhibitivelySlow(). |
+ // TODO(ryansturm): Use the correct ECT value. crbug.com/720102 |
+ if (!previews_decider->ShouldAllowPreviewAtECT( |
+ request, previews::PreviewsType::LOFI, |
+ net::EFFECTIVE_CONNECTION_TYPE_4G)) { |
+ return false; |
+ } |
+ } else if (lofi_off_) { |
+ // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit |
+ // will be removed when Lo-Fi and Lite Pages are moved over to using the |
+ // PreviewsBlackList. |
+ return false; |
+ } |
+ |
+ if (params::IsLoFiAlwaysOnViaFlags()) |
+ return true; |
+ |
+ if (params::IsLoFiCellularOnlyViaFlags()) { |
+ return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); |
+ } |
+ |
+ if (params::IsLoFiSlowConnectionsOnlyViaFlags() || |
+ params::IsIncludedInLoFiEnabledFieldTrial()) { |
+ // Accept Lo-Fi from the data reduction proxy (it will handle the effective |
+ // connection type check). |
+ return true; |
+ } |
+ |
+ return false; |
+} |
+ |
+bool DataReductionProxyConfig::ShouldAcceptLitePages( |
+ const net::URLRequest& request, |
+ previews::PreviewsDecider* previews_decider) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ DCHECK(base::FeatureList::IsEnabled( |
+ features::kDataReductionProxyDecidesTransform)); |
+ |
+ if (params::IsBlackListEnabledForServerPreviews()) { |
+ // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network |
+ // speed is checked in IsNetworkQualityProhibitivelySlow(). |
+ // TODO(ryansturm): Use the correct ECT value. crbug.com/720102 |
+ if (!previews_decider->ShouldAllowPreviewAtECT( |
+ request, previews::PreviewsType::LITE_PAGE, |
+ net::EFFECTIVE_CONNECTION_TYPE_4G)) { |
+ return false; |
+ } |
+ } else if (lofi_off_) { |
+ // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit |
+ // will be removed when Lo-Fi and Lite Pages are moved over to using the |
+ // PreviewsBlackList. |
+ return false; |
+ } |
+ |
+ if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) |
+ return true; |
+ |
+ if (params::IsLoFiCellularOnlyViaFlags() && |
+ params::AreLitePagesEnabledViaFlags()) { |
+ return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); |
+ } |
+ |
+ if ((params::IsLoFiSlowConnectionsOnlyViaFlags() && |
+ params::AreLitePagesEnabledViaFlags()) || |
+ params::IsIncludedInLitePageFieldTrial()) { |
+ // Accept LitePages from the data reduction proxy (it will handle the |
+ // effective connection type check). |
+ return true; |
+ } |
+ |
+ return false; |
+} |
+ |
bool DataReductionProxyConfig::ShouldEnableLoFiInternal( |
const net::URLRequest& request, |
previews::PreviewsDecider* previews_decider) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ DCHECK(!base::FeatureList::IsEnabled( |
+ features::kDataReductionProxyDecidesTransform)); |
last_query_ = GetTicksNow(); |
network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; |
@@ -1042,6 +1142,8 @@ bool DataReductionProxyConfig::ShouldEnableLitePagesInternal( |
const net::URLRequest& request, |
previews::PreviewsDecider* previews_decider) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ DCHECK(!base::FeatureList::IsEnabled( |
+ features::kDataReductionProxyDecidesTransform)); |
if (params::IsBlackListEnabledForServerPreviews()) { |
// Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network |