From 8edf04ca34e26f0af032575807401e3539e94c58 Mon Sep 17 00:00:00 2001 From: klzgrad Date: Wed, 4 May 2022 14:54:28 +0800 Subject: [PATCH] cronet: Use fixed proxy resolution from experimental option proxy_server --- src/components/cronet/cronet_context.cc | 26 ++++++++++++++++--- .../cronet/cronet_global_state_stubs.cc | 6 ++--- .../cronet/url_request_context_config.cc | 8 ++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/components/cronet/cronet_context.cc b/src/components/cronet/cronet_context.cc index 926500f7ae..85f14aa6fe 100644 --- a/src/components/cronet/cronet_context.cc +++ b/src/components/cronet/cronet_context.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "base/base64.h" @@ -53,7 +54,10 @@ #include "net/log/net_log_util.h" #include "net/net_buildflags.h" #include "net/nqe/network_quality_estimator_params.h" +#include "net/proxy_resolution/configured_proxy_resolution_service.h" +#include "net/proxy_resolution/proxy_config.h" #include "net/proxy_resolution/proxy_config_service_fixed.h" +#include "net/proxy_resolution/proxy_config_with_annotation.h" #include "net/proxy_resolution/proxy_resolution_service.h" #include "net/third_party/quiche/src/quiche/quic/core/quic_versions.h" #include "net/url_request/url_request_context.h" @@ -358,9 +362,25 @@ CronetContext::NetworkTasks::BuildDefaultURLRequestContext( net::URLRequestContextBuilder context_builder; SetSharedURLRequestContextBuilderConfig(&context_builder); - context_builder.set_proxy_resolution_service( - cronet::CreateProxyResolutionService(std::move(proxy_config_service), - g_net_log.Get().net_log())); + const auto proxy_server_it = + context_config_->effective_experimental_options.find("proxy_server"); + std::string proxy_server_str = "direct://"; + if (proxy_server_it != + context_config_->effective_experimental_options.end()) { + const base::Value& value = proxy_server_it->second; + if (value.is_string()) { + proxy_server_str = value.GetString(); + } + } + net::ProxyConfig proxy_config; + proxy_config.proxy_rules().ParseFromString(proxy_server_str); + auto proxy_service = + net::ConfiguredProxyResolutionService::CreateWithoutProxyResolver( + std::make_unique( + net::ProxyConfigWithAnnotation(proxy_config, + MISSING_TRAFFIC_ANNOTATION)), + g_net_log.Get().net_log()); + context_builder.set_proxy_resolution_service(std::move(proxy_service)); if (context_config_->enable_network_quality_estimator) { std::unique_ptr nqe_params = diff --git a/src/components/cronet/cronet_global_state_stubs.cc b/src/components/cronet/cronet_global_state_stubs.cc index a44ca10578..ff55b51348 100644 --- a/src/components/cronet/cronet_global_state_stubs.cc +++ b/src/components/cronet/cronet_global_state_stubs.cc @@ -62,15 +62,13 @@ void PostTaskToInitThread(const base::Location& posted_from, std::unique_ptr CreateProxyConfigService( const scoped_refptr& io_task_runner) { - return net::ConfiguredProxyResolutionService::CreateSystemProxyConfigService( - io_task_runner); + return nullptr; } std::unique_ptr CreateProxyResolutionService( std::unique_ptr proxy_config_service, net::NetLog* net_log) { - return net::ConfiguredProxyResolutionService::CreateUsingSystemProxyResolver( - std::move(proxy_config_service), net_log, /*quick_check_enabled=*/true); + return nullptr; } std::string CreateDefaultUserAgent(const std::string& partial_user_agent) { diff --git a/src/components/cronet/url_request_context_config.cc b/src/components/cronet/url_request_context_config.cc index a5688c7f2b..f19226f5de 100644 --- a/src/components/cronet/url_request_context_config.cc +++ b/src/components/cronet/url_request_context_config.cc @@ -753,6 +753,14 @@ void URLRequestContextConfig::SetContextBuilderExperimentalOptions( continue; } session_params->spdy_go_away_on_ip_change = iter.second.GetBool(); + } else if (iter.first == "proxy_server") { + if (!iter.second.is_string()) { + LOG(ERROR) << "\"" << iter.first << "\" config params \"" << iter.second + << "\" is not a string"; + effective_experimental_options.erase(iter.first); + continue; + } + // Handled in CronetContext::NetworkTasks::BuildDefaultURLRequestContext. } else { LOG(WARNING) << "Unrecognized Cronet experimental option \"" << iter.first << "\" with params \"" << iter.second;