1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_PROXY_PROXY_INFO_H_ 6 #define NET_PROXY_PROXY_INFO_H_ 7 8 #include <string> 9 10 #include "net/proxy/proxy_config.h" 11 #include "net/proxy/proxy_list.h" 12 #include "net/proxy/proxy_retry_info.h" 13 #include "net/proxy/proxy_server.h" 14 15 class GURL; 16 17 namespace net { 18 19 // This object holds proxy information returned by ResolveProxy. 20 class ProxyInfo { 21 public: 22 ProxyInfo(); 23 // Default copy-constructor and assignment operator are OK! 24 25 // Use the same proxy server as the given |proxy_info|. 26 void Use(const ProxyInfo& proxy_info); 27 28 // Use a direct connection. 29 void UseDirect(); 30 31 // Use a specific proxy server, of the form: 32 // proxy-uri = [<scheme> "://"] <hostname> [":" <port>] 33 // This may optionally be a semi-colon delimited list of <proxy-uri>. 34 // It is OK to have LWS between entries. 35 void UseNamedProxy(const std::string& proxy_uri_list); 36 37 // Set the proxy list to a single entry, |proxy_server|. 38 void UseProxyServer(const ProxyServer& proxy_server); 39 40 // Parse from the given PAC result. UsePacString(const std::string & pac_string)41 void UsePacString(const std::string& pac_string) { 42 proxy_list_.SetFromPacString(pac_string); 43 } 44 45 // Returns true if this proxy info specifies a direct connection. is_direct()46 bool is_direct() const { 47 // We don't implicitly fallback to DIRECT unless it was added to the list. 48 if (is_empty()) 49 return false; 50 return proxy_list_.Get().is_direct(); 51 } 52 53 // Returns true if this proxy info has no proxies left to try. is_empty()54 bool is_empty() const { 55 return proxy_list_.IsEmpty(); 56 } 57 58 // Returns the first valid proxy server. is_empty() must be false to be able 59 // to call this function. proxy_server()60 ProxyServer proxy_server() const { return proxy_list_.Get(); } 61 62 // See description in ProxyList::ToPacString(). 63 std::string ToPacString() const; 64 65 // Marks the current proxy as bad. Returns true if there is another proxy 66 // available to try in proxy list_. Fallback(ProxyRetryInfoMap * proxy_retry_info)67 bool Fallback(ProxyRetryInfoMap* proxy_retry_info) { 68 return proxy_list_.Fallback(proxy_retry_info); 69 } 70 71 // De-prioritizes the proxies that we have cached as not working, by moving 72 // them to the end of the proxy list. DeprioritizeBadProxies(const ProxyRetryInfoMap & proxy_retry_info)73 void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info) { 74 proxy_list_.DeprioritizeBadProxies(proxy_retry_info); 75 } 76 77 // Delete any entry which doesn't have one of the specified proxy schemes. RemoveProxiesWithoutScheme(int scheme_bit_field)78 void RemoveProxiesWithoutScheme(int scheme_bit_field) { 79 proxy_list_.RemoveProxiesWithoutScheme(scheme_bit_field); 80 } 81 82 private: 83 friend class ProxyService; 84 85 // The ordered list of proxy servers (including DIRECT attempts) remaining to 86 // try. If proxy_list_ is empty, then there is nothing left to fall back to. 87 ProxyList proxy_list_; 88 89 // This value identifies the proxy config used to initialize this object. 90 ProxyConfig::ID config_id_; 91 }; 92 93 } // namespace net 94 95 #endif // NET_PROXY_PROXY_INFO_H_ 96