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)) | |
megjablon
2017/05/22 23:58:57
Can this check just be moved inside the Internal m
dougarnett
2017/05/23 16:28:44
My intention is to delete the *Internal methods in
| |
1014 return ShouldAcceptServerLoFi(request, previews_decider); | |
1015 | |
1013 bool enable_lofi = ShouldEnableLoFiInternal(request, previews_decider); | 1016 bool enable_lofi = ShouldEnableLoFiInternal(request, previews_decider); |
1014 | 1017 |
1015 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || | 1018 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || |
1016 params::IsIncludedInLoFiEnabledFieldTrial()) { | 1019 params::IsIncludedInLoFiEnabledFieldTrial()) { |
1017 RecordAutoLoFiRequestHeaderStateChange( | 1020 RecordAutoLoFiRequestHeaderStateChange( |
1018 connection_type_, previous_state_lofi_on_, enable_lofi); | 1021 connection_type_, previous_state_lofi_on_, enable_lofi); |
1019 previous_state_lofi_on_ = enable_lofi; | 1022 previous_state_lofi_on_ = enable_lofi; |
1020 } | 1023 } |
1021 | 1024 |
1022 return enable_lofi; | 1025 return enable_lofi; |
1023 } | 1026 } |
1024 | 1027 |
1025 bool DataReductionProxyConfig::ShouldEnableLitePages( | 1028 bool DataReductionProxyConfig::ShouldEnableLitePages( |
1026 const net::URLRequest& request, | 1029 const net::URLRequest& request, |
1027 previews::PreviewsDecider* previews_decider) { | 1030 const previews::PreviewsDecider& previews_decider) { |
1028 DCHECK(previews_decider); | |
1029 DCHECK(thread_checker_.CalledOnValidThread()); | 1031 DCHECK(thread_checker_.CalledOnValidThread()); |
1030 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); | 1032 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); |
1031 DCHECK(!request.url().SchemeIsCryptographic()); | 1033 DCHECK(!request.url().SchemeIsCryptographic()); |
1032 | 1034 |
1035 if (base::FeatureList::IsEnabled( | |
1036 features::kDataReductionProxyDecidesTransform)) | |
megjablon
2017/05/22 23:58:57
Same here
dougarnett
2017/05/23 16:28:45
Acknowledged.
| |
1037 return ShouldAcceptLitePages(request, previews_decider); | |
1038 | |
1033 return ShouldEnableLitePagesInternal(request, previews_decider); | 1039 return ShouldEnableLitePagesInternal(request, previews_decider); |
1034 } | 1040 } |
1035 | 1041 |
1036 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const { | 1042 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const { |
1037 DCHECK(thread_checker_.CalledOnValidThread()); | 1043 DCHECK(thread_checker_.CalledOnValidThread()); |
1038 return enabled_by_user_ && !unreachable_; | 1044 return enabled_by_user_ && !unreachable_; |
1039 } | 1045 } |
1040 | 1046 |
1047 bool DataReductionProxyConfig::IsBlackListedOrDisabled( | |
1048 const net::URLRequest& request, | |
1049 const previews::PreviewsDecider& previews_decider, | |
1050 previews::PreviewsType previews_type) { | |
1051 // Make sure request is not locally blacklisted. | |
1052 if (params::IsBlackListEnabledForServerPreviews()) { | |
1053 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network | |
1054 // speed is checked in IsNetworkQualityProhibitivelySlow(). | |
1055 // TODO(ryansturm): Use the correct ECT value (or add new method to | |
1056 // just check blacklist). crbug.com/720102 | |
1057 return !previews_decider.ShouldAllowPreviewAtECT( | |
1058 request, previews_type, net::EFFECTIVE_CONNECTION_TYPE_4G); | |
1059 } else { | |
1060 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit | |
1061 // will be removed when Lo-Fi and Lite Pages are moved over to using the | |
1062 // PreviewsBlackList. | |
1063 return lofi_off_; | |
1064 } | |
1065 } | |
1066 | |
1067 bool DataReductionProxyConfig::ShouldAcceptServerLoFi( | |
1068 const net::URLRequest& request, | |
1069 const previews::PreviewsDecider& previews_decider) { | |
1070 DCHECK(thread_checker_.CalledOnValidThread()); | |
1071 DCHECK(base::FeatureList::IsEnabled( | |
1072 features::kDataReductionProxyDecidesTransform)); | |
1073 | |
1074 // LitePages overrides Server Lo-Fi. Server will direct Server Lo-Fi for | |
1075 // resources if applicable. | |
1076 if (ShouldEnableLitePages(request, previews_decider)) { | |
1077 return false; | |
1078 } | |
1079 | |
1080 if (IsBlackListedOrDisabled(request, previews_decider, | |
1081 previews::PreviewsType::LOFI)) | |
1082 return false; | |
1083 | |
1084 if (params::IsLoFiAlwaysOnViaFlags()) | |
1085 return true; | |
1086 | |
1087 if (params::IsLoFiCellularOnlyViaFlags()) { | |
1088 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); | |
1089 } | |
1090 | |
1091 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || | |
1092 params::IsIncludedInLoFiEnabledFieldTrial()) { | |
1093 // Accept Lo-Fi from the data reduction proxy (it will handle the effective | |
1094 // connection type check). | |
1095 return true; | |
1096 } | |
1097 | |
1098 return false; | |
1099 } | |
1100 | |
1101 bool DataReductionProxyConfig::ShouldAcceptLitePages( | |
1102 const net::URLRequest& request, | |
1103 const previews::PreviewsDecider& previews_decider) { | |
1104 DCHECK(thread_checker_.CalledOnValidThread()); | |
1105 DCHECK(base::FeatureList::IsEnabled( | |
1106 features::kDataReductionProxyDecidesTransform)); | |
1107 | |
1108 if (IsBlackListedOrDisabled(request, previews_decider, | |
1109 previews::PreviewsType::LITE_PAGE)) | |
1110 return false; | |
1111 | |
1112 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) | |
1113 return true; | |
1114 | |
1115 if (params::IsLoFiCellularOnlyViaFlags() && | |
1116 params::AreLitePagesEnabledViaFlags()) { | |
1117 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); | |
1118 } | |
1119 | |
1120 if ((params::IsLoFiSlowConnectionsOnlyViaFlags() && | |
1121 params::AreLitePagesEnabledViaFlags()) || | |
1122 params::IsIncludedInLitePageFieldTrial()) { | |
1123 // Accept LitePages from the data reduction proxy (it will handle the | |
1124 // effective connection type check). | |
1125 return true; | |
1126 } | |
1127 | |
1128 return false; | |
1129 } | |
1130 | |
1041 bool DataReductionProxyConfig::ShouldEnableLoFiInternal( | 1131 bool DataReductionProxyConfig::ShouldEnableLoFiInternal( |
1042 const net::URLRequest& request, | 1132 const net::URLRequest& request, |
1043 previews::PreviewsDecider* previews_decider) { | 1133 const previews::PreviewsDecider& previews_decider) { |
1044 DCHECK(thread_checker_.CalledOnValidThread()); | 1134 DCHECK(thread_checker_.CalledOnValidThread()); |
1135 DCHECK(!base::FeatureList::IsEnabled( | |
1136 features::kDataReductionProxyDecidesTransform)); | |
1045 | 1137 |
1046 last_query_ = GetTicksNow(); | 1138 last_query_ = GetTicksNow(); |
1047 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; | 1139 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; |
1048 | 1140 |
1049 if (params::IsBlackListEnabledForServerPreviews()) { | 1141 if (IsBlackListedOrDisabled(request, previews_decider, |
1050 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network | 1142 previews::PreviewsType::LOFI)) |
megjablon
2017/05/22 23:58:57
Use braces
dougarnett
2017/05/23 16:28:44
Done.
| |
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; | 1143 return false; |
1063 } | |
1064 | 1144 |
1065 if (params::IsLoFiAlwaysOnViaFlags()) | 1145 if (params::IsLoFiAlwaysOnViaFlags()) |
1066 return true; | 1146 return true; |
1067 | 1147 |
1068 if (params::IsLoFiCellularOnlyViaFlags()) { | 1148 if (params::IsLoFiCellularOnlyViaFlags()) { |
1069 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); | 1149 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); |
1070 } | 1150 } |
1071 | 1151 |
1072 net::NetworkQualityEstimator* network_quality_estimator; | 1152 net::NetworkQualityEstimator* network_quality_estimator; |
1073 network_quality_estimator = | 1153 network_quality_estimator = |
1074 request.context() ? request.context()->network_quality_estimator() | 1154 request.context() ? request.context()->network_quality_estimator() |
1075 : nullptr; | 1155 : nullptr; |
1076 | 1156 |
1077 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || | 1157 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || |
1078 params::IsIncludedInLoFiEnabledFieldTrial() || | 1158 params::IsIncludedInLoFiEnabledFieldTrial() || |
1079 params::IsIncludedInLoFiControlFieldTrial()) { | 1159 params::IsIncludedInLoFiControlFieldTrial()) { |
1080 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); | 1160 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); |
1081 } | 1161 } |
1082 | 1162 |
1083 return false; | 1163 return false; |
1084 } | 1164 } |
1085 | 1165 |
1086 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal( | 1166 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal( |
1087 const net::URLRequest& request, | 1167 const net::URLRequest& request, |
1088 previews::PreviewsDecider* previews_decider) { | 1168 const previews::PreviewsDecider& previews_decider) { |
1089 DCHECK(thread_checker_.CalledOnValidThread()); | 1169 DCHECK(thread_checker_.CalledOnValidThread()); |
1170 DCHECK(!base::FeatureList::IsEnabled( | |
1171 features::kDataReductionProxyDecidesTransform)); | |
1090 | 1172 |
1091 if (params::IsBlackListEnabledForServerPreviews()) { | 1173 if (IsBlackListedOrDisabled(request, previews_decider, |
1092 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network | 1174 previews::PreviewsType::LITE_PAGE)) |
megjablon
2017/05/22 23:58:57
Use braces
dougarnett
2017/05/23 16:28:45
Done.
| |
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; | 1175 return false; |
1105 } | |
1106 | 1176 |
1107 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) | 1177 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) |
1108 return true; | 1178 return true; |
1109 | 1179 |
1110 if (params::IsLoFiCellularOnlyViaFlags() && | 1180 if (params::IsLoFiCellularOnlyViaFlags() && |
1111 params::AreLitePagesEnabledViaFlags()) { | 1181 params::AreLitePagesEnabledViaFlags()) { |
1112 return net::NetworkChangeNotifier::IsConnectionCellular( | 1182 return net::NetworkChangeNotifier::IsConnectionCellular( |
1113 net::NetworkChangeNotifier::GetConnectionType()); | 1183 net::NetworkChangeNotifier::GetConnectionType()); |
1114 } | 1184 } |
1115 net::NetworkQualityEstimator* network_quality_estimator; | 1185 net::NetworkQualityEstimator* network_quality_estimator; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 DataReductionProxyConfig::GetProxiesForHttp() const { | 1230 DataReductionProxyConfig::GetProxiesForHttp() const { |
1161 DCHECK(thread_checker_.CalledOnValidThread()); | 1231 DCHECK(thread_checker_.CalledOnValidThread()); |
1162 | 1232 |
1163 if (!enabled_by_user_) | 1233 if (!enabled_by_user_) |
1164 return std::vector<DataReductionProxyServer>(); | 1234 return std::vector<DataReductionProxyServer>(); |
1165 | 1235 |
1166 return config_values_->proxies_for_http(); | 1236 return config_values_->proxies_for_http(); |
1167 } | 1237 } |
1168 | 1238 |
1169 } // namespace data_reduction_proxy | 1239 } // namespace data_reduction_proxy |
OLD | NEW |