| 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/core/browser/data_reduction_proxy_netw
ork_delegate.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw
ork_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // |lofi_low_header_added| is set to true iff Lo-Fi "q=low" request header can | 31 // |lofi_low_header_added| is set to true iff Lo-Fi "q=low" request header can |
| 32 // be added to the Chrome proxy headers. | 32 // be added to the Chrome proxy headers. |
| 33 // |received_content_length| is the number of prefilter bytes received. | 33 // |received_content_length| is the number of prefilter bytes received. |
| 34 // |original_content_length| is the length of resource if accessed directly | 34 // |original_content_length| is the length of resource if accessed directly |
| 35 // without data saver proxy. | 35 // without data saver proxy. |
| 36 // |freshness_lifetime| contains information on how long the resource will be | 36 // |freshness_lifetime| contains information on how long the resource will be |
| 37 // fresh for and how long is the usability. | 37 // fresh for and how long is the usability. |
| 38 void RecordContentLengthHistograms(bool lofi_low_header_added, | 38 void RecordContentLengthHistograms(bool lofi_low_header_added, |
| 39 int64 received_content_length, | 39 int64_t received_content_length, |
| 40 int64 original_content_length, | 40 int64_t original_content_length, |
| 41 const base::TimeDelta& freshness_lifetime) { | 41 const base::TimeDelta& freshness_lifetime) { |
| 42 // Add the current resource to these histograms only when a valid | 42 // Add the current resource to these histograms only when a valid |
| 43 // X-Original-Content-Length header is present. | 43 // X-Original-Content-Length header is present. |
| 44 if (original_content_length >= 0) { | 44 if (original_content_length >= 0) { |
| 45 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", | 45 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", |
| 46 received_content_length); | 46 received_content_length); |
| 47 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL", | 47 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL", |
| 48 original_content_length); | 48 original_content_length); |
| 49 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL", | 49 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL", |
| 50 original_content_length - received_content_length); | 50 original_content_length - received_content_length); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 void DataReductionProxyNetworkDelegate::OnCompletedInternal( | 196 void DataReductionProxyNetworkDelegate::OnCompletedInternal( |
| 197 net::URLRequest* request, | 197 net::URLRequest* request, |
| 198 bool started) { | 198 bool started) { |
| 199 DCHECK(request); | 199 DCHECK(request); |
| 200 if (data_reduction_proxy_bypass_stats_) | 200 if (data_reduction_proxy_bypass_stats_) |
| 201 data_reduction_proxy_bypass_stats_->OnUrlRequestCompleted(request, started); | 201 data_reduction_proxy_bypass_stats_->OnUrlRequestCompleted(request, started); |
| 202 | 202 |
| 203 // For better accuracy, we use the actual bytes read instead of the length | 203 // For better accuracy, we use the actual bytes read instead of the length |
| 204 // specified with the Content-Length header, which may be inaccurate, | 204 // specified with the Content-Length header, which may be inaccurate, |
| 205 // or missing, as is the case with chunked encoding. | 205 // or missing, as is the case with chunked encoding. |
| 206 int64 received_content_length = request->received_response_content_length(); | 206 int64_t received_content_length = request->received_response_content_length(); |
| 207 if (!request->was_cached() && // Don't record cached content | 207 if (!request->was_cached() && // Don't record cached content |
| 208 received_content_length && // Zero-byte responses aren't useful. | 208 received_content_length && // Zero-byte responses aren't useful. |
| 209 request->response_info().network_accessed && // Network was accessed. | 209 request->response_info().network_accessed && // Network was accessed. |
| 210 request->url().SchemeIsHTTPOrHTTPS()) { | 210 request->url().SchemeIsHTTPOrHTTPS()) { |
| 211 int64 original_content_length = | 211 int64_t original_content_length = |
| 212 request->response_info().headers->GetInt64HeaderValue( | 212 request->response_info().headers->GetInt64HeaderValue( |
| 213 "x-original-content-length"); | 213 "x-original-content-length"); |
| 214 base::TimeDelta freshness_lifetime = | 214 base::TimeDelta freshness_lifetime = |
| 215 request->response_info().headers->GetFreshnessLifetimes( | 215 request->response_info().headers->GetFreshnessLifetimes( |
| 216 request->response_info().response_time).freshness; | 216 request->response_info().response_time).freshness; |
| 217 DataReductionProxyRequestType request_type = | 217 DataReductionProxyRequestType request_type = |
| 218 GetDataReductionProxyRequestType(*request, | 218 GetDataReductionProxyRequestType(*request, |
| 219 configurator_->GetProxyConfig(), | 219 configurator_->GetProxyConfig(), |
| 220 *data_reduction_proxy_config_); | 220 *data_reduction_proxy_config_); |
| 221 | 221 |
| 222 int64 adjusted_original_content_length = | 222 int64_t adjusted_original_content_length = GetAdjustedOriginalContentLength( |
| 223 GetAdjustedOriginalContentLength(request_type, | 223 request_type, original_content_length, received_content_length); |
| 224 original_content_length, | 224 int64_t data_used = request->GetTotalReceivedBytes(); |
| 225 received_content_length); | |
| 226 int64 data_used = request->GetTotalReceivedBytes(); | |
| 227 // TODO(kundaji): Investigate why |compressed_size| can sometimes be | 225 // TODO(kundaji): Investigate why |compressed_size| can sometimes be |
| 228 // less than |received_content_length|. Bug http://crbug/536139. | 226 // less than |received_content_length|. Bug http://crbug/536139. |
| 229 if (data_used < received_content_length) | 227 if (data_used < received_content_length) |
| 230 data_used = received_content_length; | 228 data_used = received_content_length; |
| 231 | 229 |
| 232 int64 original_size = data_used; | 230 int64_t original_size = data_used; |
| 233 if (request_type == VIA_DATA_REDUCTION_PROXY) { | 231 if (request_type == VIA_DATA_REDUCTION_PROXY) { |
| 234 // TODO(kundaji): Remove headers added by data reduction proxy when | 232 // TODO(kundaji): Remove headers added by data reduction proxy when |
| 235 // computing original size. http://crbug/535701. | 233 // computing original size. http://crbug/535701. |
| 236 original_size = request->response_info().headers->raw_headers().size() + | 234 original_size = request->response_info().headers->raw_headers().size() + |
| 237 adjusted_original_content_length; | 235 adjusted_original_content_length; |
| 238 } | 236 } |
| 239 | 237 |
| 240 std::string mime_type; | 238 std::string mime_type; |
| 241 if (request->status().status() == net::URLRequestStatus::SUCCESS) | 239 if (request->status().status() == net::URLRequestStatus::SUCCESS) |
| 242 request->GetMimeType(&mime_type); | 240 request->GetMimeType(&mime_type); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 271 } | 269 } |
| 272 | 270 |
| 273 DVLOG(2) << __FUNCTION__ | 271 DVLOG(2) << __FUNCTION__ |
| 274 << " received content length: " << received_content_length | 272 << " received content length: " << received_content_length |
| 275 << " original content length: " << original_content_length | 273 << " original content length: " << original_content_length |
| 276 << " url: " << request->url(); | 274 << " url: " << request->url(); |
| 277 } | 275 } |
| 278 } | 276 } |
| 279 | 277 |
| 280 void DataReductionProxyNetworkDelegate::AccumulateDataUsage( | 278 void DataReductionProxyNetworkDelegate::AccumulateDataUsage( |
| 281 int64 data_used, | 279 int64_t data_used, |
| 282 int64 original_size, | 280 int64_t original_size, |
| 283 DataReductionProxyRequestType request_type, | 281 DataReductionProxyRequestType request_type, |
| 284 const std::string& data_usage_host, | 282 const std::string& data_usage_host, |
| 285 const std::string& mime_type) { | 283 const std::string& mime_type) { |
| 286 DCHECK_GE(data_used, 0); | 284 DCHECK_GE(data_used, 0); |
| 287 DCHECK_GE(original_size, 0); | 285 DCHECK_GE(original_size, 0); |
| 288 if (data_reduction_proxy_io_data_) { | 286 if (data_reduction_proxy_io_data_) { |
| 289 data_reduction_proxy_io_data_->UpdateContentLengths( | 287 data_reduction_proxy_io_data_->UpdateContentLengths( |
| 290 data_used, original_size, data_reduction_proxy_io_data_->IsEnabled(), | 288 data_used, original_size, data_reduction_proxy_io_data_->IsEnabled(), |
| 291 request_type, data_usage_host, mime_type); | 289 request_type, data_usage_host, mime_type); |
| 292 } | 290 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 311 net::ProxyInfo data_reduction_proxy_info; | 309 net::ProxyInfo data_reduction_proxy_info; |
| 312 data_reduction_proxy_config.proxy_rules().Apply( | 310 data_reduction_proxy_config.proxy_rules().Apply( |
| 313 url, &data_reduction_proxy_info); | 311 url, &data_reduction_proxy_info); |
| 314 data_reduction_proxy_info.DeprioritizeBadProxies(proxy_retry_info); | 312 data_reduction_proxy_info.DeprioritizeBadProxies(proxy_retry_info); |
| 315 if (!data_reduction_proxy_info.proxy_server().is_direct()) | 313 if (!data_reduction_proxy_info.proxy_server().is_direct()) |
| 316 result->OverrideProxyList(data_reduction_proxy_info.proxy_list()); | 314 result->OverrideProxyList(data_reduction_proxy_info.proxy_list()); |
| 317 } | 315 } |
| 318 } | 316 } |
| 319 | 317 |
| 320 } // namespace data_reduction_proxy | 318 } // namespace data_reduction_proxy |
| OLD | NEW |