xref: /aosp_15_r20/external/cronet/net/proxy_resolution/proxy_info.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 ProxyInfo::ProxyInfo() = default;
12 
13 ProxyInfo::ProxyInfo(const ProxyInfo& other) = default;
14 
15 ProxyInfo::~ProxyInfo() = default;
16 
Use(const ProxyInfo & other)17 void ProxyInfo::Use(const ProxyInfo& other) {
18   proxy_resolve_start_time_ = other.proxy_resolve_start_time_;
19   proxy_resolve_end_time_ = other.proxy_resolve_end_time_;
20   proxy_list_ = other.proxy_list_;
21   proxy_retry_info_ = other.proxy_retry_info_;
22   did_bypass_proxy_ = other.did_bypass_proxy_;
23 }
24 
UseDirect()25 void ProxyInfo::UseDirect() {
26   Reset();
27   proxy_list_.SetSingleProxyChain(ProxyChain::Direct());
28 }
29 
UseDirectWithBypassedProxy()30 void ProxyInfo::UseDirectWithBypassedProxy() {
31   UseDirect();
32   did_bypass_proxy_ = true;
33 }
34 
UseNamedProxy(const std::string & proxy_uri_list)35 void ProxyInfo::UseNamedProxy(const std::string& proxy_uri_list) {
36   Reset();
37   proxy_list_.Set(proxy_uri_list);
38 }
39 
UseProxyChain(const ProxyChain & proxy_chain)40 void ProxyInfo::UseProxyChain(const ProxyChain& proxy_chain) {
41   Reset();
42   proxy_list_.SetSingleProxyChain(proxy_chain);
43 }
44 
UsePacString(const std::string & pac_string)45 void ProxyInfo::UsePacString(const std::string& pac_string) {
46   Reset();
47   proxy_list_.SetFromPacString(pac_string);
48 }
49 
UseProxyList(const ProxyList & proxy_list)50 void ProxyInfo::UseProxyList(const ProxyList& proxy_list) {
51   Reset();
52   proxy_list_ = proxy_list;
53 }
54 
OverrideProxyList(const ProxyList & proxy_list)55 void ProxyInfo::OverrideProxyList(const ProxyList& proxy_list) {
56   proxy_list_ = proxy_list;
57 }
58 
ContainsMultiProxyChain() const59 bool ProxyInfo::ContainsMultiProxyChain() const {
60   auto& proxy_chains = proxy_list_.AllChains();
61   return std::any_of(proxy_chains.begin(), proxy_chains.end(),
62                      [](const ProxyChain& proxy_chain) {
63                        return proxy_chain.is_multi_proxy();
64                      });
65 }
66 
ToPacString() const67 std::string ProxyInfo::ToPacString() const {
68   return proxy_list_.ToPacString();
69 }
70 
is_for_ip_protection() const71 bool ProxyInfo::is_for_ip_protection() const {
72   if (is_empty()) {
73     return false;
74   }
75   return proxy_chain().is_for_ip_protection();
76 }
77 
ToDebugString() const78 std::string ProxyInfo::ToDebugString() const {
79   return proxy_list_.ToDebugString();
80 }
81 
Fallback(int net_error,const NetLogWithSource & net_log)82 bool ProxyInfo::Fallback(int net_error, const NetLogWithSource& net_log) {
83   return proxy_list_.Fallback(&proxy_retry_info_, net_error, net_log);
84 }
85 
DeprioritizeBadProxyChains(const ProxyRetryInfoMap & proxy_retry_info)86 void ProxyInfo::DeprioritizeBadProxyChains(
87     const ProxyRetryInfoMap& proxy_retry_info) {
88   proxy_list_.DeprioritizeBadProxyChains(proxy_retry_info);
89 }
90 
RemoveProxiesWithoutScheme(int scheme_bit_field)91 void ProxyInfo::RemoveProxiesWithoutScheme(int scheme_bit_field) {
92   proxy_list_.RemoveProxiesWithoutScheme(scheme_bit_field);
93 }
94 
Reset()95 void ProxyInfo::Reset() {
96   proxy_resolve_start_time_ = base::TimeTicks();
97   proxy_resolve_end_time_ = base::TimeTicks();
98   proxy_list_.Clear();
99   proxy_retry_info_.clear();
100   did_bypass_proxy_ = false;
101 }
102 
AllChainProxiesAreHttps() const103 bool ProxyInfo::AllChainProxiesAreHttps() const {
104   const std::vector<ProxyServer>& proxy_servers = proxy_chain().proxy_servers();
105   return std::all_of(
106       proxy_servers.begin(), proxy_servers.end(),
107       [](const ProxyServer& proxy_server) { return proxy_server.is_https(); });
108 }
109 
110 }  // namespace net
111