| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
|
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
|
| index a23f1870c3085010e98d46ebc6e66bc00c14c9ea..9d31047b3a598b1b078f4f1e2f633e5596007782 100644
|
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
|
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
|
| @@ -34,6 +34,8 @@
|
| #include "net/url_request/url_request_status.h"
|
| #include "url/gurl.h"
|
|
|
| +namespace data_reduction_proxy {
|
| +
|
| namespace {
|
|
|
| // |lofi_low_header_added| is set to true iff Lo-Fi "q=low" request header can
|
| @@ -97,77 +99,22 @@ void RecordContentLengthHistograms(bool lofi_low_header_added,
|
| received_content_length);
|
| }
|
|
|
| -// Scales |byte_count| by the ratio of |numerator|:|denomenator|.
|
| -int64_t ScaleByteCountByRatio(int64_t byte_count,
|
| - int64_t numerator,
|
| - int64_t denomenator) {
|
| - DCHECK_LE(0, byte_count);
|
| - DCHECK_LE(0, numerator);
|
| - DCHECK_LT(0, denomenator);
|
| -
|
| - // As an optimization, use integer arithmetic if it won't overflow.
|
| - if (byte_count <= std::numeric_limits<int32_t>::max() &&
|
| - numerator <= std::numeric_limits<int32_t>::max()) {
|
| - return byte_count * numerator / denomenator;
|
| - }
|
| -
|
| - double scaled_byte_count = static_cast<double>(byte_count) *
|
| - static_cast<double>(numerator) /
|
| - static_cast<double>(denomenator);
|
| - if (scaled_byte_count >
|
| - static_cast<double>(std::numeric_limits<int64_t>::max())) {
|
| - // If this ever triggers, then byte counts can no longer be safely stored in
|
| - // 64-bit ints.
|
| - NOTREACHED();
|
| - return byte_count;
|
| - }
|
| - return static_cast<int64_t>(scaled_byte_count);
|
| -}
|
| -
|
| -// Calculates the effective original content length of the |request|, accounting
|
| -// for partial responses if necessary.
|
| -int64_t CalculateEffectiveOCL(const net::URLRequest& request, int net_error) {
|
| - int64_t original_content_length_from_header =
|
| - request.response_headers()->GetInt64HeaderValue(
|
| - "x-original-content-length");
|
| -
|
| - if (original_content_length_from_header < 0)
|
| - return request.received_response_content_length();
|
| - if (net_error == net::OK)
|
| - return original_content_length_from_header;
|
| -
|
| - int64_t content_length_from_header =
|
| - request.response_headers()->GetContentLength();
|
| -
|
| - if (content_length_from_header < 0)
|
| - return request.received_response_content_length();
|
| - if (content_length_from_header == 0)
|
| - return original_content_length_from_header;
|
| -
|
| - return ScaleByteCountByRatio(request.received_response_content_length(),
|
| - original_content_length_from_header,
|
| - content_length_from_header);
|
| -}
|
| -
|
| // Given a |request| that went through the Data Reduction Proxy, this function
|
| // estimates how many bytes would have been received if the response had been
|
| // received directly from the origin using HTTP/1.1 with a content length of
|
| // |adjusted_original_content_length|.
|
| -int64_t EstimateOriginalReceivedBytes(const net::URLRequest& request,
|
| - int net_error) {
|
| +int64_t EstimateOriginalReceivedBytes(const net::URLRequest& request) {
|
| if (request.was_cached() || !request.response_headers())
|
| return request.GetTotalReceivedBytes();
|
|
|
| // TODO(sclittle): Remove headers added by Data Reduction Proxy when computing
|
| // original size. http://crbug/535701.
|
| return request.response_headers()->raw_headers().size() +
|
| - CalculateEffectiveOCL(request, net_error);
|
| + util::CalculateEffectiveOCL(request);
|
| }
|
|
|
| } // namespace
|
|
|
| -namespace data_reduction_proxy {
|
| -
|
| DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate(
|
| std::unique_ptr<net::NetworkDelegate> network_delegate,
|
| DataReductionProxyConfig* config,
|
| @@ -361,19 +308,15 @@ void DataReductionProxyNetworkDelegate::OnCompletedInternal(
|
| "x-original-content-length")
|
| : -1;
|
|
|
| - CalculateAndRecordDataUsage(*request, request_type, original_content_length,
|
| - net_error);
|
| + CalculateAndRecordDataUsage(*request, request_type);
|
|
|
| RecordContentLength(*request, request_type, original_content_length);
|
| }
|
|
|
| void DataReductionProxyNetworkDelegate::CalculateAndRecordDataUsage(
|
| const net::URLRequest& request,
|
| - DataReductionProxyRequestType request_type,
|
| - int64_t original_content_length,
|
| - int net_error) {
|
| + DataReductionProxyRequestType request_type) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - DCHECK_LE(-1, original_content_length);
|
| int64_t data_used = request.GetTotalReceivedBytes();
|
|
|
| // Estimate how many bytes would have been used if the DataReductionProxy was
|
| @@ -381,7 +324,7 @@ void DataReductionProxyNetworkDelegate::CalculateAndRecordDataUsage(
|
| int64_t original_size = data_used;
|
|
|
| if (request_type == VIA_DATA_REDUCTION_PROXY)
|
| - original_size = EstimateOriginalReceivedBytes(request, net_error);
|
| + original_size = EstimateOriginalReceivedBytes(request);
|
|
|
| std::string mime_type;
|
| if (request.response_headers())
|
|
|