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 <limits> | 7 #include <limits> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 int64_t EstimateOriginalReceivedBytes(const net::URLRequest& request) { | 108 int64_t EstimateOriginalReceivedBytes(const net::URLRequest& request) { |
109 if (request.was_cached() || !request.response_headers()) | 109 if (request.was_cached() || !request.response_headers()) |
110 return request.GetTotalReceivedBytes(); | 110 return request.GetTotalReceivedBytes(); |
111 | 111 |
112 // TODO(sclittle): Remove headers added by Data Reduction Proxy when computing | 112 // TODO(sclittle): Remove headers added by Data Reduction Proxy when computing |
113 // original size. http://crbug/535701. | 113 // original size. http://crbug/535701. |
114 return request.response_headers()->raw_headers().size() + | 114 return request.response_headers()->raw_headers().size() + |
115 util::CalculateEffectiveOCL(request); | 115 util::CalculateEffectiveOCL(request); |
116 } | 116 } |
117 | 117 |
| 118 // Verifies that the chrome proxy related request headers are set correctly. |
| 119 // |via_chrome_proxy| is true if the request is being fetched via Chrome Data |
| 120 // Saver proxy. |
| 121 void VerifyHttpRequestHeaders(bool via_chrome_proxy, |
| 122 const net::HttpRequestHeaders& headers) { |
| 123 if (via_chrome_proxy) { |
| 124 DCHECK(headers.HasHeader(chrome_proxy_header())); |
| 125 DCHECK(headers.HasHeader(chrome_proxy_ect_header())); |
| 126 } else { |
| 127 DCHECK(!headers.HasHeader(chrome_proxy_header())); |
| 128 DCHECK(!headers.HasHeader(chrome_proxy_accept_transform_header())); |
| 129 DCHECK(!headers.HasHeader(chrome_proxy_ect_header())); |
| 130 } |
| 131 } |
| 132 |
118 } // namespace | 133 } // namespace |
119 | 134 |
120 DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate( | 135 DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate( |
121 std::unique_ptr<net::NetworkDelegate> network_delegate, | 136 std::unique_ptr<net::NetworkDelegate> network_delegate, |
122 DataReductionProxyConfig* config, | 137 DataReductionProxyConfig* config, |
123 DataReductionProxyRequestOptions* request_options, | 138 DataReductionProxyRequestOptions* request_options, |
124 const DataReductionProxyConfigurator* configurator) | 139 const DataReductionProxyConfigurator* configurator) |
125 : LayeredNetworkDelegate(std::move(network_delegate)), | 140 : LayeredNetworkDelegate(std::move(network_delegate)), |
126 data_reduction_proxy_config_(config), | 141 data_reduction_proxy_config_(config), |
127 data_reduction_proxy_bypass_stats_(nullptr), | 142 data_reduction_proxy_bypass_stats_(nullptr), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 DataReductionProxyData::ClearData(request); | 228 DataReductionProxyData::ClearData(request); |
214 | 229 |
215 if (params::IsIncludedInHoldbackFieldTrial()) { | 230 if (params::IsIncludedInHoldbackFieldTrial()) { |
216 if (!WasEligibleWithoutHoldback(*request, proxy_info, proxy_retry_info)) | 231 if (!WasEligibleWithoutHoldback(*request, proxy_info, proxy_retry_info)) |
217 return; | 232 return; |
218 // For the holdback field trial, still log UMA as if the proxy was used. | 233 // For the holdback field trial, still log UMA as if the proxy was used. |
219 DataReductionProxyData* data = | 234 DataReductionProxyData* data = |
220 DataReductionProxyData::GetDataAndCreateIfNecessary(request); | 235 DataReductionProxyData::GetDataAndCreateIfNecessary(request); |
221 if (data) | 236 if (data) |
222 data->set_used_data_reduction_proxy(true); | 237 data->set_used_data_reduction_proxy(true); |
| 238 VerifyHttpRequestHeaders(false, *headers); |
223 return; | 239 return; |
224 } | 240 } |
225 | 241 |
226 bool using_data_reduction_proxy = true; | 242 bool using_data_reduction_proxy = true; |
227 // The following checks rule out direct, invalid, and other connection types. | 243 // The following checks rule out direct, invalid, and other connection types. |
228 if (!proxy_info.is_http() && !proxy_info.is_https() && | 244 if (!proxy_info.is_http() && !proxy_info.is_https() && |
229 !proxy_info.is_quic()) { | 245 !proxy_info.is_quic()) { |
230 using_data_reduction_proxy = false; | 246 using_data_reduction_proxy = false; |
231 } else if (proxy_info.proxy_server().host_port_pair().IsEmpty()) { | 247 } else if (proxy_info.proxy_server().host_port_pair().IsEmpty()) { |
232 using_data_reduction_proxy = false; | 248 using_data_reduction_proxy = false; |
233 } else if (!data_reduction_proxy_config_->IsDataReductionProxy( | 249 } else if (!data_reduction_proxy_config_->IsDataReductionProxy( |
234 proxy_info.proxy_server(), nullptr)) { | 250 proxy_info.proxy_server(), nullptr)) { |
235 using_data_reduction_proxy = false; | 251 using_data_reduction_proxy = false; |
236 } | 252 } |
237 | 253 |
238 LoFiDecider* lofi_decider = nullptr; | 254 LoFiDecider* lofi_decider = nullptr; |
239 if (data_reduction_proxy_io_data_) | 255 if (data_reduction_proxy_io_data_) |
240 lofi_decider = data_reduction_proxy_io_data_->lofi_decider(); | 256 lofi_decider = data_reduction_proxy_io_data_->lofi_decider(); |
241 | 257 |
242 if (!using_data_reduction_proxy) { | 258 if (!using_data_reduction_proxy) { |
243 if (lofi_decider) { | 259 if (lofi_decider) { |
244 // If not using the data reduction proxy, strip the | 260 // If not using the data reduction proxy, strip the |
245 // Chrome-Proxy-Accept-Transform header. | 261 // Chrome-Proxy-Accept-Transform header. |
246 lofi_decider->RemoveAcceptTransformHeader(headers); | 262 lofi_decider->RemoveAcceptTransformHeader(headers); |
247 } | 263 } |
248 RemoveChromeProxyECTHeader(headers); | 264 RemoveChromeProxyECTHeader(headers); |
| 265 VerifyHttpRequestHeaders(false, *headers); |
249 return; | 266 return; |
250 } | 267 } |
251 | 268 |
252 // Retrieves DataReductionProxyData from a request, creating a new instance | 269 // Retrieves DataReductionProxyData from a request, creating a new instance |
253 // if needed. | 270 // if needed. |
254 DataReductionProxyData* data = | 271 DataReductionProxyData* data = |
255 DataReductionProxyData::GetDataAndCreateIfNecessary(request); | 272 DataReductionProxyData::GetDataAndCreateIfNecessary(request); |
256 if (data) { | 273 if (data) { |
257 data->set_used_data_reduction_proxy(true); | 274 data->set_used_data_reduction_proxy(true); |
258 data->set_session_key( | 275 data->set_session_key( |
(...skipping 16 matching lines...) Expand all Loading... |
275 | 292 |
276 if (data) { | 293 if (data) { |
277 data->set_lofi_requested( | 294 data->set_lofi_requested( |
278 lofi_decider ? lofi_decider->ShouldRecordLoFiUMA(*request) : false); | 295 lofi_decider ? lofi_decider->ShouldRecordLoFiUMA(*request) : false); |
279 } | 296 } |
280 MaybeAddBrotliToAcceptEncodingHeader(proxy_info, headers, *request); | 297 MaybeAddBrotliToAcceptEncodingHeader(proxy_info, headers, *request); |
281 | 298 |
282 data_reduction_proxy_request_options_->AddRequestHeader(headers); | 299 data_reduction_proxy_request_options_->AddRequestHeader(headers); |
283 if (lofi_decider) | 300 if (lofi_decider) |
284 lofi_decider->MaybeSetIgnorePreviewsBlacklistDirective(headers); | 301 lofi_decider->MaybeSetIgnorePreviewsBlacklistDirective(headers); |
| 302 VerifyHttpRequestHeaders(true, *headers); |
285 } | 303 } |
286 | 304 |
287 void DataReductionProxyNetworkDelegate::OnBeforeRedirectInternal( | 305 void DataReductionProxyNetworkDelegate::OnBeforeRedirectInternal( |
288 net::URLRequest* request, | 306 net::URLRequest* request, |
289 const GURL& new_location) { | 307 const GURL& new_location) { |
290 // Since this is after a redirect response, reset |request|'s | 308 // Since this is after a redirect response, reset |request|'s |
291 // DataReductionProxyData. | 309 // DataReductionProxyData. |
292 DataReductionProxyData::ClearData(request); | 310 DataReductionProxyData::ClearData(request); |
293 } | 311 } |
294 | 312 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 net::HttpRequestHeaders* request_headers, | 525 net::HttpRequestHeaders* request_headers, |
508 const net::URLRequest& request) const { | 526 const net::URLRequest& request) const { |
509 DCHECK(thread_checker_.CalledOnValidThread()); | 527 DCHECK(thread_checker_.CalledOnValidThread()); |
510 | 528 |
511 // This method should be called only when the resolved proxy was a data | 529 // This method should be called only when the resolved proxy was a data |
512 // saver proxy. | 530 // saver proxy. |
513 DCHECK(request.url().is_valid()); | 531 DCHECK(request.url().is_valid()); |
514 DCHECK(!request.url().SchemeIsCryptographic()); | 532 DCHECK(!request.url().SchemeIsCryptographic()); |
515 DCHECK(request.url().SchemeIsHTTPOrHTTPS()); | 533 DCHECK(request.url().SchemeIsHTTPOrHTTPS()); |
516 | 534 |
517 DCHECK(!request_headers->HasHeader(chrome_proxy_ect_header())); | 535 if (request_headers->HasHeader(chrome_proxy_ect_header())) |
| 536 request_headers->RemoveHeader(chrome_proxy_ect_header()); |
518 | 537 |
519 if (request.context()->network_quality_estimator()) { | 538 if (request.context()->network_quality_estimator()) { |
520 net::EffectiveConnectionType type = request.context() | 539 net::EffectiveConnectionType type = request.context() |
521 ->network_quality_estimator() | 540 ->network_quality_estimator() |
522 ->GetEffectiveConnectionType(); | 541 ->GetEffectiveConnectionType(); |
523 if (type > net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) { | 542 if (type > net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) { |
524 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_LAST, type); | 543 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_LAST, type); |
525 request_headers->SetHeader(chrome_proxy_ect_header(), | 544 request_headers->SetHeader(chrome_proxy_ect_header(), |
526 net::GetNameForEffectiveConnectionType(type)); | 545 net::GetNameForEffectiveConnectionType(type)); |
527 return; | 546 return; |
(...skipping 12 matching lines...) Expand all Loading... |
540 } | 559 } |
541 | 560 |
542 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader( | 561 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader( |
543 net::HttpRequestHeaders* request_headers) const { | 562 net::HttpRequestHeaders* request_headers) const { |
544 DCHECK(thread_checker_.CalledOnValidThread()); | 563 DCHECK(thread_checker_.CalledOnValidThread()); |
545 | 564 |
546 request_headers->RemoveHeader(chrome_proxy_ect_header()); | 565 request_headers->RemoveHeader(chrome_proxy_ect_header()); |
547 } | 566 } |
548 | 567 |
549 } // namespace data_reduction_proxy | 568 } // namespace data_reduction_proxy |
OLD | NEW |