#include "net/proxy_resolution/configured_proxy_resolution_service.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <utility>
#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "net/base/net_errors.h"
#include "net/base/net_info_source_list.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/proxy_delegate.h"
#include "net/base/proxy_server.h"
#include "net/base/proxy_string_util.h"
#include "net/base/url_util.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_util.h"
#include "net/log/net_log_with_source.h"
#include "net/proxy_resolution/configured_proxy_resolution_request.h"
#include "net/proxy_resolution/dhcp_pac_file_fetcher.h"
#include "net/proxy_resolution/multi_threaded_proxy_resolver.h"
#include "net/proxy_resolution/pac_file_decider.h"
#include "net/proxy_resolution/pac_file_fetcher.h"
#include "net/proxy_resolution/proxy_config_service_fixed.h"
#include "net/proxy_resolution/proxy_resolver_factory.h"
#include "net/url_request/url_request_context.h"
#if BUILDFLAG(IS_WIN)
#include "net/proxy_resolution/win/proxy_resolver_winhttp.h"
#elif BUILDFLAG(IS_APPLE)
#include "net/proxy_resolution/proxy_resolver_apple.h"
#endif
TimeTicks;
namespace net {
namespace {
const size_t kDefaultNumPacThreads = …;
const int64_t kDelayAfterNetworkChangesMs = …;
class DefaultPollPolicy
: public ConfiguredProxyResolutionService::PacPollPolicy { … };
class ProxyConfigServiceDirect : public ProxyConfigService { … };
class ProxyResolverNull : public ProxyResolver { … };
class ProxyResolverFromPacString : public ProxyResolver { … };
class ProxyResolverFromProxyChains : public ProxyResolver { … };
class ProxyResolverFactoryForSystem : public MultiThreadedProxyResolverFactory { … };
class ProxyResolverFactoryForNullResolver : public ProxyResolverFactory { … };
class ProxyResolverFactoryForPacResult : public ProxyResolverFactory { … };
class ProxyResolverFactoryForProxyChains : public ProxyResolverFactory { … };
base::Value::Dict NetLogProxyConfigChangedParams(
const std::optional<ProxyConfigWithAnnotation>* old_config,
const ProxyConfigWithAnnotation* new_config) { … }
base::Value::Dict NetLogBadProxyListParams(
const ProxyRetryInfoMap* retry_info) { … }
base::Value::Dict NetLogFinishedResolvingProxyParams(const ProxyInfo* result) { … }
GURL SanitizeUrl(const GURL& url) { … }
}
class ConfiguredProxyResolutionService::InitProxyResolver { … };
class ConfiguredProxyResolutionService::PacFileDeciderPoller { … };
const ConfiguredProxyResolutionService::PacPollPolicy*
ConfiguredProxyResolutionService::PacFileDeciderPoller::poll_policy_ = …;
ConfiguredProxyResolutionService::ConfiguredProxyResolutionService(
std::unique_ptr<ProxyConfigService> config_service,
std::unique_ptr<ProxyResolverFactory> resolver_factory,
NetLog* net_log,
bool quick_check_enabled)
: … { … }
std::unique_ptr<ConfiguredProxyResolutionService>
ConfiguredProxyResolutionService::CreateUsingSystemProxyResolver(
std::unique_ptr<ProxyConfigService> proxy_config_service,
NetLog* net_log,
bool quick_check_enabled) { … }
std::unique_ptr<ConfiguredProxyResolutionService>
ConfiguredProxyResolutionService::CreateWithoutProxyResolver(
std::unique_ptr<ProxyConfigService> proxy_config_service,
NetLog* net_log) { … }
std::unique_ptr<ConfiguredProxyResolutionService>
ConfiguredProxyResolutionService::CreateFixedForTest(
const ProxyConfigWithAnnotation& pc) { … }
std::unique_ptr<ConfiguredProxyResolutionService>
ConfiguredProxyResolutionService::CreateFixedForTest(
const std::string& proxy,
const NetworkTrafficAnnotationTag& traffic_annotation) { … }
std::unique_ptr<ConfiguredProxyResolutionService>
ConfiguredProxyResolutionService::CreateDirect() { … }
std::unique_ptr<ConfiguredProxyResolutionService>
ConfiguredProxyResolutionService::CreateFixedFromPacResultForTest(
const std::string& pac_string,
const NetworkTrafficAnnotationTag& traffic_annotation) { … }
std::unique_ptr<ConfiguredProxyResolutionService>
ConfiguredProxyResolutionService::CreateFixedFromAutoDetectedPacResultForTest(
const std::string& pac_string,
const NetworkTrafficAnnotationTag& traffic_annotation) { … }
std::unique_ptr<ConfiguredProxyResolutionService>
ConfiguredProxyResolutionService::CreateFixedFromProxyChainsForTest(
const std::vector<ProxyChain>& proxy_chains,
const NetworkTrafficAnnotationTag& traffic_annotation) { … }
int ConfiguredProxyResolutionService::ResolveProxy(
const GURL& raw_url,
const std::string& method,
const NetworkAnonymizationKey& network_anonymization_key,
ProxyInfo* result,
CompletionOnceCallback callback,
std::unique_ptr<ProxyResolutionRequest>* out_request,
const NetLogWithSource& net_log) { … }
int ConfiguredProxyResolutionService::TryToCompleteSynchronously(
const GURL& url,
ProxyInfo* result) { … }
ConfiguredProxyResolutionService::~ConfiguredProxyResolutionService() { … }
void ConfiguredProxyResolutionService::SuspendAllPendingRequests() { … }
void ConfiguredProxyResolutionService::SetReady() { … }
void ConfiguredProxyResolutionService::ApplyProxyConfigIfAvailable() { … }
void ConfiguredProxyResolutionService::OnInitProxyResolverComplete(int result) { … }
void ConfiguredProxyResolutionService::ReportSuccess(const ProxyInfo& result) { … }
bool ConfiguredProxyResolutionService::ContainsPendingRequest(
ConfiguredProxyResolutionRequest* req) { … }
void ConfiguredProxyResolutionService::RemovePendingRequest(
ConfiguredProxyResolutionRequest* req) { … }
int ConfiguredProxyResolutionService::DidFinishResolvingProxy(
const GURL& url,
const NetworkAnonymizationKey& network_anonymization_key,
const std::string& method,
ProxyInfo* result,
int result_code,
const NetLogWithSource& net_log) { … }
void ConfiguredProxyResolutionService::SetPacFileFetchers(
std::unique_ptr<PacFileFetcher> pac_file_fetcher,
std::unique_ptr<DhcpPacFileFetcher> dhcp_pac_file_fetcher) { … }
void ConfiguredProxyResolutionService::SetProxyDelegate(
ProxyDelegate* delegate) { … }
void ConfiguredProxyResolutionService::OnShutdown() { … }
const ProxyRetryInfoMap& ConfiguredProxyResolutionService::proxy_retry_info()
const { … }
void ConfiguredProxyResolutionService::ClearBadProxiesCache() { … }
PacFileFetcher* ConfiguredProxyResolutionService::GetPacFileFetcher() const { … }
bool ConfiguredProxyResolutionService::GetLoadStateIfAvailable(
LoadState* load_state) const { … }
ProxyResolver* ConfiguredProxyResolutionService::GetProxyResolver() const { … }
ConfiguredProxyResolutionService::State
ConfiguredProxyResolutionService::ResetProxyConfig(bool reset_fetched_config) { … }
void ConfiguredProxyResolutionService::ForceReloadProxyConfig() { … }
base::Value::Dict ConfiguredProxyResolutionService::GetProxyNetLogValues() { … }
bool ConfiguredProxyResolutionService::CastToConfiguredProxyResolutionService(
ConfiguredProxyResolutionService** configured_proxy_resolution_service) { … }
const ConfiguredProxyResolutionService::PacPollPolicy*
ConfiguredProxyResolutionService::set_pac_script_poll_policy(
const PacPollPolicy* policy) { … }
std::unique_ptr<ConfiguredProxyResolutionService::PacPollPolicy>
ConfiguredProxyResolutionService::CreateDefaultPacPollPolicy() { … }
void ConfiguredProxyResolutionService::OnProxyConfigChanged(
const ProxyConfigWithAnnotation& config,
ProxyConfigService::ConfigAvailability availability) { … }
bool ConfiguredProxyResolutionService::ApplyPacBypassRules(const GURL& url,
ProxyInfo* results) { … }
void ConfiguredProxyResolutionService::InitializeUsingLastFetchedConfig() { … }
void ConfiguredProxyResolutionService::InitializeUsingDecidedConfig(
int decider_result,
const PacFileDataWithSource& script_data,
const ProxyConfigWithAnnotation& effective_config) { … }
void ConfiguredProxyResolutionService::OnIPAddressChanged() { … }
void ConfiguredProxyResolutionService::OnDNSChanged() { … }
}