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

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

Issue 2825543002: Return chrome-proxy-ect header code (post M59 branch) (Closed)
Patch Set: Update for comment by Ryan Created 3 years, 8 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 <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"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa ss_stats.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_conf ig.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 igurator.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_data .h" 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h"
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h"
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h"
20 #include "components/data_reduction_proxy/core/browser/data_use_group.h" 20 #include "components/data_reduction_proxy/core/browser/data_use_group.h"
21 #include "components/data_reduction_proxy/core/browser/data_use_group_provider.h " 21 #include "components/data_reduction_proxy/core/browser/data_use_group_provider.h "
22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_util. h" 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_util. h"
24 #include "components/data_reduction_proxy/core/common/lofi_decider.h" 25 #include "components/data_reduction_proxy/core/common/lofi_decider.h"
25 #include "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
26 #include "net/base/mime_util.h" 27 #include "net/base/mime_util.h"
27 #include "net/http/http_request_headers.h" 28 #include "net/http/http_request_headers.h"
28 #include "net/http/http_response_headers.h" 29 #include "net/http/http_response_headers.h"
30 #include "net/nqe/effective_connection_type.h"
29 #include "net/nqe/network_quality_estimator.h" 31 #include "net/nqe/network_quality_estimator.h"
30 #include "net/proxy/proxy_info.h" 32 #include "net/proxy/proxy_info.h"
31 #include "net/proxy/proxy_server.h" 33 #include "net/proxy/proxy_server.h"
32 #include "net/proxy/proxy_service.h" 34 #include "net/proxy/proxy_service.h"
33 #include "net/url_request/url_request.h" 35 #include "net/url_request/url_request.h"
34 #include "net/url_request/url_request_context.h" 36 #include "net/url_request/url_request_context.h"
35 #include "net/url_request/url_request_status.h" 37 #include "net/url_request/url_request_status.h"
36 #include "url/gurl.h" 38 #include "url/gurl.h"
37 39
38 namespace data_reduction_proxy { 40 namespace data_reduction_proxy {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 util::CalculateEffectiveOCL(request); 131 util::CalculateEffectiveOCL(request);
130 } 132 }
131 133
132 // Verifies that the chrome proxy related request headers are set correctly. 134 // Verifies that the chrome proxy related request headers are set correctly.
133 // |via_chrome_proxy| is true if the request is being fetched via Chrome Data 135 // |via_chrome_proxy| is true if the request is being fetched via Chrome Data
134 // Saver proxy. 136 // Saver proxy.
135 void VerifyHttpRequestHeaders(bool via_chrome_proxy, 137 void VerifyHttpRequestHeaders(bool via_chrome_proxy,
136 const net::HttpRequestHeaders& headers) { 138 const net::HttpRequestHeaders& headers) {
137 if (via_chrome_proxy) { 139 if (via_chrome_proxy) {
138 DCHECK(headers.HasHeader(chrome_proxy_header())); 140 DCHECK(headers.HasHeader(chrome_proxy_header()));
141 DCHECK(headers.HasHeader(chrome_proxy_ect_header()));
139 } else { 142 } else {
140 DCHECK(!headers.HasHeader(chrome_proxy_header())); 143 DCHECK(!headers.HasHeader(chrome_proxy_header()));
141 DCHECK(!headers.HasHeader(chrome_proxy_accept_transform_header())); 144 DCHECK(!headers.HasHeader(chrome_proxy_accept_transform_header()));
145 DCHECK(!headers.HasHeader(chrome_proxy_ect_header()));
142 } 146 }
143 } 147 }
144 148
145 } // namespace 149 } // namespace
146 150
147 DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate( 151 DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate(
148 std::unique_ptr<net::NetworkDelegate> network_delegate, 152 std::unique_ptr<net::NetworkDelegate> network_delegate,
149 DataReductionProxyConfig* config, 153 DataReductionProxyConfig* config,
150 DataReductionProxyRequestOptions* request_options, 154 DataReductionProxyRequestOptions* request_options,
151 const DataReductionProxyConfigurator* configurator) 155 const DataReductionProxyConfigurator* configurator)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // |request|. 220 // |request|.
217 data_reduction_proxy_io_data_->resource_type_provider()->SetContentType( 221 data_reduction_proxy_io_data_->resource_type_provider()->SetContentType(
218 *request); 222 *request);
219 } 223 }
220 224
221 if (data_reduction_proxy_io_data_->lofi_decider()) { 225 if (data_reduction_proxy_io_data_->lofi_decider()) {
222 data_reduction_proxy_io_data_->lofi_decider() 226 data_reduction_proxy_io_data_->lofi_decider()
223 ->MaybeSetAcceptTransformHeader( 227 ->MaybeSetAcceptTransformHeader(
224 *request, data_reduction_proxy_config_->lofi_off(), headers); 228 *request, data_reduction_proxy_config_->lofi_off(), headers);
225 } 229 }
230
231 MaybeAddChromeProxyECTHeader(headers, *request);
226 } 232 }
227 233
228 void DataReductionProxyNetworkDelegate::OnBeforeSendHeadersInternal( 234 void DataReductionProxyNetworkDelegate::OnBeforeSendHeadersInternal(
229 net::URLRequest* request, 235 net::URLRequest* request,
230 const net::ProxyInfo& proxy_info, 236 const net::ProxyInfo& proxy_info,
231 const net::ProxyRetryInfoMap& proxy_retry_info, 237 const net::ProxyRetryInfoMap& proxy_retry_info,
232 net::HttpRequestHeaders* headers) { 238 net::HttpRequestHeaders* headers) {
233 DCHECK(thread_checker_.CalledOnValidThread()); 239 DCHECK(thread_checker_.CalledOnValidThread());
234 DCHECK(data_reduction_proxy_config_); 240 DCHECK(data_reduction_proxy_config_);
235 DCHECK(request); 241 DCHECK(request);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 LoFiDecider* lofi_decider = nullptr; 280 LoFiDecider* lofi_decider = nullptr;
275 if (data_reduction_proxy_io_data_) 281 if (data_reduction_proxy_io_data_)
276 lofi_decider = data_reduction_proxy_io_data_->lofi_decider(); 282 lofi_decider = data_reduction_proxy_io_data_->lofi_decider();
277 283
278 if (!using_data_reduction_proxy) { 284 if (!using_data_reduction_proxy) {
279 if (lofi_decider) { 285 if (lofi_decider) {
280 // If not using the data reduction proxy, strip the 286 // If not using the data reduction proxy, strip the
281 // Chrome-Proxy-Accept-Transform header. 287 // Chrome-Proxy-Accept-Transform header.
282 lofi_decider->RemoveAcceptTransformHeader(headers); 288 lofi_decider->RemoveAcceptTransformHeader(headers);
283 } 289 }
290 RemoveChromeProxyECTHeader(headers);
284 VerifyHttpRequestHeaders(false, *headers); 291 VerifyHttpRequestHeaders(false, *headers);
285 return; 292 return;
286 } 293 }
287 294
288 // Retrieves DataReductionProxyData from a request, creating a new instance 295 // Retrieves DataReductionProxyData from a request, creating a new instance
289 // if needed. 296 // if needed.
290 data = DataReductionProxyData::GetDataAndCreateIfNecessary(request); 297 data = DataReductionProxyData::GetDataAndCreateIfNecessary(request);
291 if (data) { 298 if (data) {
292 data->set_used_data_reduction_proxy(true); 299 data->set_used_data_reduction_proxy(true);
293 data->set_session_key( 300 data->set_session_key(
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 DCHECK_EQ(std::string::npos, header_value.find(kBrotli)); 574 DCHECK_EQ(std::string::npos, header_value.find(kBrotli));
568 575
569 request_headers->RemoveHeader(net::HttpRequestHeaders::kAcceptEncoding); 576 request_headers->RemoveHeader(net::HttpRequestHeaders::kAcceptEncoding);
570 if (!header_value.empty()) 577 if (!header_value.empty())
571 header_value += ", "; 578 header_value += ", ";
572 header_value += kBrotli; 579 header_value += kBrotli;
573 request_headers->SetHeader(net::HttpRequestHeaders::kAcceptEncoding, 580 request_headers->SetHeader(net::HttpRequestHeaders::kAcceptEncoding,
574 header_value); 581 header_value);
575 } 582 }
576 583
584 void DataReductionProxyNetworkDelegate::MaybeAddChromeProxyECTHeader(
585 net::HttpRequestHeaders* request_headers,
586 const net::URLRequest& request) const {
587 DCHECK(thread_checker_.CalledOnValidThread());
588
589 // This method should be called only when the resolved proxy was a data
590 // saver proxy.
591 DCHECK(request.url().is_valid());
592 DCHECK(!request.url().SchemeIsCryptographic());
593 DCHECK(request.url().SchemeIsHTTPOrHTTPS());
594
595 if (request_headers->HasHeader(chrome_proxy_ect_header()))
596 request_headers->RemoveHeader(chrome_proxy_ect_header());
597
598 if (request.context()->network_quality_estimator()) {
599 net::EffectiveConnectionType type = request.context()
600 ->network_quality_estimator()
601 ->GetEffectiveConnectionType();
602 if (type > net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) {
603 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_LAST, type);
604 request_headers->SetHeader(chrome_proxy_ect_header(),
605 net::GetNameForEffectiveConnectionType(type));
606 return;
607 }
608 }
609 request_headers->SetHeader(chrome_proxy_ect_header(),
610 net::GetNameForEffectiveConnectionType(
611 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN));
612
613 static_assert(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE + 1 ==
614 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
615 "ECT enum value is not handled.");
616 static_assert(net::EFFECTIVE_CONNECTION_TYPE_4G + 1 ==
617 net::EFFECTIVE_CONNECTION_TYPE_LAST,
618 "ECT enum value is not handled.");
619 }
620
621 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader(
622 net::HttpRequestHeaders* request_headers) const {
623 DCHECK(thread_checker_.CalledOnValidThread());
624
625 request_headers->RemoveHeader(chrome_proxy_ect_header());
626 }
627
577 } // namespace data_reduction_proxy 628 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698