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

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

Issue 2642793005: Create a Lite Page bit for previews and fallback to Lo-Fi (Closed)
Patch Set: Created 3 years, 10 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>
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 951
952 accuracy_histogram->Add(accuracy); 952 accuracy_histogram->Add(accuracy);
953 } 953 }
954 954
955 bool DataReductionProxyConfig::IsEffectiveConnectionTypeSlowerThanThreshold( 955 bool DataReductionProxyConfig::IsEffectiveConnectionTypeSlowerThanThreshold(
956 net::EffectiveConnectionType effective_connection_type) const { 956 net::EffectiveConnectionType effective_connection_type) const {
957 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && 957 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE &&
958 effective_connection_type <= lofi_effective_connection_type_threshold_; 958 effective_connection_type <= lofi_effective_connection_type_threshold_;
959 } 959 }
960 960
961 bool DataReductionProxyConfig::ShouldEnableLoFiMode( 961 bool DataReductionProxyConfig::ShouldEnableLoFi(
962 const net::URLRequest& request) { 962 const net::URLRequest& request) {
963 DCHECK(thread_checker_.CalledOnValidThread()); 963 DCHECK(thread_checker_.CalledOnValidThread());
964 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); 964 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0);
965 DCHECK(!request.url().SchemeIsCryptographic()); 965 DCHECK(!request.url().SchemeIsCryptographic());
966 966
967 net::NetworkQualityEstimator* network_quality_estimator; 967 net::NetworkQualityEstimator* network_quality_estimator;
968 network_quality_estimator = 968 network_quality_estimator =
969 request.context() ? request.context()->network_quality_estimator() 969 request.context() ? request.context()->network_quality_estimator()
970 : nullptr; 970 : nullptr;
971 971
972 bool enable_lofi = ShouldEnableLoFiModeInternal(network_quality_estimator); 972 bool enable_lofi = ShouldEnableLoFiInternal(network_quality_estimator);
973 973
974 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || 974 if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
975 params::IsIncludedInLoFiEnabledFieldTrial()) { 975 params::IsIncludedInLoFiEnabledFieldTrial()) {
976 RecordAutoLoFiRequestHeaderStateChange(previous_state_lofi_on_, 976 RecordAutoLoFiRequestHeaderStateChange(previous_state_lofi_on_,
977 enable_lofi); 977 enable_lofi);
978 previous_state_lofi_on_ = enable_lofi; 978 previous_state_lofi_on_ = enable_lofi;
979 } 979 }
980 980
981 return enable_lofi; 981 return enable_lofi;
982 } 982 }
983 983
984 bool DataReductionProxyConfig::ShouldEnableLitePages(
985 const net::URLRequest& request) {
986 DCHECK(thread_checker_.CalledOnValidThread());
987 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0);
988 DCHECK(!request.url().SchemeIsCryptographic());
989
990 net::NetworkQualityEstimator* network_quality_estimator;
991 network_quality_estimator =
992 request.context() ? request.context()->network_quality_estimator()
993 : nullptr;
994
995 return ShouldEnableLitePagesInternal(network_quality_estimator);
bengr 2017/02/15 00:03:47 You could get rid of the temporary: return ShouldE
megjablon 2017/02/16 04:29:09 Done.
996 }
997
984 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const { 998 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const {
985 DCHECK(thread_checker_.CalledOnValidThread()); 999 DCHECK(thread_checker_.CalledOnValidThread());
986 return enabled_by_user_ && !unreachable_; 1000 return enabled_by_user_ && !unreachable_;
987 } 1001 }
988 1002
989 bool DataReductionProxyConfig::ShouldEnableLoFiModeInternal( 1003 bool DataReductionProxyConfig::ShouldEnableLoFiInternal(
990 const net::NetworkQualityEstimator* network_quality_estimator) { 1004 const net::NetworkQualityEstimator* network_quality_estimator) {
991 DCHECK(thread_checker_.CalledOnValidThread()); 1005 DCHECK(thread_checker_.CalledOnValidThread());
992 1006
993 last_query_ = GetTicksNow(); 1007 last_query_ = GetTicksNow();
994 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; 1008 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN;
995 1009
996 // If Lo-Fi has been turned off, its status can't change. 1010 // If Lo-Fi has been turned off, its status can't change.
997 if (lofi_off_) 1011 if (lofi_off_)
998 return false; 1012 return false;
999 1013
(...skipping 10 matching lines...) Expand all
1010 params::IsIncludedInLoFiControlFieldTrial()) { 1024 params::IsIncludedInLoFiControlFieldTrial()) {
1011 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); 1025 return IsNetworkQualityProhibitivelySlow(network_quality_estimator);
1012 } 1026 }
1013 1027
1014 // If Lo-Fi is not enabled through command line and the user is not in 1028 // If Lo-Fi is not enabled through command line and the user is not in
1015 // Lo-Fi field trials, set Lo-Fi to off. 1029 // Lo-Fi field trials, set Lo-Fi to off.
1016 lofi_off_ = true; 1030 lofi_off_ = true;
1017 return false; 1031 return false;
1018 } 1032 }
1019 1033
1034 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal(
1035 const net::NetworkQualityEstimator* network_quality_estimator) {
1036 DCHECK(thread_checker_.CalledOnValidThread());
1037
1038 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit will
1039 // be removed when Lo-Fi and Lite Pages are moved over to using the Previews
1040 // blacklist.
1041 if (lofi_off_)
1042 return false;
1043
1044 // TODO: Move the Lo-Fi flag to a flag supporting all Previews types.
bengr 2017/02/15 00:03:47 TODO(megjablon):
megjablon 2017/02/16 04:29:09 Removing since we should discuss how we want the h
1045 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags())
1046 return true;
1047
1048 if (params::IsLoFiCellularOnlyViaFlags() &&
1049 params::AreLitePagesEnabledViaFlags()) {
1050 return net::NetworkChangeNotifier::IsConnectionCellular(
1051 net::NetworkChangeNotifier::GetConnectionType());
1052 }
1053
1054 if ((params::IsLoFiSlowConnectionsOnlyViaFlags() &&
1055 params::AreLitePagesEnabledViaFlags()) ||
1056 params::IsIncludedInLitePageFieldTrial() ||
1057 params::IsIncludedInLoFiControlFieldTrial()) {
1058 return IsNetworkQualityProhibitivelySlow(network_quality_estimator);
1059 }
1060
1061 return false;
1062 }
1063
1020 void DataReductionProxyConfig::GetNetworkList( 1064 void DataReductionProxyConfig::GetNetworkList(
1021 net::NetworkInterfaceList* interfaces, 1065 net::NetworkInterfaceList* interfaces,
1022 int policy) { 1066 int policy) {
1023 net::GetNetworkList(interfaces, policy); 1067 net::GetNetworkList(interfaces, policy);
1024 } 1068 }
1025 1069
1026 const std::vector<base::TimeDelta>& 1070 const std::vector<base::TimeDelta>&
1027 DataReductionProxyConfig::GetLofiAccuracyRecordingIntervals() const { 1071 DataReductionProxyConfig::GetLofiAccuracyRecordingIntervals() const {
1028 DCHECK(thread_checker_.CalledOnValidThread()); 1072 DCHECK(thread_checker_.CalledOnValidThread());
1029 return lofi_accuracy_recording_intervals_; 1073 return lofi_accuracy_recording_intervals_;
1030 } 1074 }
1031 1075
1032 base::TimeTicks DataReductionProxyConfig::GetTicksNow() const { 1076 base::TimeTicks DataReductionProxyConfig::GetTicksNow() const {
1033 DCHECK(thread_checker_.CalledOnValidThread()); 1077 DCHECK(thread_checker_.CalledOnValidThread());
1034 return base::TimeTicks::Now(); 1078 return base::TimeTicks::Now();
1035 } 1079 }
1036 1080
1037 net::ProxyConfig DataReductionProxyConfig::ProxyConfigIgnoringHoldback() const { 1081 net::ProxyConfig DataReductionProxyConfig::ProxyConfigIgnoringHoldback() const {
1038 std::vector<net::ProxyServer> proxies_for_http = 1082 std::vector<net::ProxyServer> proxies_for_http =
1039 DataReductionProxyServer::ConvertToNetProxyServers( 1083 DataReductionProxyServer::ConvertToNetProxyServers(
1040 config_values_->proxies_for_http()); 1084 config_values_->proxies_for_http());
1041 if (!enabled_by_user_ || proxies_for_http.empty()) 1085 if (!enabled_by_user_ || proxies_for_http.empty())
1042 return net::ProxyConfig::CreateDirect(); 1086 return net::ProxyConfig::CreateDirect();
1043 return configurator_->CreateProxyConfig(!secure_proxy_allowed_, 1087 return configurator_->CreateProxyConfig(!secure_proxy_allowed_,
1044 proxies_for_http); 1088 proxies_for_http);
1045 } 1089 }
1046 1090
1047 } // namespace data_reduction_proxy 1091 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698