OLD | NEW |
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 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 } | 997 } |
998 | 998 |
999 bool DataReductionProxyConfig::IsEffectiveConnectionTypeSlowerThanThreshold( | 999 bool DataReductionProxyConfig::IsEffectiveConnectionTypeSlowerThanThreshold( |
1000 net::EffectiveConnectionType effective_connection_type) const { | 1000 net::EffectiveConnectionType effective_connection_type) const { |
1001 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && | 1001 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && |
1002 effective_connection_type <= lofi_effective_connection_type_threshold_; | 1002 effective_connection_type <= lofi_effective_connection_type_threshold_; |
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 const previews::PreviewsDecider& previews_decider) { |
1008 DCHECK(previews_decider); | |
1009 DCHECK(thread_checker_.CalledOnValidThread()); | 1008 DCHECK(thread_checker_.CalledOnValidThread()); |
1010 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); | 1009 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); |
1011 DCHECK(!request.url().SchemeIsCryptographic()); | 1010 DCHECK(!request.url().SchemeIsCryptographic()); |
1012 | 1011 |
| 1012 if (base::FeatureList::IsEnabled( |
| 1013 features::kDataReductionProxyDecidesTransform)) { |
| 1014 return ShouldAcceptServerLoFi(request, previews_decider); |
| 1015 } |
| 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 const previews::PreviewsDecider& previews_decider) { |
1028 DCHECK(previews_decider); | |
1029 DCHECK(thread_checker_.CalledOnValidThread()); | 1032 DCHECK(thread_checker_.CalledOnValidThread()); |
1030 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); | 1033 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); |
1031 DCHECK(!request.url().SchemeIsCryptographic()); | 1034 DCHECK(!request.url().SchemeIsCryptographic()); |
1032 | 1035 |
| 1036 if (base::FeatureList::IsEnabled( |
| 1037 features::kDataReductionProxyDecidesTransform)) { |
| 1038 return ShouldAcceptLitePages(request, previews_decider); |
| 1039 } |
| 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 const previews::PreviewsDecider& previews_decider, |
| 1052 previews::PreviewsType previews_type) const { |
| 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 const previews::PreviewsDecider& previews_decider) const { |
| 1072 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1073 DCHECK(base::FeatureList::IsEnabled( |
| 1074 features::kDataReductionProxyDecidesTransform)); |
| 1075 |
| 1076 if (IsBlackListedOrDisabled(request, previews_decider, |
| 1077 previews::PreviewsType::LOFI)) { |
| 1078 return false; |
| 1079 } |
| 1080 |
| 1081 if (params::IsLoFiAlwaysOnViaFlags()) { |
| 1082 return true; |
| 1083 } |
| 1084 |
| 1085 if (params::IsLoFiCellularOnlyViaFlags()) { |
| 1086 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); |
| 1087 } |
| 1088 |
| 1089 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || |
| 1090 params::IsIncludedInLoFiEnabledFieldTrial()) { |
| 1091 // Accept Lo-Fi from the data reduction proxy (it will handle the effective |
| 1092 // connection type check). |
| 1093 return true; |
| 1094 } |
| 1095 |
| 1096 return false; |
| 1097 } |
| 1098 |
| 1099 bool DataReductionProxyConfig::ShouldAcceptLitePages( |
| 1100 const net::URLRequest& request, |
| 1101 const previews::PreviewsDecider& previews_decider) const { |
| 1102 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1103 DCHECK(base::FeatureList::IsEnabled( |
| 1104 features::kDataReductionProxyDecidesTransform)); |
| 1105 |
| 1106 if (IsBlackListedOrDisabled(request, previews_decider, |
| 1107 previews::PreviewsType::LITE_PAGE)) { |
| 1108 return false; |
| 1109 } |
| 1110 |
| 1111 if (params::IsLoFiAlwaysOnViaFlags() && |
| 1112 params::AreLitePagesEnabledViaFlags()) { |
| 1113 return true; |
| 1114 } |
| 1115 |
| 1116 if (params::IsLoFiCellularOnlyViaFlags() && |
| 1117 params::AreLitePagesEnabledViaFlags()) { |
| 1118 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); |
| 1119 } |
| 1120 |
| 1121 if ((params::IsLoFiSlowConnectionsOnlyViaFlags() && |
| 1122 params::AreLitePagesEnabledViaFlags()) || |
| 1123 params::IsIncludedInLitePageFieldTrial()) { |
| 1124 // Accept LitePages from the data reduction proxy (it will handle the |
| 1125 // effective connection type check). |
| 1126 return true; |
| 1127 } |
| 1128 |
| 1129 return false; |
| 1130 } |
| 1131 |
1041 bool DataReductionProxyConfig::ShouldEnableLoFiInternal( | 1132 bool DataReductionProxyConfig::ShouldEnableLoFiInternal( |
1042 const net::URLRequest& request, | 1133 const net::URLRequest& request, |
1043 previews::PreviewsDecider* previews_decider) { | 1134 const previews::PreviewsDecider& previews_decider) { |
1044 DCHECK(thread_checker_.CalledOnValidThread()); | 1135 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1136 DCHECK(!base::FeatureList::IsEnabled( |
| 1137 features::kDataReductionProxyDecidesTransform)); |
1045 | 1138 |
1046 last_query_ = GetTicksNow(); | 1139 last_query_ = GetTicksNow(); |
1047 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; | 1140 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; |
1048 | 1141 |
1049 if (params::IsBlackListEnabledForServerPreviews()) { | 1142 // LitePages overrides Server Lo-Fi. No fallback to Lo-Fi supported |
1050 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network | 1143 // on this code path (not using DataReductionProxyDecidesTransform feature). |
1051 // speed is checked in IsNetworkQualityProhibitivelySlow(). | 1144 // TODO(dougarnett): Delete this surrounding method and related code once the |
1052 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102 | 1145 // DataReductionProxyDecidesTransform feature is launched to stable [725645]. |
1053 if (!previews_decider->ShouldAllowPreviewAtECT( | 1146 if (ShouldEnableLitePages(request, previews_decider)) { |
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; | 1147 return false; |
1063 } | 1148 } |
1064 | 1149 |
| 1150 if (IsBlackListedOrDisabled(request, previews_decider, |
| 1151 previews::PreviewsType::LOFI)) { |
| 1152 return false; |
| 1153 } |
| 1154 |
1065 if (params::IsLoFiAlwaysOnViaFlags()) | 1155 if (params::IsLoFiAlwaysOnViaFlags()) |
1066 return true; | 1156 return true; |
1067 | 1157 |
1068 if (params::IsLoFiCellularOnlyViaFlags()) { | 1158 if (params::IsLoFiCellularOnlyViaFlags()) { |
1069 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); | 1159 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); |
1070 } | 1160 } |
1071 | 1161 |
1072 net::NetworkQualityEstimator* network_quality_estimator; | 1162 net::NetworkQualityEstimator* network_quality_estimator; |
1073 network_quality_estimator = | 1163 network_quality_estimator = |
1074 request.context() ? request.context()->network_quality_estimator() | 1164 request.context() ? request.context()->network_quality_estimator() |
1075 : nullptr; | 1165 : nullptr; |
1076 | 1166 |
1077 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || | 1167 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || |
1078 params::IsIncludedInLoFiEnabledFieldTrial() || | 1168 params::IsIncludedInLoFiEnabledFieldTrial() || |
1079 params::IsIncludedInLoFiControlFieldTrial()) { | 1169 params::IsIncludedInLoFiControlFieldTrial()) { |
1080 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); | 1170 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); |
1081 } | 1171 } |
1082 | 1172 |
1083 return false; | 1173 return false; |
1084 } | 1174 } |
1085 | 1175 |
1086 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal( | 1176 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal( |
1087 const net::URLRequest& request, | 1177 const net::URLRequest& request, |
1088 previews::PreviewsDecider* previews_decider) { | 1178 const previews::PreviewsDecider& previews_decider) { |
1089 DCHECK(thread_checker_.CalledOnValidThread()); | 1179 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1180 DCHECK(!base::FeatureList::IsEnabled( |
| 1181 features::kDataReductionProxyDecidesTransform)); |
1090 | 1182 |
1091 if (params::IsBlackListEnabledForServerPreviews()) { | 1183 if (IsBlackListedOrDisabled(request, previews_decider, |
1092 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network | 1184 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; | 1185 return false; |
1105 } | 1186 } |
1106 | 1187 |
1107 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) | 1188 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) |
1108 return true; | 1189 return true; |
1109 | 1190 |
1110 if (params::IsLoFiCellularOnlyViaFlags() && | 1191 if (params::IsLoFiCellularOnlyViaFlags() && |
1111 params::AreLitePagesEnabledViaFlags()) { | 1192 params::AreLitePagesEnabledViaFlags()) { |
1112 return net::NetworkChangeNotifier::IsConnectionCellular( | 1193 return net::NetworkChangeNotifier::IsConnectionCellular( |
1113 net::NetworkChangeNotifier::GetConnectionType()); | 1194 net::NetworkChangeNotifier::GetConnectionType()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 DataReductionProxyConfig::GetProxiesForHttp() const { | 1241 DataReductionProxyConfig::GetProxiesForHttp() const { |
1161 DCHECK(thread_checker_.CalledOnValidThread()); | 1242 DCHECK(thread_checker_.CalledOnValidThread()); |
1162 | 1243 |
1163 if (!enabled_by_user_) | 1244 if (!enabled_by_user_) |
1164 return std::vector<DataReductionProxyServer>(); | 1245 return std::vector<DataReductionProxyServer>(); |
1165 | 1246 |
1166 return config_values_->proxies_for_http(); | 1247 return config_values_->proxies_for_http(); |
1167 } | 1248 } |
1168 | 1249 |
1169 } // namespace data_reduction_proxy | 1250 } // namespace data_reduction_proxy |
OLD | NEW |