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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_stats.h" | 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_stats.h" |
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" | 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" |
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" | 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" |
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" | 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" |
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" |
20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ
est_options.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ
est_options.h" |
21 #include "components/data_reduction_proxy/core/browser/data_use_group.h" | 22 #include "components/data_reduction_proxy/core/browser/data_use_group.h" |
22 #include "components/data_reduction_proxy/core/browser/data_use_group_provider.h
" | 23 #include "components/data_reduction_proxy/core/browser/data_use_group_provider.h
" |
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 util::CalculateEffectiveOCL(request) | 162 util::CalculateEffectiveOCL(request) |
162 : request.GetTotalReceivedBytes(); | 163 : request.GetTotalReceivedBytes(); |
163 } | 164 } |
164 | 165 |
165 // Verifies that the chrome proxy related request headers are set correctly. | 166 // Verifies that the chrome proxy related request headers are set correctly. |
166 // |via_chrome_proxy| is true if the request is being fetched via Chrome Data | 167 // |via_chrome_proxy| is true if the request is being fetched via Chrome Data |
167 // Saver proxy. | 168 // Saver proxy. |
168 void VerifyHttpRequestHeaders(bool via_chrome_proxy, | 169 void VerifyHttpRequestHeaders(bool via_chrome_proxy, |
169 const net::HttpRequestHeaders& headers) { | 170 const net::HttpRequestHeaders& headers) { |
170 if (via_chrome_proxy) { | 171 if (via_chrome_proxy) { |
171 DCHECK(headers.HasHeader(chrome_proxy_header())); | |
172 DCHECK(headers.HasHeader(chrome_proxy_ect_header())); | 172 DCHECK(headers.HasHeader(chrome_proxy_ect_header())); |
| 173 std::string chrome_proxy_header_value; |
| 174 DCHECK( |
| 175 headers.GetHeader(chrome_proxy_header(), &chrome_proxy_header_value)); |
| 176 // Check that only 1 "exp" directive is sent. |
| 177 DCHECK_GT(3u, base::SplitStringUsingSubstr(chrome_proxy_header_value, |
| 178 "exp=", base::TRIM_WHITESPACE, |
| 179 base::SPLIT_WANT_ALL) |
| 180 .size()); |
| 181 // Silence unused variable warning in release builds. |
| 182 (void)chrome_proxy_header_value; |
173 } else { | 183 } else { |
174 DCHECK(!headers.HasHeader(chrome_proxy_header())); | 184 DCHECK(!headers.HasHeader(chrome_proxy_header())); |
175 DCHECK(!headers.HasHeader(chrome_proxy_accept_transform_header())); | 185 DCHECK(!headers.HasHeader(chrome_proxy_accept_transform_header())); |
176 DCHECK(!headers.HasHeader(chrome_proxy_ect_header())); | 186 DCHECK(!headers.HasHeader(chrome_proxy_ect_header())); |
177 } | 187 } |
178 } | 188 } |
179 | 189 |
180 } // namespace | 190 } // namespace |
181 | 191 |
182 DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate( | 192 DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate( |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // crbug.com/709621 | 373 // crbug.com/709621 |
364 if (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) { | 374 if (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) { |
365 if (!page_id) { | 375 if (!page_id) { |
366 page_id = data_reduction_proxy_request_options_->GeneratePageId(); | 376 page_id = data_reduction_proxy_request_options_->GeneratePageId(); |
367 } | 377 } |
368 data->set_page_id(page_id.value()); | 378 data->set_page_id(page_id.value()); |
369 } | 379 } |
370 | 380 |
371 data_reduction_proxy_request_options_->AddRequestHeader(headers, page_id); | 381 data_reduction_proxy_request_options_->AddRequestHeader(headers, page_id); |
372 | 382 |
373 if (lofi_decider) | |
374 lofi_decider->MaybeSetIgnorePreviewsBlacklistDirective(headers); | |
375 VerifyHttpRequestHeaders(true, *headers); | 383 VerifyHttpRequestHeaders(true, *headers); |
376 } | 384 } |
377 | 385 |
378 void DataReductionProxyNetworkDelegate::OnBeforeRedirectInternal( | 386 void DataReductionProxyNetworkDelegate::OnBeforeRedirectInternal( |
379 net::URLRequest* request, | 387 net::URLRequest* request, |
380 const GURL& new_location) { | 388 const GURL& new_location) { |
381 // Since this is after a redirect response, reset |request|'s | 389 // Since this is after a redirect response, reset |request|'s |
382 // DataReductionProxyData, but keep page ID and session. | 390 // DataReductionProxyData, but keep page ID and session. |
383 // TODO(ryansturm): Change ClearData logic to have persistent and | 391 // TODO(ryansturm): Change ClearData logic to have persistent and |
384 // non-persistent (WRT redirects) data. | 392 // non-persistent (WRT redirects) data. |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 } | 700 } |
693 | 701 |
694 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader( | 702 void DataReductionProxyNetworkDelegate::RemoveChromeProxyECTHeader( |
695 net::HttpRequestHeaders* request_headers) const { | 703 net::HttpRequestHeaders* request_headers) const { |
696 DCHECK(thread_checker_.CalledOnValidThread()); | 704 DCHECK(thread_checker_.CalledOnValidThread()); |
697 | 705 |
698 request_headers->RemoveHeader(chrome_proxy_ect_header()); | 706 request_headers->RemoveHeader(chrome_proxy_ect_header()); |
699 } | 707 } |
700 | 708 |
701 } // namespace data_reduction_proxy | 709 } // namespace data_reduction_proxy |
OLD | NEW |