146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// found in the LICENSE file. 446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_ 646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_ 746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 8f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include <string> 9f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include <utility> 1046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include <vector> 1146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 13f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "net/base/host_port_pair.h" 145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "net/proxy/proxy_retry_info.h" 1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "url/gurl.h" 1646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace base { 185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class TimeDelta; 195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 21f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace net { 221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass ProxyConfig; 23f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class URLRequest; 24f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 2546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 26f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace data_reduction_proxy { 276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Contains information about a given proxy server. |proxy_servers| contains 296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// the configured data reduction proxy servers. |is_fallback|, |is_alternative| 306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// and |is_ssl| note whether the given proxy is a fallback, an alternative, 316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// or a proxy for ssl; these are not mutually exclusive. 326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)struct DataReductionProxyTypeInfo { 336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DataReductionProxyTypeInfo(); 346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ~DataReductionProxyTypeInfo(); 356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) std::pair<GURL, GURL> proxy_servers; 366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool is_fallback; 376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool is_alternative; 386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool is_ssl; 396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}; 406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Provides initialization parameters. Proxy origins, and the probe url are 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// are taken from flags if available and from preprocessor constants otherwise. 43116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// The DataReductionProxySettings class and others use this class to determine 44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// the necessary DNS names to configure use of the data reduction proxy. 4546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class DataReductionProxyParams { 4646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) public: 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Flags used during construction that specify if the data reduction proxy 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // is allowed to be used, if the fallback proxy is allowed to be used, if 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // an alternative set of proxies is allowed to be used, if the promotion is 50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // allowed to be shown, and if this instance is part of a holdback experiment. 5146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) static const unsigned int kAllowed = (1 << 0); 5246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) static const unsigned int kFallbackAllowed = (1 << 1); 5346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) static const unsigned int kAlternativeAllowed = (1 << 2); 541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static const unsigned int kAlternativeFallbackAllowed = (1 << 3); 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static const unsigned int kPromoAllowed = (1 << 4); 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static const unsigned int kHoldback = (1 << 5); 5746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 5846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) typedef std::vector<GURL> DataReductionProxyList; 5946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 6046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns true if this client is part of field trial to use an alternative 6146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // configuration for the data reduction proxy. 6246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) static bool IsIncludedInAlternativeFieldTrial(); 6346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 6446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns true if this client is part of the field trial that should display 6546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // a promotion for the data reduction proxy. 6646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) static bool IsIncludedInPromoFieldTrial(); 6746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 6846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns true if this client is part of a field trial that uses preconnect 6946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // hinting. 7046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) static bool IsIncludedInPreconnectHintingFieldTrial(); 7146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns true if this client is part of a field trial that bypasses the 73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // proxy if the request resource type is on the critical path (e.g. HTML). 74116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static bool IsIncludedInCriticalPathBypassFieldTrial(); 75116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 76116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns true if this client is part of a field trial that runs a holdback 77116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // experiment. A holdback experiment is one in which a fraction of browser 78116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // instances will not be configured to use the data reduction proxy even if 79116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // users have enabled it to be used. The UI will not indicate that a holdback 80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // is in effect. 81116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static bool IsIncludedInHoldbackFieldTrial(); 8246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Returns true if this client is part of a field trial that removes the 841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // |MISSING_VIA_HEADER_OTHER| proxy bypass case. This experiment changes proxy 851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // bypass logic to not trigger a proxy bypass when a response with a non-4xx 861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // response code is expected to have a data reduction proxy via header, but 871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // the data reduction proxy via header is missing. 881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static bool IsIncludedInRemoveMissingViaHeaderOtherBypassFieldTrial(); 891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 9046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Constructs configuration parameters. If |kAllowed|, then the standard 9146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // data reduction proxy configuration is allowed to be used. If 9246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // |kfallbackAllowed| a fallback proxy can be used if the primary proxy is 9346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // bypassed or disabled. If |kAlternativeAllowed| then an alternative proxy 9446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // configuration is allowed to be used. This alternative configuration would 9546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // replace the primary and fallback proxy configurations if enabled. Finally 966d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // if |kPromoAllowed|, the client may show a promotion for the data reduction 976d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // proxy. 9846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // 9946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // A standard configuration has a primary proxy, and a fallback proxy for 10046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // HTTP traffic. The alternative configuration has a different primary and 10146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // fallback proxy for HTTP traffic, and an SSL proxy. 1026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) explicit DataReductionProxyParams(int flags); 10346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 1046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Creates a copy of the configuration parameters. 1056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) scoped_ptr<DataReductionProxyParams> Clone(); 10646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 10746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual ~DataReductionProxyParams(); 10846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 109f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Returns true if a data reduction proxy was used for the given |request|. 1106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // If true, |proxy_info.proxy_servers.first| will contain the name of the 1116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // proxy that was used. |proxy_info.proxy_servers.second| will contain the 1126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // name of the data reduction proxy server that would be used if 1136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // |proxy_info.proxy_server.first| is bypassed, if one exists. In addition, 1146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // |proxy_info| will note if the proxy used was a fallback, an alternative, 1156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // or a proxy for ssl; these are not mutually exclusive. |proxy_info| can be 1166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // NULL if the caller isn't interested in its values. 117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual bool WasDataReductionProxyUsed( 118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const net::URLRequest* request, 1196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DataReductionProxyTypeInfo* proxy_info) const; 120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Returns true if the specified |host_port_pair| matches a data reduction 1226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // proxy. If true, |proxy_info.proxy_servers.first| will contain the name of 1236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // the proxy that matches. |proxy_info.proxy_servers.second| will contain the 1246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // name of the data reduction proxy server that would be used if 1256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // |proxy_info.proxy_server.first| is bypassed, if one exists. In addition, 1266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // |proxy_info| will note if the proxy was a fallback, an alternative, or a 1276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // proxy for ssl; these are not mutually exclusive. |proxy_info| can be NULL 1286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // if the caller isn't interested in its values. Virtual for testing. 1296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual bool IsDataReductionProxy( 1306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const net::HostPortPair& host_port_pair, 1316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DataReductionProxyTypeInfo* proxy_info) const; 132116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Returns true if this request would be bypassed by the data request proxy 1341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // based on applying the |data_reduction_proxy_config| param rules to the 1351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // request URL. 1361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool IsBypassedByDataReductionProxyLocalRules( 1371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const net::URLRequest& request, 1381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const net::ProxyConfig& data_reduction_proxy_config) const; 139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Checks if all configured data reduction proxies are in the retry map. 1415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Returns true if the request is bypassed by all configured data reduction 1425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // proxies and returns the bypass delay in delay_seconds (if not NULL). If 1435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // there are no configured data reduction proxies, returns false. If 1445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the request is bypassed by more than one proxy, delay_seconds returns 1455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the shortest delay. 1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool AreDataReductionProxiesBypassed(const net::URLRequest& request, 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::TimeDelta* min_retry_delay) const; 1485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Checks if all configured data reduction proxies are in the retry map. 1505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Returns true if the request is bypassed by all configured data reduction 1515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // proxies and returns the bypass delay in delay_seconds (if not NULL). If 1525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // there are no configured data reduction proxies, returns false. If 1535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the request is bypassed by more than one proxy, delay_seconds returns 1545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the shortest delay. 1555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool AreProxiesBypassed(const net::ProxyRetryInfoMap& retry_map, 1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool is_https, 1575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::TimeDelta* min_retry_delay) const; 1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 15946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns the data reduction proxy primary origin. 16046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const GURL& origin() const { 16146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return origin_; 16246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 16346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 16446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns the data reduction proxy fallback origin. 16546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const GURL& fallback_origin() const { 16646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return fallback_origin_; 16746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 16846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 16946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns the data reduction proxy ssl origin that is used with the 17046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // alternative proxy configuration. 17146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const GURL& ssl_origin() const { 17246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return ssl_origin_; 17346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 17446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 17546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns the alternative data reduction proxy primary origin. 17646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const GURL& alt_origin() const { 17746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return alt_origin_; 17846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 17946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 18046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns the alternative data reduction proxy fallback origin. 18146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const GURL& alt_fallback_origin() const { 18246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return alt_fallback_origin_; 18346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 18446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 18546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns the URL to probe to decide if the primary origin should be used. 18646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const GURL& probe_url() const { 18746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return probe_url_; 18846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 18946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 1906d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Returns the URL to fetch to warm the data reduction proxy connection. 1916d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) const GURL& warmup_url() const { 1926d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) return warmup_url_; 1936d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) } 1946d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 19546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns true if the data reduction proxy configuration may be used. 19646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool allowed() const { 19746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return allowed_; 19846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 19946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 20046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns true if the fallback proxy may be used. 20146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool fallback_allowed() const { 20246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return fallback_allowed_; 20346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 20446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 20546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns true if the alternative data reduction proxy configuration may be 20646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // used. 20746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool alternative_allowed() const { 20846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return alt_allowed_; 20946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 21046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 2111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Returns true if the alternative fallback data reduction proxy 2121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // configuration may be used. 2131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool alternative_fallback_allowed() const { 2141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return alt_fallback_allowed_; 2151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 2161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 21746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns true if the data reduction proxy promo may be shown. 21846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // This is idependent of whether the data reduction proxy is allowed. 21946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // TODO(bengr): maybe tie to whether proxy is allowed. 22046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool promo_allowed() const { 22146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return promo_allowed_; 22246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 22346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 224116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns true if the data reduction proxy should not actually use the 225116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // proxy if enabled. 226116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool holdback() const { 227116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return holdback_; 228116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 229116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 23046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Given |allowed_|, |fallback_allowed_|, and |alt_allowed_|, returns the 23146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // list of data reduction proxies that may be used. 23246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) DataReductionProxyList GetAllowedProxies() const; 23346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 234116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns true if any proxy origins are set on the command line. 235116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool is_configured_on_command_line() const { 236116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return configured_on_command_line_; 237116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 238116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 23946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) protected: 24046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Test constructor that optionally won't call Init(); 24146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) DataReductionProxyParams(int flags, 24246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool should_call_init); 24346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 2446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DataReductionProxyParams(const DataReductionProxyParams& params); 2456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 246116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Initialize the values of the proxies, and probe URL, from command 24746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // line flags and preprocessor constants, and check that there are 24846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // corresponding definitions for the allowed configurations. 2491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool Init(bool allowed, 2501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool fallback_allowed, 2511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool alt_allowed, 2521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool alt_fallback_allowed); 25346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 254116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Initialize the values of the proxies, and probe URL from command 25546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // line flags and preprocessor constants. 25646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void InitWithoutChecks(); 25746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 25846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Returns the corresponding string from preprocessor constants if defined, 25946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // and an empty string otherwise. 26046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual std::string GetDefaultDevOrigin() const; 2611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual std::string GetDefaultDevFallbackOrigin() const; 26246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual std::string GetDefaultOrigin() const; 26346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual std::string GetDefaultFallbackOrigin() const; 26446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual std::string GetDefaultSSLOrigin() const; 26546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual std::string GetDefaultAltOrigin() const; 26646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual std::string GetDefaultAltFallbackOrigin() const; 26746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual std::string GetDefaultProbeURL() const; 2686d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) virtual std::string GetDefaultWarmupURL() const; 26946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 27046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) private: 2715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Checks if the primary and fallback data reduction proxies are in the retry 2725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // map. Returns true if the request is bypassed by both data reduction 2735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // proxies and returns the shortest bypass delay in delay_seconds (if not 2745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // NULL). If the fallback proxy is not valid, returns true if primary proxy 2755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // was bypassed and returns its bypass delay. 2765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool ArePrimaryAndFallbackBypassed(const net::ProxyRetryInfoMap& retry_map, 2775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const GURL& primary, 2785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const GURL& fallback, 2795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::TimeDelta* min_retry_delay) const; 2806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 2816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DataReductionProxyParams& operator=(const DataReductionProxyParams& params); 2826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 28346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GURL origin_; 28446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GURL fallback_origin_; 28546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GURL ssl_origin_; 28646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GURL alt_origin_; 28746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GURL alt_fallback_origin_; 28846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GURL probe_url_; 2896d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) GURL warmup_url_; 29046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 29146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool allowed_; 2926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool fallback_allowed_; 29346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool alt_allowed_; 2941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool alt_fallback_allowed_; 2956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool promo_allowed_; 296116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool holdback_; 297116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 298116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool configured_on_command_line_; 29946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}; 30046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 30146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)} // namespace data_reduction_proxy 30246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_ 303