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/browser/data_reduction_proxy_params.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " | 9 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " |
10 #include "net/proxy/proxy_info.h" | 10 #include "net/proxy/proxy_info.h" |
11 #include "net/proxy/proxy_retry_info.h" | |
11 #include "net/proxy/proxy_service.h" | 12 #include "net/proxy/proxy_service.h" |
12 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
13 #include "net/url_request/url_request_context.h" | 14 #include "net/url_request/url_request_context.h" |
14 | 15 |
15 using base::FieldTrialList; | 16 using base::FieldTrialList; |
16 | 17 |
17 namespace { | 18 namespace { |
18 const char kEnabled[] = "Enabled"; | 19 const char kEnabled[] = "Enabled"; |
19 } | 20 } |
20 | 21 |
22 using namespace net; | |
bengr
2014/07/19 00:13:00
Do you need this? If so, specify each class you ar
megjablon
2014/07/21 19:44:44
Done.
| |
23 | |
21 namespace data_reduction_proxy { | 24 namespace data_reduction_proxy { |
22 | 25 |
23 // static | 26 // static |
24 bool DataReductionProxyParams::IsIncludedInFieldTrial() { | 27 bool DataReductionProxyParams::IsIncludedInFieldTrial() { |
25 return base::FieldTrialList::FindFullName( | 28 return base::FieldTrialList::FindFullName( |
26 "DataCompressionProxyRollout") == kEnabled; | 29 "DataCompressionProxyRollout") == kEnabled; |
27 } | 30 } |
28 | 31 |
29 // static | 32 // static |
30 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() { | 33 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 } | 157 } |
155 if (promo_allowed_ && !allowed_) { | 158 if (promo_allowed_ && !allowed_) { |
156 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " | 159 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " |
157 << "data reduction proxy is not allowed"; | 160 << "data reduction proxy is not allowed"; |
158 return false; | 161 return false; |
159 } | 162 } |
160 return true; | 163 return true; |
161 | 164 |
162 } | 165 } |
163 | 166 |
164 | |
165 void DataReductionProxyParams::InitWithoutChecks() { | 167 void DataReductionProxyParams::InitWithoutChecks() { |
166 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 168 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
167 std::string origin; | 169 std::string origin; |
168 if (!command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) { | 170 if (!command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) { |
169 origin = command_line.GetSwitchValueASCII( | 171 origin = command_line.GetSwitchValueASCII( |
170 switches::kDataReductionProxyDev); | 172 switches::kDataReductionProxyDev); |
171 } | 173 } |
172 if (origin.empty()) | 174 if (origin.empty()) |
173 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); | 175 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); |
174 std::string fallback_origin = | 176 std::string fallback_origin = |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 return std::string(); | 324 return std::string(); |
323 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || | 325 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || |
324 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == | 326 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == |
325 kEnabled)) { | 327 kEnabled)) { |
326 return DATA_REDUCTION_DEV_HOST; | 328 return DATA_REDUCTION_DEV_HOST; |
327 } | 329 } |
328 #endif | 330 #endif |
329 return std::string(); | 331 return std::string(); |
330 } | 332 } |
331 | 333 |
334 bool DataReductionProxyParams::WereDataReductionProxiesBypassed( | |
335 const net::URLRequest& request, int64* delay_seconds) const { | |
bengr
2014/07/19 00:13:00
why is this an int64 and not a base::TimeDelta?
Al
megjablon
2014/07/21 19:44:44
We were using an int64 before in proxy metrics so
| |
336 DCHECK(request.context()); | |
337 DCHECK(request.context()->proxy_service()); | |
bengr
2014/07/19 00:13:00
So this should never be called if the request does
megjablon
2014/07/21 19:44:44
Switching back to how we checked previously.
| |
338 | |
339 const net::ProxyRetryInfoMap& retry_map = | |
340 request.context()->proxy_service()->proxy_retry_info(); | |
341 | |
342 bool ssl = request.url().SchemeIs(url::kHttpsScheme); | |
343 | |
344 return WereProxiesBypassed(retry_map, ssl, delay_seconds); | |
bengr
2014/07/19 00:13:00
Why not just:
return WereProxiesBypassed(request.
megjablon
2014/07/21 19:44:44
Done.
| |
345 } | |
346 | |
347 bool DataReductionProxyParams::WereProxiesBypassed( | |
348 const net::ProxyRetryInfoMap& retry_map, | |
349 bool ssl, | |
bengr
2014/07/19 00:13:00
rename ssl -> is_https
megjablon
2014/07/21 19:44:44
Done.
| |
350 int64* delay_seconds) const { | |
351 if (retry_map.size() == 0) | |
352 return false; | |
353 | |
354 if (ssl && alt_allowed_) { | |
355 if (WerePrimaryAndFallbackBypassed( | |
356 retry_map, ssl_origin_, GURL(), delay_seconds)) { | |
357 return true; | |
358 } | |
359 } else { | |
360 if (allowed_) { | |
361 if (WerePrimaryAndFallbackBypassed(retry_map, | |
362 origin_, | |
363 fallback_origin_, | |
364 delay_seconds)) { | |
365 return true; | |
366 } | |
367 } | |
368 | |
369 if (alt_allowed_) { | |
370 if (WerePrimaryAndFallbackBypassed(retry_map, | |
371 alt_origin_, | |
372 alt_fallback_origin_, | |
373 delay_seconds)) { | |
374 return true; | |
375 } | |
376 } | |
377 } | |
378 | |
379 return false; | |
bengr
2014/07/19 00:13:00
indentation here and below.
megjablon
2014/07/21 19:44:44
Done.
| |
380 } | |
381 | |
382 | |
383 bool DataReductionProxyParams::WerePrimaryAndFallbackBypassed( | |
384 const net::ProxyRetryInfoMap& retry_map, | |
385 GURL primary, | |
bengr
2014/07/19 00:13:00
const GURL&
megjablon
2014/07/21 19:44:44
Done.
| |
386 GURL fallback, | |
387 int64* delay_seconds) const { | |
388 int64 shortest_delay = 0; | |
389 net::ProxyRetryInfoMap::const_iterator found; | |
390 | |
391 std::string proxy = net::HostPortPair::FromURL(primary).ToString() + "/"; | |
392 // The retry list has the scheme prefix for https but not for http. | |
bengr
2014/07/19 00:13:01
Maybe a better way to do this would be to create a
megjablon
2014/07/21 19:44:44
Done.
| |
393 if (primary.SchemeIs(url::kHttpsScheme)) | |
394 proxy = std::string("https://") + proxy; | |
395 found = retry_map.find(proxy); | |
396 if (!(found == retry_map.end())) { | |
397 shortest_delay = found->second.current_delay.InSeconds(); | |
398 if (fallback_allowed_ && fallback.is_valid()) { | |
399 proxy = net::HostPortPair::FromURL(fallback).ToString() + "/"; | |
400 found = retry_map.find(proxy); | |
401 if (!(found == retry_map.end())) { | |
402 if(shortest_delay > found->second.current_delay.InSeconds()) | |
403 shortest_delay = found->second.current_delay.InSeconds(); | |
404 if (delay_seconds != NULL) | |
405 *delay_seconds = shortest_delay; | |
406 return true; | |
407 } | |
408 } else { | |
409 if (delay_seconds != NULL) | |
410 *delay_seconds = shortest_delay; | |
411 return true; | |
412 } | |
413 } | |
414 | |
415 return false; | |
416 } | |
417 | |
332 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 418 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
333 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 419 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
334 return SPDY_PROXY_AUTH_ORIGIN; | 420 return SPDY_PROXY_AUTH_ORIGIN; |
335 #endif | 421 #endif |
336 return std::string(); | 422 return std::string(); |
337 } | 423 } |
338 | 424 |
339 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { | 425 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { |
340 #if defined(DATA_REDUCTION_FALLBACK_HOST) | 426 #if defined(DATA_REDUCTION_FALLBACK_HOST) |
341 return DATA_REDUCTION_FALLBACK_HOST; | 427 return DATA_REDUCTION_FALLBACK_HOST; |
(...skipping 30 matching lines...) Expand all Loading... | |
372 } | 458 } |
373 | 459 |
374 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 460 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
375 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 461 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
376 return DATA_REDUCTION_PROXY_WARMUP_URL; | 462 return DATA_REDUCTION_PROXY_WARMUP_URL; |
377 #endif | 463 #endif |
378 return std::string(); | 464 return std::string(); |
379 } | 465 } |
380 | 466 |
381 } // namespace data_reduction_proxy | 467 } // namespace data_reduction_proxy |
OLD | NEW |