1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/proxy_resolution/proxy_info.h" 6 7 #include "net/proxy_resolution/proxy_retry_info.h" 8 9 namespace net { 10 11 // static Direct()12ProxyInfo ProxyInfo::Direct() { 13 ProxyInfo proxy_info; 14 proxy_info.UseDirect(); 15 return proxy_info; 16 } 17 18 ProxyInfo::ProxyInfo() = default; 19 20 ProxyInfo::ProxyInfo(const ProxyInfo& other) = default; 21 22 ProxyInfo::~ProxyInfo() = default; 23 Use(const ProxyInfo & other)24void ProxyInfo::Use(const ProxyInfo& other) { 25 proxy_resolve_start_time_ = other.proxy_resolve_start_time_; 26 proxy_resolve_end_time_ = other.proxy_resolve_end_time_; 27 proxy_list_ = other.proxy_list_; 28 proxy_retry_info_ = other.proxy_retry_info_; 29 did_bypass_proxy_ = other.did_bypass_proxy_; 30 } 31 UseDirect()32void ProxyInfo::UseDirect() { 33 Reset(); 34 proxy_list_.SetSingleProxyChain(ProxyChain::Direct()); 35 } 36 UseDirectWithBypassedProxy()37void ProxyInfo::UseDirectWithBypassedProxy() { 38 UseDirect(); 39 did_bypass_proxy_ = true; 40 } 41 UseNamedProxy(const std::string & proxy_uri_list)42void ProxyInfo::UseNamedProxy(const std::string& proxy_uri_list) { 43 Reset(); 44 proxy_list_.Set(proxy_uri_list); 45 } 46 UseProxyChain(const ProxyChain & proxy_chain)47void ProxyInfo::UseProxyChain(const ProxyChain& proxy_chain) { 48 Reset(); 49 proxy_list_.SetSingleProxyChain(proxy_chain); 50 } 51 UsePacString(const std::string & pac_string)52void ProxyInfo::UsePacString(const std::string& pac_string) { 53 Reset(); 54 proxy_list_.SetFromPacString(pac_string); 55 } 56 UseProxyList(const ProxyList & proxy_list)57void ProxyInfo::UseProxyList(const ProxyList& proxy_list) { 58 Reset(); 59 proxy_list_ = proxy_list; 60 } 61 OverrideProxyList(const ProxyList & proxy_list)62void ProxyInfo::OverrideProxyList(const ProxyList& proxy_list) { 63 proxy_list_ = proxy_list; 64 } 65 ContainsMultiProxyChain() const66bool ProxyInfo::ContainsMultiProxyChain() const { 67 auto& proxy_chains = proxy_list_.AllChains(); 68 return std::any_of(proxy_chains.begin(), proxy_chains.end(), 69 [](const ProxyChain& proxy_chain) { 70 return proxy_chain.is_multi_proxy(); 71 }); 72 } 73 ToPacString() const74std::string ProxyInfo::ToPacString() const { 75 return proxy_list_.ToPacString(); 76 } 77 is_for_ip_protection() const78bool ProxyInfo::is_for_ip_protection() const { 79 if (is_empty()) { 80 return false; 81 } 82 return proxy_chain().is_for_ip_protection(); 83 } 84 ToDebugString() const85std::string ProxyInfo::ToDebugString() const { 86 return proxy_list_.ToDebugString(); 87 } 88 Fallback(int net_error,const NetLogWithSource & net_log)89bool ProxyInfo::Fallback(int net_error, const NetLogWithSource& net_log) { 90 return proxy_list_.Fallback(&proxy_retry_info_, net_error, net_log); 91 } 92 DeprioritizeBadProxyChains(const ProxyRetryInfoMap & proxy_retry_info)93void ProxyInfo::DeprioritizeBadProxyChains( 94 const ProxyRetryInfoMap& proxy_retry_info) { 95 proxy_list_.DeprioritizeBadProxyChains(proxy_retry_info); 96 } 97 RemoveProxiesWithoutScheme(int scheme_bit_field)98void ProxyInfo::RemoveProxiesWithoutScheme(int scheme_bit_field) { 99 proxy_list_.RemoveProxiesWithoutScheme(scheme_bit_field); 100 } 101 Reset()102void ProxyInfo::Reset() { 103 proxy_resolve_start_time_ = base::TimeTicks(); 104 proxy_resolve_end_time_ = base::TimeTicks(); 105 proxy_list_.Clear(); 106 proxy_retry_info_.clear(); 107 did_bypass_proxy_ = false; 108 } 109 AllChainProxiesAreHttps() const110bool ProxyInfo::AllChainProxiesAreHttps() const { 111 const std::vector<ProxyServer>& proxy_servers = proxy_chain().proxy_servers(); 112 return std::all_of( 113 proxy_servers.begin(), proxy_servers.end(), 114 [](const ProxyServer& proxy_server) { return proxy_server.is_https(); }); 115 } 116 117 } // namespace net 118