Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc

Issue 2889993004: New CPAT support in DataReductionProxyConfig guarded by feature flag. (Closed)
Patch Set: Factored blacklist and lofi_off_ check (and comment verbage) into helper Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h" 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/metrics/field_trial.h" 15 #include "base/metrics/field_trial.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/metrics/histogram_base.h" 17 #include "base/metrics/histogram_base.h"
18 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
19 #include "base/metrics/sparse_histogram.h" 19 #include "base/metrics/sparse_histogram.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/stl_util.h" 21 #include "base/stl_util.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_piece.h" 23 #include "base/strings/string_piece.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "base/time/default_tick_clock.h" 26 #include "base/time/default_tick_clock.h"
27 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator.h" 27 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator.h"
28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_confi g_values.h" 28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_confi g_values.h"
29 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _creator.h" 29 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _creator.h"
30 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_featu res.h"
30 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 31 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
31 #include "components/data_use_measurement/core/data_use_user_data.h" 32 #include "components/data_use_measurement/core/data_use_user_data.h"
32 #include "components/previews/core/previews_decider.h" 33 #include "components/previews/core/previews_decider.h"
33 #include "components/previews/core/previews_experiments.h"
34 #include "components/variations/variations_associated_data.h" 34 #include "components/variations/variations_associated_data.h"
35 #include "net/base/host_port_pair.h" 35 #include "net/base/host_port_pair.h"
36 #include "net/base/load_flags.h" 36 #include "net/base/load_flags.h"
37 #include "net/base/network_change_notifier.h" 37 #include "net/base/network_change_notifier.h"
38 #include "net/log/net_log_source_type.h" 38 #include "net/log/net_log_source_type.h"
39 #include "net/nqe/effective_connection_type.h" 39 #include "net/nqe/effective_connection_type.h"
40 #include "net/proxy/proxy_server.h" 40 #include "net/proxy/proxy_server.h"
41 #include "net/traffic_annotation/network_traffic_annotation.h" 41 #include "net/traffic_annotation/network_traffic_annotation.h"
42 #include "net/url_request/url_fetcher.h" 42 #include "net/url_request/url_fetcher.h"
43 #include "net/url_request/url_fetcher_delegate.h" 43 #include "net/url_request/url_fetcher_delegate.h"
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 } 1003 }
1004 1004
1005 bool DataReductionProxyConfig::ShouldEnableLoFi( 1005 bool DataReductionProxyConfig::ShouldEnableLoFi(
1006 const net::URLRequest& request, 1006 const net::URLRequest& request,
1007 previews::PreviewsDecider* previews_decider) { 1007 previews::PreviewsDecider* previews_decider) {
1008 DCHECK(previews_decider); 1008 DCHECK(previews_decider);
1009 DCHECK(thread_checker_.CalledOnValidThread()); 1009 DCHECK(thread_checker_.CalledOnValidThread());
1010 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); 1010 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0);
1011 DCHECK(!request.url().SchemeIsCryptographic()); 1011 DCHECK(!request.url().SchemeIsCryptographic());
1012 1012
1013 if (base::FeatureList::IsEnabled(
1014 features::kDataReductionProxyDecidesTransform))
1015 return ShouldAcceptServerLoFi(request, previews_decider);
1016
1013 bool enable_lofi = ShouldEnableLoFiInternal(request, previews_decider); 1017 bool enable_lofi = ShouldEnableLoFiInternal(request, previews_decider);
1014 1018
1015 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || 1019 if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
1016 params::IsIncludedInLoFiEnabledFieldTrial()) { 1020 params::IsIncludedInLoFiEnabledFieldTrial()) {
1017 RecordAutoLoFiRequestHeaderStateChange( 1021 RecordAutoLoFiRequestHeaderStateChange(
1018 connection_type_, previous_state_lofi_on_, enable_lofi); 1022 connection_type_, previous_state_lofi_on_, enable_lofi);
1019 previous_state_lofi_on_ = enable_lofi; 1023 previous_state_lofi_on_ = enable_lofi;
1020 } 1024 }
1021 1025
1022 return enable_lofi; 1026 return enable_lofi;
1023 } 1027 }
1024 1028
1025 bool DataReductionProxyConfig::ShouldEnableLitePages( 1029 bool DataReductionProxyConfig::ShouldEnableLitePages(
1026 const net::URLRequest& request, 1030 const net::URLRequest& request,
1027 previews::PreviewsDecider* previews_decider) { 1031 previews::PreviewsDecider* previews_decider) {
1028 DCHECK(previews_decider); 1032 DCHECK(previews_decider);
1029 DCHECK(thread_checker_.CalledOnValidThread()); 1033 DCHECK(thread_checker_.CalledOnValidThread());
1030 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); 1034 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0);
1031 DCHECK(!request.url().SchemeIsCryptographic()); 1035 DCHECK(!request.url().SchemeIsCryptographic());
1032 1036
1037 if (base::FeatureList::IsEnabled(
1038 features::kDataReductionProxyDecidesTransform))
1039 return ShouldAcceptLitePages(request, previews_decider);
1040
1033 return ShouldEnableLitePagesInternal(request, previews_decider); 1041 return ShouldEnableLitePagesInternal(request, previews_decider);
1034 } 1042 }
1035 1043
1036 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const { 1044 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const {
1037 DCHECK(thread_checker_.CalledOnValidThread()); 1045 DCHECK(thread_checker_.CalledOnValidThread());
1038 return enabled_by_user_ && !unreachable_; 1046 return enabled_by_user_ && !unreachable_;
1039 } 1047 }
1040 1048
1049 bool DataReductionProxyConfig::IsBlackListedOrDisabled(
1050 const net::URLRequest& request,
1051 previews::PreviewsDecider* previews_decider,
bengr 2017/05/19 22:44:53 Why is this not a const previews::PreviewsDecider&
dougarnett 2017/05/19 23:48:31 Done.
1052 previews::PreviewsType previews_type) {
1053 // Make sure request is not locally blacklisted.
1054 if (params::IsBlackListEnabledForServerPreviews()) {
1055 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network
1056 // speed is checked in IsNetworkQualityProhibitivelySlow().
1057 // TODO(ryansturm): Use the correct ECT value (or add new method to
1058 // just check blacklist). crbug.com/720102
1059 return !previews_decider->ShouldAllowPreviewAtECT(
1060 request, previews_type, net::EFFECTIVE_CONNECTION_TYPE_4G);
1061 } else {
1062 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit
1063 // will be removed when Lo-Fi and Lite Pages are moved over to using the
1064 // PreviewsBlackList.
1065 return lofi_off_;
1066 }
1067 }
1068
1069 bool DataReductionProxyConfig::ShouldAcceptServerLoFi(
1070 const net::URLRequest& request,
1071 previews::PreviewsDecider* previews_decider) {
1072 DCHECK(thread_checker_.CalledOnValidThread());
1073 DCHECK(base::FeatureList::IsEnabled(
1074 features::kDataReductionProxyDecidesTransform));
1075
1076 // LitePages overrides Server Lo-Fi. Server will direct Server Lo-Fi for
1077 // resources if applicable.
1078 if (ShouldEnableLitePages(request, previews_decider)) {
1079 return false;
1080 }
1081
1082 if (IsBlackListedOrDisabled(request, previews_decider,
1083 previews::PreviewsType::LOFI))
1084 return false;
1085
1086 if (params::IsLoFiAlwaysOnViaFlags())
1087 return true;
1088
1089 if (params::IsLoFiCellularOnlyViaFlags()) {
1090 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_);
1091 }
1092
1093 if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
1094 params::IsIncludedInLoFiEnabledFieldTrial()) {
1095 // Accept Lo-Fi from the data reduction proxy (it will handle the effective
1096 // connection type check).
1097 return true;
1098 }
1099
1100 return false;
1101 }
1102
1103 bool DataReductionProxyConfig::ShouldAcceptLitePages(
1104 const net::URLRequest& request,
1105 previews::PreviewsDecider* previews_decider) {
1106 DCHECK(thread_checker_.CalledOnValidThread());
1107 DCHECK(base::FeatureList::IsEnabled(
1108 features::kDataReductionProxyDecidesTransform));
1109
1110 if (IsBlackListedOrDisabled(request, previews_decider,
1111 previews::PreviewsType::LITE_PAGE))
1112 return false;
1113
1114 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags())
1115 return true;
1116
1117 if (params::IsLoFiCellularOnlyViaFlags() &&
1118 params::AreLitePagesEnabledViaFlags()) {
1119 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_);
1120 }
1121
1122 if ((params::IsLoFiSlowConnectionsOnlyViaFlags() &&
1123 params::AreLitePagesEnabledViaFlags()) ||
1124 params::IsIncludedInLitePageFieldTrial()) {
1125 // Accept LitePages from the data reduction proxy (it will handle the
1126 // effective connection type check).
1127 return true;
1128 }
1129
1130 return false;
1131 }
1132
1041 bool DataReductionProxyConfig::ShouldEnableLoFiInternal( 1133 bool DataReductionProxyConfig::ShouldEnableLoFiInternal(
1042 const net::URLRequest& request, 1134 const net::URLRequest& request,
1043 previews::PreviewsDecider* previews_decider) { 1135 previews::PreviewsDecider* previews_decider) {
1044 DCHECK(thread_checker_.CalledOnValidThread()); 1136 DCHECK(thread_checker_.CalledOnValidThread());
1137 DCHECK(!base::FeatureList::IsEnabled(
1138 features::kDataReductionProxyDecidesTransform));
1045 1139
1046 last_query_ = GetTicksNow(); 1140 last_query_ = GetTicksNow();
1047 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; 1141 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN;
1048 1142
1049 if (params::IsBlackListEnabledForServerPreviews()) { 1143 if (IsBlackListedOrDisabled(request, previews_decider,
1050 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network 1144 previews::PreviewsType::LOFI))
1051 // speed is checked in IsNetworkQualityProhibitivelySlow().
1052 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102
1053 if (!previews_decider->ShouldAllowPreviewAtECT(
1054 request, previews::PreviewsType::LOFI,
1055 net::EFFECTIVE_CONNECTION_TYPE_4G)) {
1056 return false;
1057 }
1058 } else if (lofi_off_) {
1059 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit
1060 // will be removed when Lo-Fi and Lite Pages are moved over to using the
1061 // PreviewsBlackList.
1062 return false; 1145 return false;
1063 }
1064 1146
1065 if (params::IsLoFiAlwaysOnViaFlags()) 1147 if (params::IsLoFiAlwaysOnViaFlags())
1066 return true; 1148 return true;
1067 1149
1068 if (params::IsLoFiCellularOnlyViaFlags()) { 1150 if (params::IsLoFiCellularOnlyViaFlags()) {
1069 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); 1151 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_);
1070 } 1152 }
1071 1153
1072 net::NetworkQualityEstimator* network_quality_estimator; 1154 net::NetworkQualityEstimator* network_quality_estimator;
1073 network_quality_estimator = 1155 network_quality_estimator =
1074 request.context() ? request.context()->network_quality_estimator() 1156 request.context() ? request.context()->network_quality_estimator()
1075 : nullptr; 1157 : nullptr;
1076 1158
1077 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || 1159 if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
1078 params::IsIncludedInLoFiEnabledFieldTrial() || 1160 params::IsIncludedInLoFiEnabledFieldTrial() ||
1079 params::IsIncludedInLoFiControlFieldTrial()) { 1161 params::IsIncludedInLoFiControlFieldTrial()) {
1080 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); 1162 return IsNetworkQualityProhibitivelySlow(network_quality_estimator);
1081 } 1163 }
1082 1164
1083 return false; 1165 return false;
1084 } 1166 }
1085 1167
1086 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal( 1168 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal(
1087 const net::URLRequest& request, 1169 const net::URLRequest& request,
1088 previews::PreviewsDecider* previews_decider) { 1170 previews::PreviewsDecider* previews_decider) {
1089 DCHECK(thread_checker_.CalledOnValidThread()); 1171 DCHECK(thread_checker_.CalledOnValidThread());
1172 DCHECK(!base::FeatureList::IsEnabled(
1173 features::kDataReductionProxyDecidesTransform));
1090 1174
1091 if (params::IsBlackListEnabledForServerPreviews()) { 1175 if (IsBlackListedOrDisabled(request, previews_decider,
1092 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network 1176 previews::PreviewsType::LITE_PAGE))
1093 // speed is checked in IsNetworkQualityProhibitivelySlow().
1094 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102
1095 if (!previews_decider->ShouldAllowPreviewAtECT(
1096 request, previews::PreviewsType::LITE_PAGE,
1097 net::EFFECTIVE_CONNECTION_TYPE_4G)) {
1098 return false;
1099 }
1100 } else if (lofi_off_) {
1101 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit
1102 // will be removed when Lo-Fi and Lite Pages are moved over to using the
1103 // PreviewsBlackList.
1104 return false; 1177 return false;
1105 }
1106 1178
1107 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) 1179 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags())
1108 return true; 1180 return true;
1109 1181
1110 if (params::IsLoFiCellularOnlyViaFlags() && 1182 if (params::IsLoFiCellularOnlyViaFlags() &&
1111 params::AreLitePagesEnabledViaFlags()) { 1183 params::AreLitePagesEnabledViaFlags()) {
1112 return net::NetworkChangeNotifier::IsConnectionCellular( 1184 return net::NetworkChangeNotifier::IsConnectionCellular(
1113 net::NetworkChangeNotifier::GetConnectionType()); 1185 net::NetworkChangeNotifier::GetConnectionType());
1114 } 1186 }
1115 net::NetworkQualityEstimator* network_quality_estimator; 1187 net::NetworkQualityEstimator* network_quality_estimator;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 DataReductionProxyConfig::GetProxiesForHttp() const { 1232 DataReductionProxyConfig::GetProxiesForHttp() const {
1161 DCHECK(thread_checker_.CalledOnValidThread()); 1233 DCHECK(thread_checker_.CalledOnValidThread());
1162 1234
1163 if (!enabled_by_user_) 1235 if (!enabled_by_user_)
1164 return std::vector<DataReductionProxyServer>(); 1236 return std::vector<DataReductionProxyServer>();
1165 1237
1166 return config_values_->proxies_for_http(); 1238 return config_values_->proxies_for_http();
1167 } 1239 }
1168 1240
1169 } // namespace data_reduction_proxy 1241 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698