Chromium Code Reviews| Index: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc |
| diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc |
| index b24094763c503b3a30ef59cf9ebad7ba84a9127a..5192bd80e8e23c39c05e401d4da67225e1127394 100644 |
| --- a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc |
| +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc |
| @@ -79,8 +79,8 @@ DataReductionProxyUsageStats::DataReductionProxyUsageStats( |
| last_bypass_type_(BYPASS_EVENT_TYPE_MAX), |
| triggering_request_(true), |
| ui_thread_proxy_(ui_thread_proxy), |
| - eligible_num_requests_through_proxy_(0), |
| - actual_num_requests_through_proxy_(0), |
| + num_successful_requests_through_proxy_(0), |
|
bengr
2014/09/16 18:48:57
num_ is implied here and with proxy_net_errors_. I
Not at Google. Contact bengr
2014/09/16 19:34:49
Prefer keeping it since it makes it more obvious.
|
| + num_proxy_net_errors_(0), |
| unavailable_(false) { |
| NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| }; |
| @@ -93,12 +93,17 @@ void DataReductionProxyUsageStats::OnUrlRequestCompleted( |
| const net::URLRequest* request, bool started) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - if (request->status().status() == net::URLRequestStatus::SUCCESS) { |
| - if (data_reduction_proxy_params_->IsDataReductionProxyEligible(request)) { |
| - bool was_received_via_proxy = |
| - data_reduction_proxy_params_->WasDataReductionProxyUsed( |
| - request, NULL); |
| - IncrementRequestCounts(was_received_via_proxy); |
| + if (request->status().status() == net::URLRequestStatus::SUCCESS && |
| + data_reduction_proxy_params_->WasDataReductionProxyUsed(request, NULL)) { |
|
bengr
2014/09/16 18:48:56
Can params be NULL? If so, check here. If not, DCH
Not at Google. Contact bengr
2014/09/16 19:34:48
Added DCHECK in constructor.
|
| + num_successful_requests_through_proxy_++; |
| + |
| + // To account for the case when the proxy does not work for a little while |
|
bengr
2014/09/16 18:48:57
Why would it not work for a little while?
Not at Google. Contact bengr
2014/09/16 19:34:48
Done.
|
| + // and then works fine, we reset the counts occasionally. |
|
bengr
2014/09/16 18:48:56
How often? What triggers the reset?
Not at Google. Contact bengr
2014/09/16 19:34:48
Done.
|
| + if (num_proxy_net_errors_ > 0 && |
| + num_successful_requests_through_proxy_ > 3) { |
|
bengr
2014/09/16 18:48:56
Define these constants in an anonymous namespace a
Not at Google. Contact bengr
2014/09/16 19:34:48
Done.
|
| + ClearRequestCounts(); |
| + } else { |
| + MaybeNotifyUnavailability(); |
| } |
| } |
| } |
| @@ -109,35 +114,17 @@ void DataReductionProxyUsageStats::OnNetworkChanged( |
| ClearRequestCounts(); |
| } |
| -void DataReductionProxyUsageStats::IncrementRequestCounts( |
| - bool was_received_via_proxy) { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - if (was_received_via_proxy) { |
| - actual_num_requests_through_proxy_++; |
| - } |
| - eligible_num_requests_through_proxy_++; |
| - |
| - // To account for the case when the proxy works for a little while and then |
| - // gets blocked, we reset the counts occasionally. |
| - if (eligible_num_requests_through_proxy_ > 50 |
| - && actual_num_requests_through_proxy_ > 0) { |
| - ClearRequestCounts(); |
| - } else { |
| - MaybeNotifyUnavailability(); |
| - } |
| -} |
| - |
| void DataReductionProxyUsageStats::ClearRequestCounts() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - eligible_num_requests_through_proxy_ = 0; |
| - actual_num_requests_through_proxy_ = 0; |
| + num_successful_requests_through_proxy_ = 0; |
| + num_proxy_net_errors_ = 0; |
| MaybeNotifyUnavailability(); |
| } |
| void DataReductionProxyUsageStats::MaybeNotifyUnavailability() { |
| bool prev_unavailable = unavailable_; |
| - unavailable_ = (eligible_num_requests_through_proxy_ > 0 && |
| - actual_num_requests_through_proxy_ == 0); |
| + unavailable_ = (num_proxy_net_errors_ > 0 && |
| + num_successful_requests_through_proxy_ == 0); |
|
bengr
2014/09/16 18:48:56
Define these constants in an anonymous namespace a
Not at Google. Contact bengr
2014/09/16 19:34:49
Done.
|
| if (prev_unavailable != unavailable_) { |
| ui_thread_proxy_->PostTask(FROM_HERE, base::Bind( |
| &DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread, |
| @@ -235,15 +222,19 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms( |
| } |
| } |
| -void DataReductionProxyUsageStats::RecordBypassEventHistograms( |
| +void DataReductionProxyUsageStats::OnProxyFallback( |
| const net::ProxyServer& bypassed_proxy, |
| - int net_error) const { |
| + int net_error) { |
| DataReductionProxyTypeInfo data_reduction_proxy_info; |
| if (bypassed_proxy.is_valid() && !bypassed_proxy.is_direct() && |
| data_reduction_proxy_params_->IsDataReductionProxy( |
| bypassed_proxy.host_port_pair(), &data_reduction_proxy_info)) { |
| if (data_reduction_proxy_info.is_ssl) |
| return; |
| + |
| + num_proxy_net_errors_++; |
| + MaybeNotifyUnavailability(); |
| + |
| if (!data_reduction_proxy_info.is_fallback) { |
| RecordDataReductionProxyBypassInfo( |
| true, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR); |