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 "base/time/time.h" |
9 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 10 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
| 11 #include "net/base/host_port_pair.h" |
10 #include "net/proxy/proxy_info.h" | 12 #include "net/proxy/proxy_info.h" |
| 13 #include "net/proxy/proxy_retry_info.h" |
| 14 #include "net/proxy/proxy_server.h" |
11 #include "net/proxy/proxy_service.h" | 15 #include "net/proxy/proxy_service.h" |
12 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
13 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
| 18 #include "url/url_constants.h" |
14 | 19 |
15 using base::FieldTrialList; | 20 using base::FieldTrialList; |
16 | 21 |
17 namespace { | 22 namespace { |
18 const char kEnabled[] = "Enabled"; | 23 const char kEnabled[] = "Enabled"; |
19 } | 24 } |
20 | 25 |
21 namespace data_reduction_proxy { | 26 namespace data_reduction_proxy { |
22 | 27 |
23 // static | 28 // static |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 166 } |
162 if (promo_allowed_ && !allowed_) { | 167 if (promo_allowed_ && !allowed_) { |
163 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " | 168 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " |
164 << "data reduction proxy is not allowed"; | 169 << "data reduction proxy is not allowed"; |
165 return false; | 170 return false; |
166 } | 171 } |
167 return true; | 172 return true; |
168 | 173 |
169 } | 174 } |
170 | 175 |
171 | |
172 void DataReductionProxyParams::InitWithoutChecks() { | 176 void DataReductionProxyParams::InitWithoutChecks() { |
173 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 177 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
174 std::string origin; | 178 std::string origin; |
175 if (!command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) { | 179 if (!command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) { |
176 origin = command_line.GetSwitchValueASCII( | 180 origin = command_line.GetSwitchValueASCII( |
177 switches::kDataReductionProxyDev); | 181 switches::kDataReductionProxyDev); |
178 } | 182 } |
179 if (origin.empty()) | 183 if (origin.empty()) |
180 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); | 184 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); |
181 std::string fallback_origin = | 185 std::string fallback_origin = |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 return std::string(); | 333 return std::string(); |
330 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || | 334 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || |
331 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == | 335 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == |
332 kEnabled)) { | 336 kEnabled)) { |
333 return DATA_REDUCTION_DEV_HOST; | 337 return DATA_REDUCTION_DEV_HOST; |
334 } | 338 } |
335 #endif | 339 #endif |
336 return std::string(); | 340 return std::string(); |
337 } | 341 } |
338 | 342 |
| 343 bool DataReductionProxyParams::AreDataReductionProxiesBypassed( |
| 344 const net::URLRequest& request, base::TimeDelta* min_retry_delay) const { |
| 345 if (request.context() != NULL && |
| 346 request.context()->proxy_service() != NULL) { |
| 347 return AreProxiesBypassed( |
| 348 request.context()->proxy_service()->proxy_retry_info(), |
| 349 request.url().SchemeIs(url::kHttpsScheme), |
| 350 min_retry_delay); |
| 351 } |
| 352 |
| 353 return false; |
| 354 } |
| 355 |
| 356 bool DataReductionProxyParams::AreProxiesBypassed( |
| 357 const net::ProxyRetryInfoMap& retry_map, |
| 358 bool is_https, |
| 359 base::TimeDelta* min_retry_delay) const { |
| 360 if (retry_map.size() == 0) |
| 361 return false; |
| 362 |
| 363 if (is_https && alt_allowed_) { |
| 364 return ArePrimaryAndFallbackBypassed( |
| 365 retry_map, ssl_origin_, GURL(), min_retry_delay); |
| 366 } |
| 367 |
| 368 if (allowed_ && ArePrimaryAndFallbackBypassed( |
| 369 retry_map, origin_, fallback_origin_, min_retry_delay)) { |
| 370 return true; |
| 371 } |
| 372 |
| 373 if (alt_allowed_ && ArePrimaryAndFallbackBypassed( |
| 374 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay)) { |
| 375 return true; |
| 376 } |
| 377 |
| 378 return false; |
| 379 } |
| 380 |
| 381 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed( |
| 382 const net::ProxyRetryInfoMap& retry_map, |
| 383 const GURL& primary, |
| 384 const GURL& fallback, |
| 385 base::TimeDelta* min_retry_delay) const { |
| 386 net::ProxyRetryInfoMap::const_iterator found = retry_map.find( |
| 387 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ? |
| 388 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, |
| 389 net::HostPortPair::FromURL(primary)).ToURI()); |
| 390 |
| 391 if (found == retry_map.end()) |
| 392 return false; |
| 393 |
| 394 base::TimeDelta min_delay = found->second.current_delay; |
| 395 if (!fallback_allowed_ || !fallback.is_valid()) { |
| 396 if (min_retry_delay != NULL) |
| 397 *min_retry_delay = min_delay; |
| 398 return true; |
| 399 } |
| 400 |
| 401 found = retry_map.find( |
| 402 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ? |
| 403 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, |
| 404 net::HostPortPair::FromURL(fallback)).ToURI()); |
| 405 |
| 406 if (found == retry_map.end()) |
| 407 return false; |
| 408 |
| 409 if (min_delay > found->second.current_delay) |
| 410 min_delay = found->second.current_delay; |
| 411 if (min_retry_delay != NULL) |
| 412 *min_retry_delay = min_delay; |
| 413 return true; |
| 414 } |
| 415 |
339 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 416 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
340 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 417 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
341 return SPDY_PROXY_AUTH_ORIGIN; | 418 return SPDY_PROXY_AUTH_ORIGIN; |
342 #endif | 419 #endif |
343 return std::string(); | 420 return std::string(); |
344 } | 421 } |
345 | 422 |
346 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { | 423 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { |
347 #if defined(DATA_REDUCTION_FALLBACK_HOST) | 424 #if defined(DATA_REDUCTION_FALLBACK_HOST) |
348 return DATA_REDUCTION_FALLBACK_HOST; | 425 return DATA_REDUCTION_FALLBACK_HOST; |
(...skipping 30 matching lines...) Expand all Loading... |
379 } | 456 } |
380 | 457 |
381 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 458 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
382 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 459 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
383 return DATA_REDUCTION_PROXY_WARMUP_URL; | 460 return DATA_REDUCTION_PROXY_WARMUP_URL; |
384 #endif | 461 #endif |
385 return std::string(); | 462 return std::string(); |
386 } | 463 } |
387 | 464 |
388 } // namespace data_reduction_proxy | 465 } // namespace data_reduction_proxy |
OLD | NEW |