| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 RemoveChromeProxyECTHeader(headers); | 290 RemoveChromeProxyECTHeader(headers); |
| 291 VerifyHttpRequestHeaders(false, *headers); | 291 VerifyHttpRequestHeaders(false, *headers); |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 | 294 |
| 295 // Retrieves DataReductionProxyData from a request, creating a new instance | 295 // Retrieves DataReductionProxyData from a request, creating a new instance |
| 296 // if needed. | 296 // if needed. |
| 297 data = DataReductionProxyData::GetDataAndCreateIfNecessary(request); | 297 data = DataReductionProxyData::GetDataAndCreateIfNecessary(request); |
| 298 if (data) { | 298 if (data) { |
| 299 data->set_used_data_reduction_proxy(true); | 299 data->set_used_data_reduction_proxy(true); |
| 300 data->set_session_key( | 300 // Only set GURL, NQE and session key string for main frame requests since |
| 301 data_reduction_proxy_request_options_->GetSecureSession()); | 301 // they are not needed for sub-resources. |
| 302 data->set_request_url(request->url()); | 302 if (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) { |
| 303 if ((request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) && | 303 data->set_session_key( |
| 304 request->context()->network_quality_estimator()) { | 304 data_reduction_proxy_request_options_->GetSecureSession()); |
| 305 data->set_effective_connection_type(request->context() | 305 data->set_request_url(request->url()); |
| 306 ->network_quality_estimator() | 306 if (request->context()->network_quality_estimator()) { |
| 307 ->GetEffectiveConnectionType()); | 307 data->set_effective_connection_type(request->context() |
| 308 ->network_quality_estimator() |
| 309 ->GetEffectiveConnectionType()); |
| 310 } |
| 308 } | 311 } |
| 309 } | 312 } |
| 310 | 313 |
| 311 if (data_reduction_proxy_io_data_ && | 314 if (data_reduction_proxy_io_data_ && |
| 312 (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED)) { | 315 (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED)) { |
| 313 data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame( | 316 data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame( |
| 314 lofi_decider ? lofi_decider->IsSlowPagePreviewRequested(*headers) | 317 lofi_decider ? lofi_decider->IsSlowPagePreviewRequested(*headers) |
| 315 : false); | 318 : false); |
| 316 } | 319 } |
| 317 | 320 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 request->response_headers() | 410 request->response_headers() |
| 408 ? request->response_headers()->GetInt64HeaderValue( | 411 ? request->response_headers()->GetInt64HeaderValue( |
| 409 "x-original-content-length") | 412 "x-original-content-length") |
| 410 : -1; | 413 : -1; |
| 411 | 414 |
| 412 CalculateAndRecordDataUsage(*request, request_type); | 415 CalculateAndRecordDataUsage(*request, request_type); |
| 413 | 416 |
| 414 RecordContentLength(*request, request_type, original_content_length); | 417 RecordContentLength(*request, request_type, original_content_length); |
| 415 } | 418 } |
| 416 | 419 |
| 420 void DataReductionProxyNetworkDelegate::OnHeadersReceivedInternal( |
| 421 net::URLRequest* request, |
| 422 const net::CompletionCallback& callback, |
| 423 const net::HttpResponseHeaders* original_response_headers, |
| 424 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 425 GURL* allowed_unsafe_redirect_url) { |
| 426 if (!original_response_headers) |
| 427 return; |
| 428 if (IsEmptyImagePreview(*original_response_headers)) { |
| 429 DataReductionProxyData* data = |
| 430 DataReductionProxyData::GetDataAndCreateIfNecessary(request); |
| 431 data->set_lofi_received(true); |
| 432 } else if (IsLitePagePreview(*original_response_headers)) { |
| 433 DataReductionProxyData* data = |
| 434 DataReductionProxyData::GetDataAndCreateIfNecessary(request); |
| 435 data->set_lite_page_received(true); |
| 436 } |
| 437 } |
| 438 |
| 417 void DataReductionProxyNetworkDelegate::CalculateAndRecordDataUsage( | 439 void DataReductionProxyNetworkDelegate::CalculateAndRecordDataUsage( |
| 418 const net::URLRequest& request, | 440 const net::URLRequest& request, |
| 419 DataReductionProxyRequestType request_type) { | 441 DataReductionProxyRequestType request_type) { |
| 420 DCHECK(thread_checker_.CalledOnValidThread()); | 442 DCHECK(thread_checker_.CalledOnValidThread()); |
| 421 int64_t data_used = request.GetTotalReceivedBytes(); | 443 int64_t data_used = request.GetTotalReceivedBytes(); |
| 422 | 444 |
| 423 // Estimate how many bytes would have been used if the DataReductionProxy was | 445 // Estimate how many bytes would have been used if the DataReductionProxy was |
| 424 // not used, and record the data usage. | 446 // not used, and record the data usage. |
| 425 int64_t original_size = data_used; | 447 int64_t original_size = data_used; |
| 426 | 448 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 } | 641 } |
| 620 | 642 |
| 621 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader( | 643 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader( |
| 622 net::HttpRequestHeaders* request_headers) const { | 644 net::HttpRequestHeaders* request_headers) const { |
| 623 DCHECK(thread_checker_.CalledOnValidThread()); | 645 DCHECK(thread_checker_.CalledOnValidThread()); |
| 624 | 646 |
| 625 request_headers->RemoveHeader(chrome_proxy_ect_header()); | 647 request_headers->RemoveHeader(chrome_proxy_ect_header()); |
| 626 } | 648 } |
| 627 | 649 |
| 628 } // namespace data_reduction_proxy | 650 } // namespace data_reduction_proxy |
| OLD | NEW |