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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 283 } |
284 VerifyHttpRequestHeaders(false, *headers); | 284 VerifyHttpRequestHeaders(false, *headers); |
285 return; | 285 return; |
286 } | 286 } |
287 | 287 |
288 // Retrieves DataReductionProxyData from a request, creating a new instance | 288 // Retrieves DataReductionProxyData from a request, creating a new instance |
289 // if needed. | 289 // if needed. |
290 data = DataReductionProxyData::GetDataAndCreateIfNecessary(request); | 290 data = DataReductionProxyData::GetDataAndCreateIfNecessary(request); |
291 if (data) { | 291 if (data) { |
292 data->set_used_data_reduction_proxy(true); | 292 data->set_used_data_reduction_proxy(true); |
293 data->set_session_key( | 293 // Only set GURL, NQE and session key string for main frame requests since |
294 data_reduction_proxy_request_options_->GetSecureSession()); | 294 // they are not needed for sub-resources. |
295 data->set_request_url(request->url()); | 295 if (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) { |
296 if ((request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) && | 296 data->set_session_key( |
297 request->context()->network_quality_estimator()) { | 297 data_reduction_proxy_request_options_->GetSecureSession()); |
298 data->set_effective_connection_type(request->context() | 298 data->set_request_url(request->url()); |
299 ->network_quality_estimator() | 299 if (request->context()->network_quality_estimator()) { |
300 ->GetEffectiveConnectionType()); | 300 data->set_effective_connection_type(request->context() |
| 301 ->network_quality_estimator() |
| 302 ->GetEffectiveConnectionType()); |
| 303 } |
301 } | 304 } |
302 } | 305 } |
303 | 306 |
304 if (data_reduction_proxy_io_data_ && | 307 if (data_reduction_proxy_io_data_ && |
305 (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED)) { | 308 (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED)) { |
306 data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame( | 309 data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame( |
307 lofi_decider ? lofi_decider->IsSlowPagePreviewRequested(*headers) | 310 lofi_decider ? lofi_decider->IsSlowPagePreviewRequested(*headers) |
308 : false); | 311 : false); |
309 } | 312 } |
310 | 313 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 request->response_headers() | 403 request->response_headers() |
401 ? request->response_headers()->GetInt64HeaderValue( | 404 ? request->response_headers()->GetInt64HeaderValue( |
402 "x-original-content-length") | 405 "x-original-content-length") |
403 : -1; | 406 : -1; |
404 | 407 |
405 CalculateAndRecordDataUsage(*request, request_type); | 408 CalculateAndRecordDataUsage(*request, request_type); |
406 | 409 |
407 RecordContentLength(*request, request_type, original_content_length); | 410 RecordContentLength(*request, request_type, original_content_length); |
408 } | 411 } |
409 | 412 |
| 413 void DataReductionProxyNetworkDelegate::OnHeadersReceivedInternal( |
| 414 net::URLRequest* request, |
| 415 const net::CompletionCallback& callback, |
| 416 const net::HttpResponseHeaders* original_response_headers, |
| 417 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 418 GURL* allowed_unsafe_redirect_url) { |
| 419 if (!original_response_headers) |
| 420 return; |
| 421 if (IsEmptyImagePreview(*original_response_headers)) { |
| 422 DataReductionProxyData* data = |
| 423 DataReductionProxyData::GetDataAndCreateIfNecessary(request); |
| 424 data->set_lofi_received(true); |
| 425 } else if (IsLitePagePreview(*original_response_headers)) { |
| 426 DataReductionProxyData* data = |
| 427 DataReductionProxyData::GetDataAndCreateIfNecessary(request); |
| 428 data->set_lite_page_received(true); |
| 429 } |
| 430 } |
| 431 |
410 void DataReductionProxyNetworkDelegate::CalculateAndRecordDataUsage( | 432 void DataReductionProxyNetworkDelegate::CalculateAndRecordDataUsage( |
411 const net::URLRequest& request, | 433 const net::URLRequest& request, |
412 DataReductionProxyRequestType request_type) { | 434 DataReductionProxyRequestType request_type) { |
413 DCHECK(thread_checker_.CalledOnValidThread()); | 435 DCHECK(thread_checker_.CalledOnValidThread()); |
414 int64_t data_used = request.GetTotalReceivedBytes(); | 436 int64_t data_used = request.GetTotalReceivedBytes(); |
415 | 437 |
416 // Estimate how many bytes would have been used if the DataReductionProxy was | 438 // Estimate how many bytes would have been used if the DataReductionProxy was |
417 // not used, and record the data usage. | 439 // not used, and record the data usage. |
418 int64_t original_size = data_used; | 440 int64_t original_size = data_used; |
419 | 441 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 590 |
569 request_headers->RemoveHeader(net::HttpRequestHeaders::kAcceptEncoding); | 591 request_headers->RemoveHeader(net::HttpRequestHeaders::kAcceptEncoding); |
570 if (!header_value.empty()) | 592 if (!header_value.empty()) |
571 header_value += ", "; | 593 header_value += ", "; |
572 header_value += kBrotli; | 594 header_value += kBrotli; |
573 request_headers->SetHeader(net::HttpRequestHeaders::kAcceptEncoding, | 595 request_headers->SetHeader(net::HttpRequestHeaders::kAcceptEncoding, |
574 header_value); | 596 header_value); |
575 } | 597 } |
576 | 598 |
577 } // namespace data_reduction_proxy | 599 } // namespace data_reduction_proxy |
OLD | NEW |