diff options
Diffstat (limited to 'net/proxy/proxy_service.cc')
-rw-r--r-- | net/proxy/proxy_service.cc | 160 |
1 files changed, 7 insertions, 153 deletions
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 438f147..9b1462f 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -4,20 +4,16 @@ #include "net/proxy/proxy_service.h" -#if defined(OS_WIN) -#include <windows.h> -#include <winhttp.h> -#endif - #include <algorithm> #include "base/compiler_specific.h" #include "base/logging.h" -#include "base/message_loop.h" #include "base/string_tokenizer.h" +#include "base/string_util.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" #include "net/proxy/proxy_config_service_fixed.h" +#include "net/proxy/proxy_script_fetcher.h" #if defined(OS_WIN) #include "net/proxy/proxy_config_service_win.h" #include "net/proxy/proxy_resolver_winhttp.h" @@ -67,153 +63,6 @@ class NotifyFetchCompletionTask : public Task { std::string bytes_; }; -// ProxyConfig ---------------------------------------------------------------- - -// static -ProxyConfig::ID ProxyConfig::last_id_ = ProxyConfig::INVALID_ID; - -ProxyConfig::ProxyConfig() - : auto_detect(false), - proxy_bypass_local_names(false), - id_(++last_id_) { -} - -bool ProxyConfig::Equals(const ProxyConfig& other) const { - // The two configs can have different IDs. We are just interested in if they - // have the same settings. - return auto_detect == other.auto_detect && - pac_url == other.pac_url && - proxy_rules == other.proxy_rules && - proxy_bypass == other.proxy_bypass && - proxy_bypass_local_names == other.proxy_bypass_local_names; -} - -// ProxyList ------------------------------------------------------------------ - -void ProxyList::Set(const std::string& proxy_uri_list) { - proxies_.clear(); - StringTokenizer str_tok(proxy_uri_list, ";"); - while (str_tok.GetNext()) { - ProxyServer uri = ProxyServer::FromURI( - str_tok.token_begin(), str_tok.token_end()); - // Silently discard malformed inputs. - if (uri.is_valid()) - proxies_.push_back(uri); - } -} - -void ProxyList::RemoveBadProxies(const ProxyRetryInfoMap& proxy_retry_info) { - std::vector<ProxyServer> new_proxy_list; - std::vector<ProxyServer>::const_iterator iter = proxies_.begin(); - for (; iter != proxies_.end(); ++iter) { - ProxyRetryInfoMap::const_iterator bad_proxy = - proxy_retry_info.find(iter->ToURI()); - if (bad_proxy != proxy_retry_info.end()) { - // This proxy is bad. Check if it's time to retry. - if (bad_proxy->second.bad_until >= TimeTicks::Now()) { - // still invalid. - continue; - } - } - new_proxy_list.push_back(*iter); - } - - proxies_ = new_proxy_list; -} - -void ProxyList::RemoveProxiesWithoutScheme(int scheme_bit_field) { - for (std::vector<ProxyServer>::iterator it = proxies_.begin(); - it != proxies_.end(); ) { - if (!(scheme_bit_field & it->scheme())) { - it = proxies_.erase(it); - continue; - } - ++it; - } -} - -ProxyServer ProxyList::Get() const { - if (!proxies_.empty()) - return proxies_[0]; - return ProxyServer(ProxyServer::SCHEME_DIRECT, std::string(), -1); -} - -std::string ProxyList::ToPacString() const { - std::string proxy_list; - std::vector<ProxyServer>::const_iterator iter = proxies_.begin(); - for (; iter != proxies_.end(); ++iter) { - if (!proxy_list.empty()) - proxy_list += ";"; - proxy_list += iter->ToPacString(); - } - return proxy_list.empty() ? "DIRECT" : proxy_list; -} - -void ProxyList::SetFromPacString(const std::string& pac_string) { - StringTokenizer entry_tok(pac_string, ";"); - proxies_.clear(); - while (entry_tok.GetNext()) { - ProxyServer uri = ProxyServer::FromPacString( - entry_tok.token_begin(), entry_tok.token_end()); - // Silently discard malformed inputs. - if (uri.is_valid()) - proxies_.push_back(uri); - } -} - -bool ProxyList::Fallback(ProxyRetryInfoMap* proxy_retry_info) { - // Number of minutes to wait before retrying a bad proxy server. - const TimeDelta kProxyRetryDelay = TimeDelta::FromMinutes(5); - - if (proxies_.empty()) { - NOTREACHED(); - return false; - } - - std::string key = proxies_[0].ToURI(); - - // Mark this proxy as bad. - ProxyRetryInfoMap::iterator iter = proxy_retry_info->find(key); - if (iter != proxy_retry_info->end()) { - // TODO(nsylvain): This is not the first time we get this. We should - // double the retry time. Bug 997660. - iter->second.bad_until = TimeTicks::Now() + iter->second.current_delay; - } else { - ProxyRetryInfo retry_info; - retry_info.current_delay = kProxyRetryDelay; - retry_info.bad_until = TimeTicks().Now() + retry_info.current_delay; - (*proxy_retry_info)[key] = retry_info; - } - - // Remove this proxy from our list. - proxies_.erase(proxies_.begin()); - - return !proxies_.empty(); -} - -// ProxyInfo ------------------------------------------------------------------ - -ProxyInfo::ProxyInfo() - : config_id_(ProxyConfig::INVALID_ID), - config_was_tried_(false) { -} - -void ProxyInfo::Use(const ProxyInfo& other) { - proxy_list_ = other.proxy_list_; -} - -void ProxyInfo::UseDirect() { - proxy_list_.Set(std::string()); -} - -void ProxyInfo::UseNamedProxy(const std::string& proxy_uri_list) { - proxy_list_.Set(proxy_uri_list); -} - -std::string ProxyInfo::ToPacString() { - return proxy_list_.ToPacString(); -} - // ProxyService::PacRequest --------------------------------------------------- // We rely on the fact that the origin thread (and its message loop) will not @@ -633,6 +482,11 @@ void ProxyService::CancelPacRequest(PacRequest* req) { } } +void ProxyService::SetProxyScriptFetcher( + ProxyScriptFetcher* proxy_script_fetcher) { + proxy_script_fetcher_.reset(proxy_script_fetcher); +} + void ProxyService::DidCompletePacRequest(int config_id, int result_code) { // If we get an error that indicates a bad PAC config, then we should // remember that, and not try the PAC config again for a while. |