Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/data_reduction_proxy_usage_sta ts.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 DataReductionProxyUsageStats::DataReductionProxyUsageStats( | 75 DataReductionProxyUsageStats::DataReductionProxyUsageStats( |
| 76 DataReductionProxyParams* params, | 76 DataReductionProxyParams* params, |
| 77 MessageLoopProxy* ui_thread_proxy) | 77 MessageLoopProxy* ui_thread_proxy) |
| 78 : data_reduction_proxy_params_(params), | 78 : data_reduction_proxy_params_(params), |
| 79 last_bypass_type_(BYPASS_EVENT_TYPE_MAX), | 79 last_bypass_type_(BYPASS_EVENT_TYPE_MAX), |
| 80 triggering_request_(true), | 80 triggering_request_(true), |
| 81 ui_thread_proxy_(ui_thread_proxy), | 81 ui_thread_proxy_(ui_thread_proxy), |
| 82 eligible_num_requests_through_proxy_(0), | 82 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.
| |
| 83 actual_num_requests_through_proxy_(0), | 83 num_proxy_net_errors_(0), |
| 84 unavailable_(false) { | 84 unavailable_(false) { |
| 85 NetworkChangeNotifier::AddNetworkChangeObserver(this); | 85 NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 DataReductionProxyUsageStats::~DataReductionProxyUsageStats() { | 88 DataReductionProxyUsageStats::~DataReductionProxyUsageStats() { |
| 89 NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 89 NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 void DataReductionProxyUsageStats::OnUrlRequestCompleted( | 92 void DataReductionProxyUsageStats::OnUrlRequestCompleted( |
| 93 const net::URLRequest* request, bool started) { | 93 const net::URLRequest* request, bool started) { |
| 94 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
| 95 | 95 |
| 96 if (request->status().status() == net::URLRequestStatus::SUCCESS) { | 96 if (request->status().status() == net::URLRequestStatus::SUCCESS && |
| 97 if (data_reduction_proxy_params_->IsDataReductionProxyEligible(request)) { | 97 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.
| |
| 98 bool was_received_via_proxy = | 98 num_successful_requests_through_proxy_++; |
| 99 data_reduction_proxy_params_->WasDataReductionProxyUsed( | 99 |
| 100 request, NULL); | 100 // 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.
| |
| 101 IncrementRequestCounts(was_received_via_proxy); | 101 // 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.
| |
| 102 if (num_proxy_net_errors_ > 0 && | |
| 103 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.
| |
| 104 ClearRequestCounts(); | |
| 105 } else { | |
| 106 MaybeNotifyUnavailability(); | |
| 102 } | 107 } |
| 103 } | 108 } |
| 104 } | 109 } |
| 105 | 110 |
| 106 void DataReductionProxyUsageStats::OnNetworkChanged( | 111 void DataReductionProxyUsageStats::OnNetworkChanged( |
| 107 NetworkChangeNotifier::ConnectionType type) { | 112 NetworkChangeNotifier::ConnectionType type) { |
| 108 DCHECK(thread_checker_.CalledOnValidThread()); | 113 DCHECK(thread_checker_.CalledOnValidThread()); |
| 109 ClearRequestCounts(); | 114 ClearRequestCounts(); |
| 110 } | 115 } |
| 111 | 116 |
| 112 void DataReductionProxyUsageStats::IncrementRequestCounts( | |
| 113 bool was_received_via_proxy) { | |
| 114 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 115 if (was_received_via_proxy) { | |
| 116 actual_num_requests_through_proxy_++; | |
| 117 } | |
| 118 eligible_num_requests_through_proxy_++; | |
| 119 | |
| 120 // To account for the case when the proxy works for a little while and then | |
| 121 // gets blocked, we reset the counts occasionally. | |
| 122 if (eligible_num_requests_through_proxy_ > 50 | |
| 123 && actual_num_requests_through_proxy_ > 0) { | |
| 124 ClearRequestCounts(); | |
| 125 } else { | |
| 126 MaybeNotifyUnavailability(); | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 void DataReductionProxyUsageStats::ClearRequestCounts() { | 117 void DataReductionProxyUsageStats::ClearRequestCounts() { |
| 131 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
| 132 eligible_num_requests_through_proxy_ = 0; | 119 num_successful_requests_through_proxy_ = 0; |
| 133 actual_num_requests_through_proxy_ = 0; | 120 num_proxy_net_errors_ = 0; |
| 134 MaybeNotifyUnavailability(); | 121 MaybeNotifyUnavailability(); |
| 135 } | 122 } |
| 136 | 123 |
| 137 void DataReductionProxyUsageStats::MaybeNotifyUnavailability() { | 124 void DataReductionProxyUsageStats::MaybeNotifyUnavailability() { |
| 138 bool prev_unavailable = unavailable_; | 125 bool prev_unavailable = unavailable_; |
| 139 unavailable_ = (eligible_num_requests_through_proxy_ > 0 && | 126 unavailable_ = (num_proxy_net_errors_ > 0 && |
| 140 actual_num_requests_through_proxy_ == 0); | 127 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.
| |
| 141 if (prev_unavailable != unavailable_) { | 128 if (prev_unavailable != unavailable_) { |
| 142 ui_thread_proxy_->PostTask(FROM_HERE, base::Bind( | 129 ui_thread_proxy_->PostTask(FROM_HERE, base::Bind( |
| 143 &DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread, | 130 &DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread, |
| 144 base::Unretained(this), | 131 base::Unretained(this), |
| 145 unavailable_)); | 132 unavailable_)); |
| 146 } | 133 } |
| 147 } | 134 } |
| 148 | 135 |
| 149 void DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread( | 136 void DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread( |
| 150 bool unavailable) { | 137 bool unavailable) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 } | 215 } |
| 229 | 216 |
| 230 if (data_reduction_proxy_params_-> | 217 if (data_reduction_proxy_params_-> |
| 231 AreDataReductionProxiesBypassed(request, NULL)) { | 218 AreDataReductionProxiesBypassed(request, NULL)) { |
| 232 RecordBypassedBytes(last_bypass_type_, | 219 RecordBypassedBytes(last_bypass_type_, |
| 233 DataReductionProxyUsageStats::NETWORK_ERROR, | 220 DataReductionProxyUsageStats::NETWORK_ERROR, |
| 234 content_length); | 221 content_length); |
| 235 } | 222 } |
| 236 } | 223 } |
| 237 | 224 |
| 238 void DataReductionProxyUsageStats::RecordBypassEventHistograms( | 225 void DataReductionProxyUsageStats::OnProxyFallback( |
| 239 const net::ProxyServer& bypassed_proxy, | 226 const net::ProxyServer& bypassed_proxy, |
| 240 int net_error) const { | 227 int net_error) { |
| 241 DataReductionProxyTypeInfo data_reduction_proxy_info; | 228 DataReductionProxyTypeInfo data_reduction_proxy_info; |
| 242 if (bypassed_proxy.is_valid() && !bypassed_proxy.is_direct() && | 229 if (bypassed_proxy.is_valid() && !bypassed_proxy.is_direct() && |
| 243 data_reduction_proxy_params_->IsDataReductionProxy( | 230 data_reduction_proxy_params_->IsDataReductionProxy( |
| 244 bypassed_proxy.host_port_pair(), &data_reduction_proxy_info)) { | 231 bypassed_proxy.host_port_pair(), &data_reduction_proxy_info)) { |
| 245 if (data_reduction_proxy_info.is_ssl) | 232 if (data_reduction_proxy_info.is_ssl) |
| 246 return; | 233 return; |
| 234 | |
| 235 num_proxy_net_errors_++; | |
| 236 MaybeNotifyUnavailability(); | |
| 237 | |
| 247 if (!data_reduction_proxy_info.is_fallback) { | 238 if (!data_reduction_proxy_info.is_fallback) { |
| 248 RecordDataReductionProxyBypassInfo( | 239 RecordDataReductionProxyBypassInfo( |
| 249 true, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR); | 240 true, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR); |
| 250 RecordDataReductionProxyBypassOnNetworkError( | 241 RecordDataReductionProxyBypassOnNetworkError( |
| 251 true, bypassed_proxy, net_error); | 242 true, bypassed_proxy, net_error); |
| 252 } else { | 243 } else { |
| 253 RecordDataReductionProxyBypassInfo( | 244 RecordDataReductionProxyBypassInfo( |
| 254 false, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR); | 245 false, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR); |
| 255 RecordDataReductionProxyBypassOnNetworkError( | 246 RecordDataReductionProxyBypassOnNetworkError( |
| 256 false, bypassed_proxy, net_error); | 247 false, bypassed_proxy, net_error); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 default: | 360 default: |
| 370 break; | 361 break; |
| 371 } | 362 } |
| 372 break; | 363 break; |
| 373 } | 364 } |
| 374 } | 365 } |
| 375 | 366 |
| 376 } // namespace data_reduction_proxy | 367 } // namespace data_reduction_proxy |
| 377 | 368 |
| 378 | 369 |
| OLD | NEW |