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

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: 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/previews/core/previews_experiments.h"
34 #include "components/variations/variations_associated_data.h" 35 #include "components/variations/variations_associated_data.h"
35 #include "net/base/host_port_pair.h" 36 #include "net/base/host_port_pair.h"
36 #include "net/base/load_flags.h" 37 #include "net/base/load_flags.h"
37 #include "net/base/network_change_notifier.h" 38 #include "net/base/network_change_notifier.h"
38 #include "net/log/net_log_source_type.h" 39 #include "net/log/net_log_source_type.h"
39 #include "net/nqe/effective_connection_type.h" 40 #include "net/nqe/effective_connection_type.h"
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 } 959 }
959 960
960 bool DataReductionProxyConfig::ShouldEnableLoFi( 961 bool DataReductionProxyConfig::ShouldEnableLoFi(
961 const net::URLRequest& request, 962 const net::URLRequest& request,
962 previews::PreviewsDecider* previews_decider) { 963 previews::PreviewsDecider* previews_decider) {
963 DCHECK(previews_decider); 964 DCHECK(previews_decider);
964 DCHECK(thread_checker_.CalledOnValidThread()); 965 DCHECK(thread_checker_.CalledOnValidThread());
965 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); 966 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0);
966 DCHECK(!request.url().SchemeIsCryptographic()); 967 DCHECK(!request.url().SchemeIsCryptographic());
967 968
969 if (base::FeatureList::IsEnabled(
970 features::kDataReductionProxyDecidesTransform))
971 return ShouldAcceptServerLoFi(request, previews_decider);
972
968 bool enable_lofi = ShouldEnableLoFiInternal(request, previews_decider); 973 bool enable_lofi = ShouldEnableLoFiInternal(request, previews_decider);
969 974
970 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || 975 if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
971 params::IsIncludedInLoFiEnabledFieldTrial()) { 976 params::IsIncludedInLoFiEnabledFieldTrial()) {
972 RecordAutoLoFiRequestHeaderStateChange( 977 RecordAutoLoFiRequestHeaderStateChange(
973 connection_type_, previous_state_lofi_on_, enable_lofi); 978 connection_type_, previous_state_lofi_on_, enable_lofi);
974 previous_state_lofi_on_ = enable_lofi; 979 previous_state_lofi_on_ = enable_lofi;
975 } 980 }
976 981
977 return enable_lofi; 982 return enable_lofi;
978 } 983 }
979 984
980 bool DataReductionProxyConfig::ShouldEnableLitePages( 985 bool DataReductionProxyConfig::ShouldEnableLitePages(
981 const net::URLRequest& request, 986 const net::URLRequest& request,
982 previews::PreviewsDecider* previews_decider) { 987 previews::PreviewsDecider* previews_decider) {
983 DCHECK(previews_decider); 988 DCHECK(previews_decider);
984 DCHECK(thread_checker_.CalledOnValidThread()); 989 DCHECK(thread_checker_.CalledOnValidThread());
985 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); 990 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0);
986 DCHECK(!request.url().SchemeIsCryptographic()); 991 DCHECK(!request.url().SchemeIsCryptographic());
987 992
993 if (base::FeatureList::IsEnabled(
994 features::kDataReductionProxyDecidesTransform))
995 return ShouldAcceptLitePages(request, previews_decider);
996
988 return ShouldEnableLitePagesInternal(request, previews_decider); 997 return ShouldEnableLitePagesInternal(request, previews_decider);
989 } 998 }
990 999
991 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const { 1000 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const {
992 DCHECK(thread_checker_.CalledOnValidThread()); 1001 DCHECK(thread_checker_.CalledOnValidThread());
993 return enabled_by_user_ && !unreachable_; 1002 return enabled_by_user_ && !unreachable_;
994 } 1003 }
995 1004
1005 bool DataReductionProxyConfig::ShouldAcceptServerLoFi(
1006 const net::URLRequest& request,
1007 previews::PreviewsDecider* previews_decider) {
1008 DCHECK(thread_checker_.CalledOnValidThread());
1009 DCHECK(base::FeatureList::IsEnabled(
1010 features::kDataReductionProxyDecidesTransform));
1011
1012 // LitePages overrides Server Lo-Fi. Server will direct Server Lo-Fi for
1013 // resources if applicable.
1014 if (ShouldEnableLitePages(request, previews_decider)) {
1015 return false;
1016 }
1017
1018 // 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
1019 if (params::IsBlackListEnabledForServerPreviews()) {
1020 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network
1021 // speed is checked in IsNetworkQualityProhibitivelySlow().
1022 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102
1023 if (!previews_decider->ShouldAllowPreviewAtECT(
1024 request, previews::PreviewsType::LOFI,
1025 net::EFFECTIVE_CONNECTION_TYPE_4G)) {
1026 return false;
1027 }
1028 } else if (lofi_off_) {
1029 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit
1030 // will be removed when Lo-Fi and Lite Pages are moved over to using the
1031 // PreviewsBlackList.
1032 return false;
1033 }
1034
1035 if (params::IsLoFiAlwaysOnViaFlags())
1036 return true;
1037
1038 if (params::IsLoFiCellularOnlyViaFlags()) {
1039 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_);
1040 }
1041
1042 if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
1043 params::IsIncludedInLoFiEnabledFieldTrial()) {
1044 // Accept Lo-Fi from the data reduction proxy (it will handle the effective
1045 // connection type check).
1046 return true;
1047 }
1048
1049 return false;
1050 }
1051
1052 bool DataReductionProxyConfig::ShouldAcceptLitePages(
1053 const net::URLRequest& request,
1054 previews::PreviewsDecider* previews_decider) {
1055 DCHECK(thread_checker_.CalledOnValidThread());
1056 DCHECK(base::FeatureList::IsEnabled(
1057 features::kDataReductionProxyDecidesTransform));
1058
1059 if (params::IsBlackListEnabledForServerPreviews()) {
1060 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network
1061 // speed is checked in IsNetworkQualityProhibitivelySlow().
1062 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102
1063 if (!previews_decider->ShouldAllowPreviewAtECT(
1064 request, previews::PreviewsType::LITE_PAGE,
1065 net::EFFECTIVE_CONNECTION_TYPE_4G)) {
1066 return false;
1067 }
1068 } else if (lofi_off_) {
1069 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit
1070 // will be removed when Lo-Fi and Lite Pages are moved over to using the
1071 // PreviewsBlackList.
1072 return false;
1073 }
1074
1075 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags())
1076 return true;
1077
1078 if (params::IsLoFiCellularOnlyViaFlags() &&
1079 params::AreLitePagesEnabledViaFlags()) {
1080 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_);
1081 }
1082
1083 if ((params::IsLoFiSlowConnectionsOnlyViaFlags() &&
1084 params::AreLitePagesEnabledViaFlags()) ||
1085 params::IsIncludedInLitePageFieldTrial()) {
1086 // Accept LitePages from the data reduction proxy (it will handle the
1087 // effective connection type check).
1088 return true;
1089 }
1090
1091 return false;
1092 }
1093
996 bool DataReductionProxyConfig::ShouldEnableLoFiInternal( 1094 bool DataReductionProxyConfig::ShouldEnableLoFiInternal(
997 const net::URLRequest& request, 1095 const net::URLRequest& request,
998 previews::PreviewsDecider* previews_decider) { 1096 previews::PreviewsDecider* previews_decider) {
999 DCHECK(thread_checker_.CalledOnValidThread()); 1097 DCHECK(thread_checker_.CalledOnValidThread());
1098 DCHECK(!base::FeatureList::IsEnabled(
1099 features::kDataReductionProxyDecidesTransform));
1000 1100
1001 last_query_ = GetTicksNow(); 1101 last_query_ = GetTicksNow();
1002 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; 1102 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN;
1003 1103
1004 if (params::IsBlackListEnabledForServerPreviews()) { 1104 if (params::IsBlackListEnabledForServerPreviews()) {
1005 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network 1105 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network
1006 // speed is checked in IsNetworkQualityProhibitivelySlow(). 1106 // speed is checked in IsNetworkQualityProhibitivelySlow().
1007 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102 1107 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102
1008 if (!previews_decider->ShouldAllowPreviewAtECT( 1108 if (!previews_decider->ShouldAllowPreviewAtECT(
1009 request, previews::PreviewsType::LOFI, 1109 request, previews::PreviewsType::LOFI,
(...skipping 25 matching lines...) Expand all
1035 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); 1135 return IsNetworkQualityProhibitivelySlow(network_quality_estimator);
1036 } 1136 }
1037 1137
1038 return false; 1138 return false;
1039 } 1139 }
1040 1140
1041 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal( 1141 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal(
1042 const net::URLRequest& request, 1142 const net::URLRequest& request,
1043 previews::PreviewsDecider* previews_decider) { 1143 previews::PreviewsDecider* previews_decider) {
1044 DCHECK(thread_checker_.CalledOnValidThread()); 1144 DCHECK(thread_checker_.CalledOnValidThread());
1145 DCHECK(!base::FeatureList::IsEnabled(
1146 features::kDataReductionProxyDecidesTransform));
1045 1147
1046 if (params::IsBlackListEnabledForServerPreviews()) { 1148 if (params::IsBlackListEnabledForServerPreviews()) {
1047 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network 1149 // Pass in net::EFFECTIVE_CONNECTION_TYPE_4G as the thresold as network
1048 // speed is checked in IsNetworkQualityProhibitivelySlow(). 1150 // speed is checked in IsNetworkQualityProhibitivelySlow().
1049 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102 1151 // TODO(ryansturm): Use the correct ECT value. crbug.com/720102
1050 if (!previews_decider->ShouldAllowPreviewAtECT( 1152 if (!previews_decider->ShouldAllowPreviewAtECT(
1051 request, previews::PreviewsType::LITE_PAGE, 1153 request, previews::PreviewsType::LITE_PAGE,
1052 net::EFFECTIVE_CONNECTION_TYPE_4G)) { 1154 net::EFFECTIVE_CONNECTION_TYPE_4G)) {
1053 return false; 1155 return false;
1054 } 1156 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 DataReductionProxyConfig::GetProxiesForHttp() const { 1217 DataReductionProxyConfig::GetProxiesForHttp() const {
1116 DCHECK(thread_checker_.CalledOnValidThread()); 1218 DCHECK(thread_checker_.CalledOnValidThread());
1117 1219
1118 if (!enabled_by_user_) 1220 if (!enabled_by_user_)
1119 return std::vector<DataReductionProxyServer>(); 1221 return std::vector<DataReductionProxyServer>();
1120 1222
1121 return config_values_->proxies_for_http(); 1223 return config_values_->proxies_for_http();
1122 } 1224 }
1123 1225
1124 } // namespace data_reduction_proxy 1226 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698