Home | History | Annotate | Download | only in proxy
      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_LIST_H_
      6 #define NET_PROXY_PROXY_LIST_H_
      7 #pragma once
      8 
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "net/proxy/proxy_retry_info.h"
     13 
     14 namespace net {
     15 
     16 class ProxyServer;
     17 
     18 // This class is used to hold a list of proxies returned by GetProxyForUrl or
     19 // manually configured. It handles proxy fallback if multiple servers are
     20 // specified.
     21 class ProxyList {
     22  public:
     23   ProxyList();
     24   ~ProxyList();
     25 
     26   // Initializes the proxy list to a string containing one or more proxy servers
     27   // delimited by a semicolon.
     28   void Set(const std::string& proxy_uri_list);
     29 
     30   // Set the proxy list to a single entry, |proxy_server|.
     31   void SetSingleProxyServer(const ProxyServer& proxy_server);
     32 
     33   // De-prioritizes the proxies that we have cached as not working, by moving
     34   // them to the end of the fallback list.
     35   void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info);
     36 
     37   // Delete any entry which doesn't have one of the specified proxy schemes.
     38   // |scheme_bit_field| is a bunch of ProxyServer::Scheme bitwise ORed together.
     39   void RemoveProxiesWithoutScheme(int scheme_bit_field);
     40 
     41   // Returns true if there is nothing left in the ProxyList.
     42   bool IsEmpty() const;
     43 
     44   // Returns the first proxy server in the list. It is only valid to call
     45   // this if !IsEmpty().
     46   const ProxyServer& Get() const;
     47 
     48   // Sets the list by parsing the pac result |pac_string|.
     49   // Some examples for |pac_string|:
     50   //   "DIRECT"
     51   //   "PROXY foopy1"
     52   //   "PROXY foopy1; SOCKS4 foopy2:1188"
     53   // Does a best-effort parse, and silently discards any errors.
     54   void SetFromPacString(const std::string& pac_string);
     55 
     56   // Returns a PAC-style semicolon-separated list of valid proxy servers.
     57   // For example: "PROXY xxx.xxx.xxx.xxx:xx; SOCKS yyy.yyy.yyy:yy".
     58   std::string ToPacString() const;
     59 
     60   // Marks the current proxy server as bad and deletes it from the list.  The
     61   // list of known bad proxies is given by proxy_retry_info.  Returns true if
     62   // there is another server available in the list.
     63   bool Fallback(ProxyRetryInfoMap* proxy_retry_info);
     64 
     65  private:
     66   // List of proxies.
     67   std::vector<ProxyServer> proxies_;
     68 };
     69 
     70 }  // namespace net
     71 
     72 #endif  // NET_PROXY_PROXY_LIST_H_
     73