Chromium Code Reviews| 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> |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 // Key of the UMA DataReductionProxy.SecureProxyCheck.Latency histogram. | 69 // Key of the UMA DataReductionProxy.SecureProxyCheck.Latency histogram. |
| 70 const char kUMAProxySecureProxyCheckLatency[] = | 70 const char kUMAProxySecureProxyCheckLatency[] = |
| 71 "DataReductionProxy.SecureProxyCheck.Latency"; | 71 "DataReductionProxy.SecureProxyCheck.Latency"; |
| 72 | 72 |
| 73 // Record a network change event. | 73 // Record a network change event. |
| 74 void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) { | 74 void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) { |
| 75 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents", event, | 75 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents", event, |
| 76 CHANGE_EVENT_COUNT); | 76 CHANGE_EVENT_COUNT); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Returns a descriptive name corresponding to |connection_type|. | |
| 80 const char* GetNameForConnectionType( | |
| 81 net::NetworkChangeNotifier::ConnectionType connection_type) { | |
| 82 switch (connection_type) { | |
| 83 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | |
| 84 return "Unknown"; | |
| 85 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | |
| 86 return "Ethernet"; | |
| 87 case net::NetworkChangeNotifier::CONNECTION_WIFI: | |
| 88 return "WiFi"; | |
| 89 case net::NetworkChangeNotifier::CONNECTION_2G: | |
| 90 return "2G"; | |
| 91 case net::NetworkChangeNotifier::CONNECTION_3G: | |
| 92 return "3G"; | |
| 93 case net::NetworkChangeNotifier::CONNECTION_4G: | |
| 94 return "4G"; | |
| 95 case net::NetworkChangeNotifier::CONNECTION_NONE: | |
| 96 return "None"; | |
| 97 case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH: | |
| 98 return "Bluetooth"; | |
| 99 } | |
| 100 NOTREACHED(); | |
| 101 return ""; | |
| 102 } | |
| 103 | |
| 104 // Returns an enumerated histogram that should be used to record the given | |
| 105 // statistic. |max_limit| is the maximum value that can be stored in the | |
| 106 // histogram. Number of buckets in the enumerated histogram are one more than | |
| 107 // |max_limit|. | |
| 108 base::HistogramBase* GetEnumeratedHistogram( | |
| 109 base::StringPiece prefix, | |
| 110 net::NetworkChangeNotifier::ConnectionType type, | |
| 111 int32_t max_limit) { | |
| 112 DCHECK_GT(max_limit, 0); | |
| 113 | |
| 114 base::StringPiece name_for_connection_type(GetNameForConnectionType(type)); | |
| 115 std::string histogram_name; | |
| 116 histogram_name.reserve(prefix.size() + name_for_connection_type.size()); | |
| 117 histogram_name.append(prefix.data(), prefix.size()); | |
| 118 histogram_name.append(name_for_connection_type.data(), | |
| 119 name_for_connection_type.size()); | |
| 120 | |
| 121 return base::Histogram::FactoryGet( | |
| 122 histogram_name, 0, max_limit, max_limit + 1, | |
| 123 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 124 } | |
| 125 | |
| 126 // Following UMA is plotted to measure how frequently Lo-Fi state changes. | |
| 127 // Too frequent changes are undesirable. |connection_type| is the current | |
| 128 // connection type. | |
| 129 void RecordAutoLoFiRequestHeaderStateChange( | |
| 130 net::NetworkChangeNotifier::ConnectionType connection_type, | |
| 131 bool previous_header_low, | |
| 132 bool current_header_low) { | |
| 133 // Auto Lo-Fi request header state changes. | |
| 134 // Possible Lo-Fi header directives are empty ("") and low ("q=low"). | |
| 135 // This enum must remain synchronized with the enum of the same name in | |
| 136 // metrics/histograms/histograms.xml. | |
| 137 enum AutoLoFiRequestHeaderState { | |
| 138 AUTO_LOFI_REQUEST_HEADER_STATE_EMPTY_TO_EMPTY = 0, | |
| 139 AUTO_LOFI_REQUEST_HEADER_STATE_EMPTY_TO_LOW = 1, | |
| 140 AUTO_LOFI_REQUEST_HEADER_STATE_LOW_TO_EMPTY = 2, | |
| 141 AUTO_LOFI_REQUEST_HEADER_STATE_LOW_TO_LOW = 3, | |
| 142 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY | |
| 143 }; | |
| 144 | |
| 145 AutoLoFiRequestHeaderState state; | |
| 146 | |
| 147 if (!previous_header_low) { | |
| 148 if (current_header_low) | |
| 149 state = AUTO_LOFI_REQUEST_HEADER_STATE_EMPTY_TO_LOW; | |
| 150 else | |
| 151 state = AUTO_LOFI_REQUEST_HEADER_STATE_EMPTY_TO_EMPTY; | |
| 152 } else { | |
| 153 if (current_header_low) { | |
| 154 // Low to low in useful in checking how many consecutive page loads | |
| 155 // are done with Lo-Fi enabled. | |
| 156 state = AUTO_LOFI_REQUEST_HEADER_STATE_LOW_TO_LOW; | |
| 157 } else { | |
| 158 state = AUTO_LOFI_REQUEST_HEADER_STATE_LOW_TO_EMPTY; | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 switch (connection_type) { | |
| 163 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | |
| 164 UMA_HISTOGRAM_ENUMERATION( | |
| 165 "DataReductionProxy.AutoLoFiRequestHeaderState.Unknown", state, | |
| 166 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY); | |
| 167 break; | |
| 168 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | |
| 169 UMA_HISTOGRAM_ENUMERATION( | |
| 170 "DataReductionProxy.AutoLoFiRequestHeaderState.Ethernet", state, | |
| 171 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY); | |
| 172 break; | |
| 173 case net::NetworkChangeNotifier::CONNECTION_WIFI: | |
| 174 UMA_HISTOGRAM_ENUMERATION( | |
| 175 "DataReductionProxy.AutoLoFiRequestHeaderState.WiFi", state, | |
| 176 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY); | |
| 177 break; | |
| 178 case net::NetworkChangeNotifier::CONNECTION_2G: | |
| 179 UMA_HISTOGRAM_ENUMERATION( | |
| 180 "DataReductionProxy.AutoLoFiRequestHeaderState.2G", state, | |
| 181 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY); | |
| 182 break; | |
| 183 case net::NetworkChangeNotifier::CONNECTION_3G: | |
| 184 UMA_HISTOGRAM_ENUMERATION( | |
| 185 "DataReductionProxy.AutoLoFiRequestHeaderState.3G", state, | |
| 186 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY); | |
| 187 break; | |
| 188 case net::NetworkChangeNotifier::CONNECTION_4G: | |
| 189 UMA_HISTOGRAM_ENUMERATION( | |
| 190 "DataReductionProxy.AutoLoFiRequestHeaderState.4G", state, | |
| 191 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY); | |
| 192 break; | |
| 193 case net::NetworkChangeNotifier::CONNECTION_NONE: | |
| 194 UMA_HISTOGRAM_ENUMERATION( | |
| 195 "DataReductionProxy.AutoLoFiRequestHeaderState.None", state, | |
| 196 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY); | |
| 197 break; | |
| 198 case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH: | |
| 199 UMA_HISTOGRAM_ENUMERATION( | |
| 200 "DataReductionProxy.AutoLoFiRequestHeaderState.Bluetooth", state, | |
| 201 AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY); | |
| 202 break; | |
| 203 default: | |
| 204 NOTREACHED(); | |
| 205 break; | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 // Records UMA containing the result of requesting the secure proxy check. | 79 // Records UMA containing the result of requesting the secure proxy check. |
| 210 void RecordSecureProxyCheckFetchResult( | 80 void RecordSecureProxyCheckFetchResult( |
| 211 data_reduction_proxy::SecureProxyCheckFetchResult result) { | 81 data_reduction_proxy::SecureProxyCheckFetchResult result) { |
| 212 UMA_HISTOGRAM_ENUMERATION( | 82 UMA_HISTOGRAM_ENUMERATION( |
| 213 kUMAProxyProbeURL, result, | 83 kUMAProxyProbeURL, result, |
| 214 data_reduction_proxy::SECURE_PROXY_CHECK_FETCH_RESULT_COUNT); | 84 data_reduction_proxy::SECURE_PROXY_CHECK_FETCH_RESULT_COUNT); |
| 215 } | 85 } |
| 216 | 86 |
| 217 } // namespace | 87 } // namespace |
| 218 | 88 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 DataReductionProxyConfigurator* configurator, | 205 DataReductionProxyConfigurator* configurator, |
| 336 DataReductionProxyEventCreator* event_creator) | 206 DataReductionProxyEventCreator* event_creator) |
| 337 : secure_proxy_allowed_(true), | 207 : secure_proxy_allowed_(true), |
| 338 unreachable_(false), | 208 unreachable_(false), |
| 339 enabled_by_user_(false), | 209 enabled_by_user_(false), |
| 340 config_values_(std::move(config_values)), | 210 config_values_(std::move(config_values)), |
| 341 io_task_runner_(io_task_runner), | 211 io_task_runner_(io_task_runner), |
| 342 net_log_(net_log), | 212 net_log_(net_log), |
| 343 configurator_(configurator), | 213 configurator_(configurator), |
| 344 event_creator_(event_creator), | 214 event_creator_(event_creator), |
| 345 lofi_effective_connection_type_threshold_( | |
| 346 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | |
| 347 auto_lofi_hysteresis_(base::TimeDelta::Max()), | |
| 348 network_prohibitively_slow_(false), | |
| 349 connection_type_(net::NetworkChangeNotifier::GetConnectionType()), | 215 connection_type_(net::NetworkChangeNotifier::GetConnectionType()), |
| 350 connection_type_changed_(false), | |
| 351 lofi_off_(false), | 216 lofi_off_(false), |
| 352 network_quality_at_last_query_(NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN), | |
| 353 previous_state_lofi_on_(false), | |
| 354 is_captive_portal_(false), | 217 is_captive_portal_(false), |
| 355 weak_factory_(this) { | 218 weak_factory_(this) { |
| 356 DCHECK(io_task_runner_); | 219 DCHECK(io_task_runner_); |
| 357 DCHECK(configurator); | 220 DCHECK(configurator); |
| 358 DCHECK(event_creator); | 221 DCHECK(event_creator); |
| 359 | 222 |
| 360 if (params::IsLoFiDisabledViaFlags()) | 223 if (params::IsLoFiDisabledViaFlags()) |
| 361 SetLoFiModeOff(); | 224 SetLoFiModeOff(); |
| 362 // Constructed on the UI thread, but should be checked on the IO thread. | 225 // Constructed on the UI thread, but should be checked on the IO thread. |
| 363 thread_checker_.DetachFromThread(); | 226 thread_checker_.DetachFromThread(); |
| 364 } | 227 } |
| 365 | 228 |
| 366 DataReductionProxyConfig::~DataReductionProxyConfig() { | 229 DataReductionProxyConfig::~DataReductionProxyConfig() { |
| 367 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 230 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 368 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 231 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 369 } | 232 } |
| 370 | 233 |
| 371 void DataReductionProxyConfig::InitializeOnIOThread( | 234 void DataReductionProxyConfig::InitializeOnIOThread( |
| 372 const scoped_refptr<net::URLRequestContextGetter>& | 235 const scoped_refptr<net::URLRequestContextGetter>& |
| 373 basic_url_request_context_getter, | 236 basic_url_request_context_getter, |
| 374 const scoped_refptr<net::URLRequestContextGetter>& | 237 const scoped_refptr<net::URLRequestContextGetter>& |
| 375 url_request_context_getter) { | 238 url_request_context_getter) { |
| 376 DCHECK(thread_checker_.CalledOnValidThread()); | 239 DCHECK(thread_checker_.CalledOnValidThread()); |
| 377 | 240 |
| 378 secure_proxy_checker_.reset( | 241 secure_proxy_checker_.reset( |
| 379 new SecureProxyChecker(basic_url_request_context_getter)); | 242 new SecureProxyChecker(basic_url_request_context_getter)); |
| 380 warmup_url_fetcher_.reset(new WarmupURLFetcher(url_request_context_getter)); | 243 warmup_url_fetcher_.reset(new WarmupURLFetcher(url_request_context_getter)); |
| 381 | 244 |
| 382 PopulateAutoLoFiParams(); | |
| 383 AddDefaultProxyBypassRules(); | 245 AddDefaultProxyBypassRules(); |
| 384 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 246 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 385 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 247 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 386 | |
| 387 // Record accuracy at 3 different intervals. The values used here must remain | |
| 388 // in sync with the suffixes specified in | |
| 389 // tools/metrics/histograms/histograms.xml. | |
| 390 lofi_accuracy_recording_intervals_.push_back( | |
| 391 base::TimeDelta::FromSeconds(15)); | |
| 392 lofi_accuracy_recording_intervals_.push_back( | |
| 393 base::TimeDelta::FromSeconds(30)); | |
| 394 lofi_accuracy_recording_intervals_.push_back( | |
| 395 base::TimeDelta::FromSeconds(60)); | |
| 396 } | 248 } |
| 397 | 249 |
| 398 void DataReductionProxyConfig::ReloadConfig() { | 250 void DataReductionProxyConfig::ReloadConfig() { |
| 399 DCHECK(thread_checker_.CalledOnValidThread()); | 251 DCHECK(thread_checker_.CalledOnValidThread()); |
| 400 DCHECK(configurator_); | 252 DCHECK(configurator_); |
| 401 | 253 |
| 402 if (enabled_by_user_ && !config_values_->holdback() && | 254 if (enabled_by_user_ && !config_values_->holdback() && |
| 403 !config_values_->proxies_for_http().empty()) { | 255 !config_values_->proxies_for_http().empty()) { |
| 404 configurator_->Enable(!secure_proxy_allowed_ || is_captive_portal_, | 256 configurator_->Enable(!secure_proxy_allowed_ || is_captive_portal_, |
| 405 config_values_->proxies_for_http()); | 257 config_values_->proxies_for_http()); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 bypassed = true; | 375 bypassed = true; |
| 524 } | 376 } |
| 525 } | 377 } |
| 526 | 378 |
| 527 if (min_retry_delay && bypassed) | 379 if (min_retry_delay && bypassed) |
| 528 *min_retry_delay = min_delay; | 380 *min_retry_delay = min_delay; |
| 529 | 381 |
| 530 return bypassed; | 382 return bypassed; |
| 531 } | 383 } |
| 532 | 384 |
| 533 bool DataReductionProxyConfig::IsNetworkQualityProhibitivelySlow( | |
| 534 const net::NetworkQualityEstimator* network_quality_estimator) { | |
| 535 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 536 DCHECK(params::IsIncludedInLoFiEnabledFieldTrial() || | |
| 537 params::IsIncludedInLoFiControlFieldTrial() || | |
| 538 params::IsLoFiSlowConnectionsOnlyViaFlags()); | |
| 539 | |
| 540 if (!network_quality_estimator) | |
| 541 return false; | |
| 542 | |
| 543 const net::EffectiveConnectionType effective_connection_type = | |
| 544 network_quality_estimator->GetEffectiveConnectionType(); | |
| 545 | |
| 546 const bool is_network_quality_available = | |
| 547 effective_connection_type != net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | |
| 548 | |
| 549 // True only if the network is currently estimated to be slower than the | |
| 550 // defined thresholds. | |
| 551 const bool is_network_currently_slow = | |
| 552 is_network_quality_available && | |
| 553 IsEffectiveConnectionTypeSlowerThanThreshold(effective_connection_type); | |
| 554 | |
| 555 if (is_network_quality_available) { | |
| 556 network_quality_at_last_query_ = | |
| 557 is_network_currently_slow ? NETWORK_QUALITY_AT_LAST_QUERY_SLOW | |
| 558 : NETWORK_QUALITY_AT_LAST_QUERY_NOT_SLOW; | |
| 559 | |
| 560 if ((params::IsIncludedInLoFiEnabledFieldTrial() || | |
| 561 params::IsIncludedInLoFiControlFieldTrial()) && | |
| 562 !params::IsLoFiSlowConnectionsOnlyViaFlags()) { | |
| 563 // Post tasks to record accuracy of network quality prediction at | |
| 564 // different intervals. | |
| 565 for (const base::TimeDelta& measuring_delay : | |
| 566 GetLofiAccuracyRecordingIntervals()) { | |
| 567 io_task_runner_->PostDelayedTask( | |
| 568 FROM_HERE, | |
| 569 base::Bind(&DataReductionProxyConfig::RecordAutoLoFiAccuracyRate, | |
| 570 weak_factory_.GetWeakPtr(), network_quality_estimator, | |
| 571 measuring_delay), | |
| 572 measuring_delay); | |
| 573 } | |
| 574 } | |
| 575 } | |
| 576 | |
| 577 // Return the cached entry if the last update was within the hysteresis | |
| 578 // duration and if the connection type has not changed. | |
| 579 if (!connection_type_changed_ && !network_quality_last_checked_.is_null() && | |
| 580 GetTicksNow() - network_quality_last_checked_ <= auto_lofi_hysteresis_) { | |
| 581 return network_prohibitively_slow_; | |
| 582 } | |
| 583 | |
| 584 network_quality_last_checked_ = GetTicksNow(); | |
| 585 connection_type_changed_ = false; | |
| 586 | |
| 587 if (!is_network_quality_available) | |
| 588 return false; | |
| 589 | |
| 590 network_prohibitively_slow_ = is_network_currently_slow; | |
| 591 return network_prohibitively_slow_; | |
| 592 } | |
| 593 | |
| 594 void DataReductionProxyConfig::PopulateAutoLoFiParams() { | |
| 595 std::string field_trial = params::GetLoFiFieldTrialName(); | |
| 596 | |
| 597 // Default parameters to use. | |
| 598 const net::EffectiveConnectionType | |
| 599 default_effective_connection_type_threshold = | |
| 600 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; | |
| 601 const base::TimeDelta default_hysterisis = base::TimeDelta::FromSeconds(60); | |
| 602 | |
| 603 if (params::IsLoFiSlowConnectionsOnlyViaFlags()) { | |
| 604 // Use the default parameters. | |
| 605 lofi_effective_connection_type_threshold_ = | |
| 606 default_effective_connection_type_threshold; | |
| 607 auto_lofi_hysteresis_ = default_hysterisis; | |
| 608 field_trial = params::GetLoFiFlagFieldTrialName(); | |
| 609 } | |
| 610 | |
| 611 if (!params::IsIncludedInLoFiControlFieldTrial() && | |
| 612 !params::IsIncludedInLoFiEnabledFieldTrial() && | |
| 613 !params::IsLoFiSlowConnectionsOnlyViaFlags()) { | |
| 614 return; | |
| 615 } | |
| 616 | |
| 617 std::string variation_value = variations::GetVariationParamValue( | |
| 618 field_trial, "effective_connection_type"); | |
| 619 if (!variation_value.empty()) { | |
| 620 bool effective_connection_type_available = | |
| 621 net::GetEffectiveConnectionTypeForName( | |
| 622 variation_value, &lofi_effective_connection_type_threshold_); | |
| 623 DCHECK(effective_connection_type_available); | |
| 624 | |
| 625 // Silence unused variable warning in release builds. | |
| 626 (void)effective_connection_type_available; | |
| 627 } else { | |
| 628 // Use the default parameters. | |
| 629 lofi_effective_connection_type_threshold_ = | |
| 630 default_effective_connection_type_threshold; | |
| 631 } | |
| 632 | |
| 633 uint32_t auto_lofi_hysteresis_period_seconds; | |
| 634 variation_value = variations::GetVariationParamValue( | |
| 635 field_trial, "hysteresis_period_seconds"); | |
| 636 if (!variation_value.empty() && | |
| 637 base::StringToUint(variation_value, | |
| 638 &auto_lofi_hysteresis_period_seconds)) { | |
| 639 auto_lofi_hysteresis_ = | |
| 640 base::TimeDelta::FromSeconds(auto_lofi_hysteresis_period_seconds); | |
| 641 } else { | |
| 642 // Use the default parameters. | |
| 643 auto_lofi_hysteresis_ = default_hysterisis; | |
| 644 } | |
| 645 DCHECK_GE(auto_lofi_hysteresis_, base::TimeDelta()); | |
| 646 } | |
| 647 | |
| 648 bool DataReductionProxyConfig::IsProxyBypassed( | 385 bool DataReductionProxyConfig::IsProxyBypassed( |
| 649 const net::ProxyRetryInfoMap& retry_map, | 386 const net::ProxyRetryInfoMap& retry_map, |
| 650 const net::ProxyServer& proxy_server, | 387 const net::ProxyServer& proxy_server, |
| 651 base::TimeDelta* retry_delay) const { | 388 base::TimeDelta* retry_delay) const { |
| 652 DCHECK(thread_checker_.CalledOnValidThread()); | 389 DCHECK(thread_checker_.CalledOnValidThread()); |
| 653 net::ProxyRetryInfoMap::const_iterator found = | 390 net::ProxyRetryInfoMap::const_iterator found = |
| 654 retry_map.find(proxy_server.ToURI()); | 391 retry_map.find(proxy_server.ToURI()); |
| 655 | 392 |
| 656 if (found == retry_map.end() || found->second.bad_until < GetTicksNow()) { | 393 if (found == retry_map.end() || found->second.bad_until < GetTicksNow()) { |
| 657 return false; | 394 return false; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 RecordSecureProxyCheckFetchResult(SUCCEEDED_PROXY_ENABLED); | 512 RecordSecureProxyCheckFetchResult(SUCCEEDED_PROXY_ENABLED); |
| 776 } else { | 513 } else { |
| 777 DCHECK(!secure_proxy_allowed_past && !secure_proxy_allowed_); | 514 DCHECK(!secure_proxy_allowed_past && !secure_proxy_allowed_); |
| 778 RecordSecureProxyCheckFetchResult(FAILED_PROXY_ALREADY_DISABLED); | 515 RecordSecureProxyCheckFetchResult(FAILED_PROXY_ALREADY_DISABLED); |
| 779 } | 516 } |
| 780 } | 517 } |
| 781 | 518 |
| 782 void DataReductionProxyConfig::OnConnectionTypeChanged( | 519 void DataReductionProxyConfig::OnConnectionTypeChanged( |
| 783 net::NetworkChangeNotifier::ConnectionType type) { | 520 net::NetworkChangeNotifier::ConnectionType type) { |
| 784 DCHECK(thread_checker_.CalledOnValidThread()); | 521 DCHECK(thread_checker_.CalledOnValidThread()); |
| 785 connection_type_changed_ = true; | |
| 786 connection_type_ = type; | 522 connection_type_ = type; |
| 787 FetchWarmupURL(); | 523 FetchWarmupURL(); |
| 788 } | 524 } |
| 789 | 525 |
| 790 void DataReductionProxyConfig::OnIPAddressChanged() { | 526 void DataReductionProxyConfig::OnIPAddressChanged() { |
| 791 DCHECK(thread_checker_.CalledOnValidThread()); | 527 DCHECK(thread_checker_.CalledOnValidThread()); |
| 792 | 528 |
| 793 if (enabled_by_user_) { | 529 if (enabled_by_user_) { |
| 794 RecordNetworkChangeEvent(IP_CHANGED); | 530 RecordNetworkChangeEvent(IP_CHANGED); |
| 795 | 531 |
| 796 // Reset |network_quality_at_last_query_| to prevent recording of network | |
| 797 // quality prediction accuracy if there was a change in the IP address. | |
| 798 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; | |
| 799 | |
| 800 HandleCaptivePortal(); | 532 HandleCaptivePortal(); |
| 801 // It is safe to use base::Unretained here, since it gets executed | 533 // It is safe to use base::Unretained here, since it gets executed |
| 802 // synchronously on the IO thread, and |this| outlives | 534 // synchronously on the IO thread, and |this| outlives |
| 803 // |secure_proxy_checker_|. | 535 // |secure_proxy_checker_|. |
| 804 SecureProxyCheck( | 536 SecureProxyCheck( |
| 805 config_values_->secure_proxy_check_url(), | 537 config_values_->secure_proxy_check_url(), |
| 806 base::Bind(&DataReductionProxyConfig::HandleSecureProxyCheckResponse, | 538 base::Bind(&DataReductionProxyConfig::HandleSecureProxyCheckResponse, |
| 807 base::Unretained(this))); | 539 base::Unretained(this))); |
| 808 } | 540 } |
| 809 } | 541 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 return; | 590 return; |
| 859 | 591 |
| 860 warmup_url_fetcher_->FetchWarmupURL(); | 592 warmup_url_fetcher_->FetchWarmupURL(); |
| 861 } | 593 } |
| 862 | 594 |
| 863 void DataReductionProxyConfig::SetLoFiModeOff() { | 595 void DataReductionProxyConfig::SetLoFiModeOff() { |
| 864 DCHECK(thread_checker_.CalledOnValidThread()); | 596 DCHECK(thread_checker_.CalledOnValidThread()); |
| 865 lofi_off_ = true; | 597 lofi_off_ = true; |
| 866 } | 598 } |
| 867 | 599 |
| 868 void DataReductionProxyConfig::RecordAutoLoFiAccuracyRate( | 600 // TODO(dougarnett): Remove once using alt-transforms directive. |
| 869 const net::NetworkQualityEstimator* network_quality_estimator, | 601 bool DataReductionProxyConfig::IsNetworkQualityProhibitivelySlow( |
| 870 const base::TimeDelta& measuring_duration) const { | 602 const net::NetworkQualityEstimator* network_quality_estimator) { |
| 871 DCHECK(thread_checker_.CalledOnValidThread()); | 603 DCHECK(thread_checker_.CalledOnValidThread()); |
| 872 DCHECK(network_quality_estimator); | |
| 873 DCHECK((params::IsIncludedInLoFiEnabledFieldTrial() || | |
|
megjablon
2017/04/25 23:10:36
Keep these DCHECKS? Is this cl just a intermediate
dougarnett
2017/04/26 19:50:48
This RecordAutoLoFiAccuracyRate() method is gone n
| |
| 874 params::IsIncludedInLoFiControlFieldTrial()) && | |
| 875 !params::IsLoFiSlowConnectionsOnlyViaFlags()); | |
| 876 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); | |
| 877 DCHECK(base::ContainsValue(GetLofiAccuracyRecordingIntervals(), | |
| 878 measuring_duration)); | |
| 879 | 604 |
| 880 if (network_quality_at_last_query_ == NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN) | 605 if (!network_quality_estimator) |
| 881 return; | 606 return false; |
| 882 | 607 |
| 883 const base::TimeTicks now = GetTicksNow(); | 608 const net::EffectiveConnectionType effective_connection_type = |
| 884 | 609 network_quality_estimator->GetEffectiveConnectionType(); |
| 885 // Return if the time since |last_query_| is less than |measuring_duration|. | |
| 886 // This may happen if another main frame request started during last | |
| 887 // |measuring_duration|. | |
| 888 if (now - last_query_ < measuring_duration) | |
| 889 return; | |
| 890 | |
| 891 // Return if the time since |last_query_| is off by a factor of 2. | |
| 892 if (now - last_query_ > 2 * measuring_duration) | |
| 893 return; | |
| 894 | |
| 895 const net::EffectiveConnectionType recent_effective_connection_type = | |
| 896 network_quality_estimator->GetRecentEffectiveConnectionType(last_query_); | |
| 897 if (recent_effective_connection_type == | |
| 898 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | |
| 899 return; | |
| 900 } | |
| 901 | |
| 902 // Values of Auto Lo-Fi accuracy. | |
| 903 // This enum must remain synchronized with the enum of the same name in | |
| 904 // metrics/histograms/histograms.xml. | |
| 905 enum AutoLoFiAccuracy { | |
| 906 AUTO_LOFI_ACCURACY_ESTIMATED_SLOW_ACTUAL_SLOW = 0, | |
| 907 AUTO_LOFI_ACCURACY_ESTIMATED_SLOW_ACTUAL_NOT_SLOW = 1, | |
| 908 AUTO_LOFI_ACCURACY_ESTIMATED_NOT_SLOW_ACTUAL_SLOW = 2, | |
| 909 AUTO_LOFI_ACCURACY_ESTIMATED_NOT_SLOW_ACTUAL_NOT_SLOW = 3, | |
| 910 AUTO_LOFI_ACCURACY_INDEX_BOUNDARY | |
| 911 }; | |
| 912 | |
| 913 const bool should_have_used_lofi = | |
| 914 IsEffectiveConnectionTypeSlowerThanThreshold( | |
| 915 recent_effective_connection_type); | |
| 916 | |
| 917 AutoLoFiAccuracy accuracy = AUTO_LOFI_ACCURACY_INDEX_BOUNDARY; | |
| 918 | |
| 919 if (should_have_used_lofi) { | |
| 920 if (network_quality_at_last_query_ == NETWORK_QUALITY_AT_LAST_QUERY_SLOW) { | |
| 921 accuracy = AUTO_LOFI_ACCURACY_ESTIMATED_SLOW_ACTUAL_SLOW; | |
| 922 } else if (network_quality_at_last_query_ == | |
| 923 NETWORK_QUALITY_AT_LAST_QUERY_NOT_SLOW) { | |
| 924 accuracy = AUTO_LOFI_ACCURACY_ESTIMATED_NOT_SLOW_ACTUAL_SLOW; | |
| 925 } else { | |
| 926 NOTREACHED(); | |
| 927 } | |
| 928 } else { | |
| 929 if (network_quality_at_last_query_ == NETWORK_QUALITY_AT_LAST_QUERY_SLOW) { | |
| 930 accuracy = AUTO_LOFI_ACCURACY_ESTIMATED_SLOW_ACTUAL_NOT_SLOW; | |
| 931 } else if (network_quality_at_last_query_ == | |
| 932 NETWORK_QUALITY_AT_LAST_QUERY_NOT_SLOW) { | |
| 933 accuracy = AUTO_LOFI_ACCURACY_ESTIMATED_NOT_SLOW_ACTUAL_NOT_SLOW; | |
| 934 } else { | |
| 935 NOTREACHED(); | |
| 936 } | |
| 937 } | |
| 938 | |
| 939 base::HistogramBase* accuracy_histogram = GetEnumeratedHistogram( | |
| 940 base::StringPrintf("DataReductionProxy.LoFi.Accuracy.%d.", | |
| 941 static_cast<int>(measuring_duration.InSeconds())), | |
| 942 connection_type_, AUTO_LOFI_ACCURACY_INDEX_BOUNDARY - 1); | |
| 943 | |
| 944 accuracy_histogram->Add(accuracy); | |
| 945 } | |
| 946 | |
| 947 bool DataReductionProxyConfig::IsEffectiveConnectionTypeSlowerThanThreshold( | |
| 948 net::EffectiveConnectionType effective_connection_type) const { | |
| 949 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && | 610 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && |
| 950 effective_connection_type <= lofi_effective_connection_type_threshold_; | 611 effective_connection_type <= net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; |
| 951 } | 612 } |
| 952 | 613 |
| 953 bool DataReductionProxyConfig::ShouldEnableLoFi( | 614 bool DataReductionProxyConfig::ShouldEnableLoFi( |
| 954 const net::URLRequest& request) { | 615 const net::URLRequest& request) { |
| 955 DCHECK(thread_checker_.CalledOnValidThread()); | 616 DCHECK(thread_checker_.CalledOnValidThread()); |
| 956 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); | 617 DCHECK_NE((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED), 0); |
| 957 DCHECK(!request.url().SchemeIsCryptographic()); | 618 DCHECK(!request.url().SchemeIsCryptographic()); |
| 958 | 619 |
| 959 net::NetworkQualityEstimator* network_quality_estimator; | |
| 960 network_quality_estimator = | |
| 961 request.context() ? request.context()->network_quality_estimator() | |
| 962 : nullptr; | |
| 963 | |
| 964 bool enable_lofi = ShouldEnableLoFiInternal(network_quality_estimator); | |
| 965 | |
| 966 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || | |
| 967 params::IsIncludedInLoFiEnabledFieldTrial()) { | |
| 968 RecordAutoLoFiRequestHeaderStateChange( | |
| 969 connection_type_, previous_state_lofi_on_, enable_lofi); | |
| 970 previous_state_lofi_on_ = enable_lofi; | |
| 971 } | |
| 972 | |
| 973 return enable_lofi; | |
| 974 } | |
| 975 | |
| 976 bool DataReductionProxyConfig::ShouldEnableLitePages( | |
| 977 const net::URLRequest& request) { | |
| 978 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 979 DCHECK((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0); | |
| 980 DCHECK(!request.url().SchemeIsCryptographic()); | |
| 981 | |
| 982 return ShouldEnableLitePagesInternal( | |
| 983 request.context() ? request.context()->network_quality_estimator() | |
| 984 : nullptr); | |
| 985 } | |
| 986 | |
| 987 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const { | |
| 988 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 989 return enabled_by_user_ && !unreachable_; | |
| 990 } | |
| 991 | |
| 992 bool DataReductionProxyConfig::ShouldEnableLoFiInternal( | |
| 993 const net::NetworkQualityEstimator* network_quality_estimator) { | |
| 994 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 995 | |
| 996 last_query_ = GetTicksNow(); | |
| 997 network_quality_at_last_query_ = NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN; | |
| 998 | |
| 999 // If Lo-Fi has been turned off, its status can't change. | 620 // If Lo-Fi has been turned off, its status can't change. |
| 1000 if (lofi_off_) | 621 if (lofi_off_) |
| 1001 return false; | 622 return false; |
| 1002 | 623 |
| 1003 if (params::IsLoFiAlwaysOnViaFlags()) | 624 if (params::IsLoFiAlwaysOnViaFlags()) |
| 1004 return true; | 625 return true; |
| 1005 | 626 |
| 1006 if (params::IsLoFiCellularOnlyViaFlags()) { | 627 if (params::IsLoFiCellularOnlyViaFlags()) { |
| 1007 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); | 628 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); |
| 1008 } | 629 } |
| 1009 | 630 |
| 1010 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || | 631 net::NetworkQualityEstimator* network_quality_estimator = |
| 1011 params::IsIncludedInLoFiEnabledFieldTrial() || | 632 request.context() ? request.context()->network_quality_estimator() |
| 1012 params::IsIncludedInLoFiControlFieldTrial()) { | 633 : nullptr; |
| 634 | |
| 635 // Handle LitePage fallback case for enabling LoFi. | |
| 636 if (ShouldEnableLitePages(request)) { | |
| 637 if (!params::IsLitePageFallbackEnabled()) | |
|
megjablon
2017/04/25 23:10:36
Once we have alt-transform should we even have IsL
dougarnett
2017/04/26 19:50:48
Adding TODO to revisit this topic. I had discussed
| |
| 638 return false; | |
| 639 | |
| 640 // TODO(dougarnett): Remove NQE check once using alt-transforms directive | |
| 1013 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); | 641 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); |
| 1014 } | 642 } |
| 1015 | 643 |
| 644 if (params::IsLoFiSlowConnectionsOnlyViaFlags() || | |
| 645 params::IsIncludedInLoFiEnabledFieldTrial()) { | |
| 646 // TODO(dougarnett): Remove NQE check once using alt-transforms directive | |
| 647 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); | |
| 648 } | |
| 649 | |
| 1016 // If Lo-Fi is not enabled through command line and the user is not in | 650 // If Lo-Fi is not enabled through command line and the user is not in |
| 1017 // Lo-Fi field trials, set Lo-Fi to off. | 651 // Lo-Fi field trials, set Lo-Fi to off. |
| 1018 lofi_off_ = true; | 652 lofi_off_ = true; |
| 1019 return false; | 653 return false; |
| 1020 } | 654 } |
| 1021 | 655 |
| 1022 bool DataReductionProxyConfig::ShouldEnableLitePagesInternal( | 656 bool DataReductionProxyConfig::ShouldEnableLitePages( |
| 1023 const net::NetworkQualityEstimator* network_quality_estimator) { | 657 const net::URLRequest& request) { |
| 1024 DCHECK(thread_checker_.CalledOnValidThread()); | 658 DCHECK(thread_checker_.CalledOnValidThread()); |
| 659 DCHECK_NE((request.load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED), 0); | |
| 660 DCHECK(!request.url().SchemeIsCryptographic()); | |
| 1025 | 661 |
| 1026 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit will | 662 // If Lo-Fi has been turned off, its status can't change. This Lo-Fi bit will |
| 1027 // be removed when Lo-Fi and Lite Pages are moved over to using the Previews | 663 // be removed when Lo-Fi and Lite Pages are moved over to using the Previews |
| 1028 // blacklist. | 664 // blacklist. |
| 1029 if (lofi_off_) | 665 if (lofi_off_) |
| 1030 return false; | 666 return false; |
| 1031 | 667 |
| 1032 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) | 668 if (params::IsLoFiAlwaysOnViaFlags() && params::AreLitePagesEnabledViaFlags()) |
| 1033 return true; | 669 return true; |
| 1034 | 670 |
| 1035 if (params::IsLoFiCellularOnlyViaFlags() && | 671 if (params::IsLoFiCellularOnlyViaFlags() && |
| 1036 params::AreLitePagesEnabledViaFlags()) { | 672 params::AreLitePagesEnabledViaFlags()) { |
| 1037 return net::NetworkChangeNotifier::IsConnectionCellular( | 673 return net::NetworkChangeNotifier::IsConnectionCellular(connection_type_); |
| 1038 net::NetworkChangeNotifier::GetConnectionType()); | |
| 1039 } | 674 } |
| 1040 | 675 |
| 1041 if ((params::IsLoFiSlowConnectionsOnlyViaFlags() && | 676 if ((params::IsLoFiSlowConnectionsOnlyViaFlags() && |
| 1042 params::AreLitePagesEnabledViaFlags()) || | 677 params::AreLitePagesEnabledViaFlags()) || |
| 1043 params::IsIncludedInLitePageFieldTrial() || | 678 params::IsIncludedInLitePageFieldTrial()) { |
| 1044 params::IsIncludedInLoFiControlFieldTrial()) { | 679 return true; |
| 1045 return IsNetworkQualityProhibitivelySlow(network_quality_estimator); | |
| 1046 } | 680 } |
| 1047 | 681 |
| 1048 return false; | 682 return false; |
| 1049 } | 683 } |
| 1050 | 684 |
| 685 bool DataReductionProxyConfig::enabled_by_user_and_reachable() const { | |
| 686 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 687 return enabled_by_user_ && !unreachable_; | |
| 688 } | |
| 689 | |
| 1051 void DataReductionProxyConfig::GetNetworkList( | 690 void DataReductionProxyConfig::GetNetworkList( |
| 1052 net::NetworkInterfaceList* interfaces, | 691 net::NetworkInterfaceList* interfaces, |
| 1053 int policy) { | 692 int policy) { |
| 1054 net::GetNetworkList(interfaces, policy); | 693 net::GetNetworkList(interfaces, policy); |
| 1055 } | 694 } |
| 1056 | 695 |
| 1057 const std::vector<base::TimeDelta>& | |
| 1058 DataReductionProxyConfig::GetLofiAccuracyRecordingIntervals() const { | |
| 1059 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1060 return lofi_accuracy_recording_intervals_; | |
| 1061 } | |
| 1062 | |
| 1063 base::TimeTicks DataReductionProxyConfig::GetTicksNow() const { | 696 base::TimeTicks DataReductionProxyConfig::GetTicksNow() const { |
| 1064 DCHECK(thread_checker_.CalledOnValidThread()); | 697 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1065 return base::TimeTicks::Now(); | 698 return base::TimeTicks::Now(); |
| 1066 } | 699 } |
| 1067 | 700 |
| 1068 net::ProxyConfig DataReductionProxyConfig::ProxyConfigIgnoringHoldback() const { | 701 net::ProxyConfig DataReductionProxyConfig::ProxyConfigIgnoringHoldback() const { |
| 1069 if (!enabled_by_user_ || config_values_->proxies_for_http().empty()) | 702 if (!enabled_by_user_ || config_values_->proxies_for_http().empty()) |
| 1070 return net::ProxyConfig::CreateDirect(); | 703 return net::ProxyConfig::CreateDirect(); |
| 1071 return configurator_->CreateProxyConfig(!secure_proxy_allowed_, | 704 return configurator_->CreateProxyConfig(!secure_proxy_allowed_, |
| 1072 config_values_->proxies_for_http()); | 705 config_values_->proxies_for_http()); |
| 1073 } | 706 } |
| 1074 | 707 |
| 1075 bool DataReductionProxyConfig::secure_proxy_allowed() const { | 708 bool DataReductionProxyConfig::secure_proxy_allowed() const { |
| 1076 DCHECK(thread_checker_.CalledOnValidThread()); | 709 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1077 return secure_proxy_allowed_; | 710 return secure_proxy_allowed_; |
| 1078 } | 711 } |
| 1079 | 712 |
| 1080 std::vector<DataReductionProxyServer> | 713 std::vector<DataReductionProxyServer> |
| 1081 DataReductionProxyConfig::GetProxiesForHttp() const { | 714 DataReductionProxyConfig::GetProxiesForHttp() const { |
| 1082 DCHECK(thread_checker_.CalledOnValidThread()); | 715 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1083 | 716 |
| 1084 if (!enabled_by_user_) | 717 if (!enabled_by_user_) |
| 1085 return std::vector<DataReductionProxyServer>(); | 718 return std::vector<DataReductionProxyServer>(); |
| 1086 | 719 |
| 1087 return config_values_->proxies_for_http(); | 720 return config_values_->proxies_for_http(); |
| 1088 } | 721 } |
| 1089 | 722 |
| 1090 } // namespace data_reduction_proxy | 723 } // namespace data_reduction_proxy |
| OLD | NEW |