Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(671)

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc

Issue 2873793002: Record Data Savings for Client-Side LoFi (Closed)
Patch Set: Rebased on master Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm>
7 #include <limits> 8 #include <limits>
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa ss_stats.h" 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa ss_stats.h"
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h" 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h"
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator.h" 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return; 111 return;
111 UMA_HISTOGRAM_COUNTS_1M("Net.HttpContentLengthCacheable4Hours", 112 UMA_HISTOGRAM_COUNTS_1M("Net.HttpContentLengthCacheable4Hours",
112 received_content_length); 113 received_content_length);
113 114
114 if (freshness_lifetime.InHours() < 24) 115 if (freshness_lifetime.InHours() < 24)
115 return; 116 return;
116 UMA_HISTOGRAM_COUNTS_1M("Net.HttpContentLengthCacheable24Hours", 117 UMA_HISTOGRAM_COUNTS_1M("Net.HttpContentLengthCacheable24Hours",
117 received_content_length); 118 received_content_length);
118 } 119 }
119 120
120 // Given a |request| that went through the Data Reduction Proxy, this function 121 // Estimate the size of the original headers of |request|. If |used_drp| is
121 // estimates how many bytes would have been received if the response had been 122 // true, then it's assumed that the original request would have used HTTP/1.1,
122 // received directly from the origin using HTTP/1.1 with a content length of 123 // otherwise it assumes that the original request would have used the same
123 // |adjusted_original_content_length|. 124 // protocol as |request| did. This is to account for stuff like HTTP/2 header
124 int64_t EstimateOriginalReceivedBytes(const net::URLRequest& request) { 125 // compression.
126 int64_t EstimateOriginalHeaderBytes(const net::URLRequest& request,
127 bool used_drp) {
128 if (used_drp) {
129 // TODO(sclittle): Remove headers added by Data Reduction Proxy when
130 // computing original size. https://crbug.com/535701.
131 return request.response_headers()->raw_headers().size();
132 }
133 return std::max<int64_t>(0, request.GetTotalReceivedBytes() -
RyanSturm 2017/05/10 18:14:08 As a note, I don't believe GetTotalReceivedBytes c
sclittle 2017/05/10 19:56:36 From looking at URLRequest::GetTotalReceivedBytes(
134 request.received_response_content_length());
135 }
136
137 // Given a |request| that went through the Data Reduction Proxy if |used_drp| is
138 // true, this function estimates how many bytes would have been received if the
139 // response had been received directly from the origin without any data saver
140 // optimizations.
141 int64_t EstimateOriginalReceivedBytes(const net::URLRequest& request,
142 bool used_drp,
143 const LoFiDecider* lofi_decider) {
125 if (request.was_cached() || !request.response_headers()) 144 if (request.was_cached() || !request.response_headers())
126 return request.GetTotalReceivedBytes(); 145 return request.GetTotalReceivedBytes();
127 146
128 // TODO(sclittle): Remove headers added by Data Reduction Proxy when computing 147 if (lofi_decider) {
129 // original size. http://crbug/535701. 148 if (lofi_decider->IsClientLoFiAutoReloadRequest(request))
130 return request.response_headers()->raw_headers().size() + 149 return 0;
131 util::CalculateEffectiveOCL(request); 150
151 int64_t first, last, length;
152 if (lofi_decider->IsClientLoFiImageRequest(request) &&
153 request.response_headers()->GetContentRangeFor206(&first, &last,
154 &length) &&
155 length > request.received_response_content_length()) {
156 return EstimateOriginalHeaderBytes(request, used_drp) + length;
157 }
158 }
159
160 return used_drp ? EstimateOriginalHeaderBytes(request, used_drp) +
161 util::CalculateEffectiveOCL(request)
162 : request.GetTotalReceivedBytes();
132 } 163 }
133 164
134 // Verifies that the chrome proxy related request headers are set correctly. 165 // Verifies that the chrome proxy related request headers are set correctly.
135 // |via_chrome_proxy| is true if the request is being fetched via Chrome Data 166 // |via_chrome_proxy| is true if the request is being fetched via Chrome Data
136 // Saver proxy. 167 // Saver proxy.
137 void VerifyHttpRequestHeaders(bool via_chrome_proxy, 168 void VerifyHttpRequestHeaders(bool via_chrome_proxy,
138 const net::HttpRequestHeaders& headers) { 169 const net::HttpRequestHeaders& headers) {
139 if (via_chrome_proxy) { 170 if (via_chrome_proxy) {
140 DCHECK(headers.HasHeader(chrome_proxy_header())); 171 DCHECK(headers.HasHeader(chrome_proxy_header()));
141 DCHECK(headers.HasHeader(chrome_proxy_ect_header())); 172 DCHECK(headers.HasHeader(chrome_proxy_ect_header()));
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 475 }
445 476
446 void DataReductionProxyNetworkDelegate::CalculateAndRecordDataUsage( 477 void DataReductionProxyNetworkDelegate::CalculateAndRecordDataUsage(
447 const net::URLRequest& request, 478 const net::URLRequest& request,
448 DataReductionProxyRequestType request_type) { 479 DataReductionProxyRequestType request_type) {
449 DCHECK(thread_checker_.CalledOnValidThread()); 480 DCHECK(thread_checker_.CalledOnValidThread());
450 int64_t data_used = request.GetTotalReceivedBytes(); 481 int64_t data_used = request.GetTotalReceivedBytes();
451 482
452 // Estimate how many bytes would have been used if the DataReductionProxy was 483 // Estimate how many bytes would have been used if the DataReductionProxy was
453 // not used, and record the data usage. 484 // not used, and record the data usage.
454 int64_t original_size = data_used; 485 int64_t original_size = EstimateOriginalReceivedBytes(
455 486 request, request_type == VIA_DATA_REDUCTION_PROXY,
456 if (request_type == VIA_DATA_REDUCTION_PROXY) 487 data_reduction_proxy_io_data_
457 original_size = EstimateOriginalReceivedBytes(request); 488 ? data_reduction_proxy_io_data_->lofi_decider()
489 : nullptr);
458 490
459 std::string mime_type; 491 std::string mime_type;
460 if (request.response_headers()) 492 if (request.response_headers())
461 request.response_headers()->GetMimeType(&mime_type); 493 request.response_headers()->GetMimeType(&mime_type);
462 494
463 scoped_refptr<DataUseGroup> data_use_group = 495 scoped_refptr<DataUseGroup> data_use_group =
464 data_use_group_provider_ 496 data_use_group_provider_
465 ? data_use_group_provider_->GetDataUseGroup(&request) 497 ? data_use_group_provider_->GetDataUseGroup(&request)
466 : nullptr; 498 : nullptr;
467 AccumulateDataUsage(data_used, original_size, request_type, data_use_group, 499 AccumulateDataUsage(data_used, original_size, request_type, data_use_group,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 } 680 }
649 681
650 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader( 682 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader(
651 net::HttpRequestHeaders* request_headers) const { 683 net::HttpRequestHeaders* request_headers) const {
652 DCHECK(thread_checker_.CalledOnValidThread()); 684 DCHECK(thread_checker_.CalledOnValidThread());
653 685
654 request_headers->RemoveHeader(chrome_proxy_ect_header()); 686 request_headers->RemoveHeader(chrome_proxy_ect_header());
655 } 687 }
656 688
657 } // namespace data_reduction_proxy 689 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698