#include "net/http/http_stream_factory_job_controller.h"
#include <string>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/values.h"
#include "net/base/features.h"
#include "net/base/host_mapping_rules.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/privacy_mode.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_string_util.h"
#include "net/base/session_usage.h"
#include "net/base/url_util.h"
#include "net/http/alternative_service.h"
#include "net/http/bidirectional_stream_impl.h"
#include "net/http/http_stream_key.h"
#include "net/http/http_stream_pool.h"
#include "net/http/transport_security_state.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_with_source.h"
#include "net/proxy_resolution/proxy_info.h"
#include "net/proxy_resolution/proxy_resolution_request.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/quic/quic_session_key.h"
#include "net/spdy/spdy_session.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"
#include "url/url_constants.h"
namespace net {
namespace {
base::Value::Dict NetLogHttpStreamJobProxyChainResolved(
const ProxyChain& proxy_chain) { … }
GURL CreateAltSvcUrl(const GURL& origin_url,
const HostPortPair& alternative_destination) { … }
void ConvertWsToHttp(url::SchemeHostPort& input) { … }
void HistogramProxyUsed(const ProxyInfo& proxy_info, bool success) { … }
AlternativeService GetAlternativeServiceForDnsJob(const GURL& url) { … }
base::Value::Dict NetLogAltSvcParams(const AlternativeServiceInfo* alt_svc_info,
bool is_broken) { … }
}
const int kMaxDelayTimeForMainJobSecs = …;
HttpStreamFactory::JobController::JobController(
HttpStreamFactory* factory,
HttpStreamRequest::Delegate* delegate,
HttpNetworkSession* session,
JobFactory* job_factory,
const HttpRequestInfo& http_request_info,
bool is_preconnect,
bool is_websocket,
bool enable_ip_based_pooling,
bool enable_alternative_services,
bool delay_main_job_with_available_spdy_session,
const std::vector<SSLConfig::CertAndStatus>& allowed_bad_certs)
: … { … }
HttpStreamFactory::JobController::~JobController() { … }
std::unique_ptr<HttpStreamRequest> HttpStreamFactory::JobController::Start(
HttpStreamRequest::Delegate* delegate,
WebSocketHandshakeStreamBase::CreateHelper*
websocket_handshake_stream_create_helper,
const NetLogWithSource& source_net_log,
HttpStreamRequest::StreamType stream_type,
RequestPriority priority) { … }
void HttpStreamFactory::JobController::Preconnect(int num_streams) { … }
LoadState HttpStreamFactory::JobController::GetLoadState() const { … }
void HttpStreamFactory::JobController::OnRequestComplete() { … }
int HttpStreamFactory::JobController::RestartTunnelWithProxyAuth() { … }
void HttpStreamFactory::JobController::SetPriority(RequestPriority priority) { … }
void HttpStreamFactory::JobController::OnStreamReady(Job* job) { … }
void HttpStreamFactory::JobController::OnBidirectionalStreamImplReady(
Job* job,
const ProxyInfo& used_proxy_info) { … }
void HttpStreamFactory::JobController::OnWebSocketHandshakeStreamReady(
Job* job,
const ProxyInfo& used_proxy_info,
std::unique_ptr<WebSocketHandshakeStreamBase> stream) { … }
void HttpStreamFactory::JobController::OnQuicHostResolution(
const url::SchemeHostPort& destination,
base::TimeTicks dns_resolution_start_time,
base::TimeTicks dns_resolution_end_time) { … }
void HttpStreamFactory::JobController::OnStreamFailed(Job* job, int status) { … }
void HttpStreamFactory::JobController::OnFailedOnDefaultNetwork(Job* job) { … }
void HttpStreamFactory::JobController::OnCertificateError(
Job* job,
int status,
const SSLInfo& ssl_info) { … }
void HttpStreamFactory::JobController::OnNeedsClientAuth(
Job* job,
SSLCertRequestInfo* cert_info) { … }
void HttpStreamFactory::JobController::OnNeedsProxyAuth(
Job* job,
const HttpResponseInfo& proxy_response,
const ProxyInfo& used_proxy_info,
HttpAuthController* auth_controller) { … }
void HttpStreamFactory::JobController::OnPreconnectsComplete(Job* job,
int result) { … }
void HttpStreamFactory::JobController::OnOrphanedJobComplete(const Job* job) { … }
void HttpStreamFactory::JobController::AddConnectionAttemptsToRequest(
Job* job,
const ConnectionAttempts& attempts) { … }
void HttpStreamFactory::JobController::ResumeMainJobLater(
const base::TimeDelta& delay) { … }
void HttpStreamFactory::JobController::ResumeMainJob() { … }
void HttpStreamFactory::JobController::ResetErrorStatusForJobs() { … }
void HttpStreamFactory::JobController::MaybeResumeMainJob(
Job* job,
const base::TimeDelta& delay) { … }
void HttpStreamFactory::JobController::OnConnectionInitialized(Job* job,
int rv) { … }
bool HttpStreamFactory::JobController::ShouldWait(Job* job) { … }
const NetLogWithSource* HttpStreamFactory::JobController::GetNetLog() const { … }
void HttpStreamFactory::JobController::MaybeSetWaitTimeForMainJob(
const base::TimeDelta& delay) { … }
bool HttpStreamFactory::JobController::HasPendingMainJob() const { … }
bool HttpStreamFactory::JobController::HasPendingAltJob() const { … }
WebSocketHandshakeStreamBase::CreateHelper*
HttpStreamFactory::JobController::websocket_handshake_stream_create_helper() { … }
void HttpStreamFactory::JobController::OnIOComplete(int result) { … }
void HttpStreamFactory::JobController::RunLoop(int result) { … }
int HttpStreamFactory::JobController::DoLoop(int rv) { … }
int HttpStreamFactory::JobController::DoResolveProxy() { … }
int HttpStreamFactory::JobController::DoResolveProxyComplete(int rv) { … }
int HttpStreamFactory::JobController::DoCreateJobs() { … }
void HttpStreamFactory::JobController::ClearInappropriateJobs() { … }
void HttpStreamFactory::JobController::BindJob(Job* job) { … }
void HttpStreamFactory::JobController::OrphanUnboundJob() { … }
void HttpStreamFactory::JobController::OnJobSucceeded(Job* job) { … }
void HttpStreamFactory::JobController::MarkRequestComplete(Job* job) { … }
void HttpStreamFactory::JobController::MaybeReportBrokenAlternativeService(
const AlternativeService& alt_service,
int alt_job_net_error,
bool alt_job_failed_on_default_network,
const std::string& histogram_name_for_failure) { … }
void HttpStreamFactory::JobController::MaybeNotifyFactoryOfCompletion() { … }
void HttpStreamFactory::JobController::NotifyRequestFailed(int rv) { … }
void HttpStreamFactory::JobController::RewriteUrlWithHostMappingRules(
GURL& url) const { … }
GURL HttpStreamFactory::JobController::DuplicateUrlWithHostMappingRules(
const GURL& url) const { … }
AlternativeServiceInfo
HttpStreamFactory::JobController::GetAlternativeServiceInfoFor(
const GURL& http_request_info_url,
const StreamRequestInfo& request_info,
HttpStreamRequest::Delegate* delegate,
HttpStreamRequest::StreamType stream_type) { … }
AlternativeServiceInfo
HttpStreamFactory::JobController::GetAlternativeServiceInfoInternal(
const GURL& http_request_info_url,
const StreamRequestInfo& request_info,
HttpStreamRequest::Delegate* delegate,
HttpStreamRequest::StreamType stream_type) { … }
quic::ParsedQuicVersion HttpStreamFactory::JobController::SelectQuicVersion(
const quic::ParsedQuicVersionVector& advertised_versions) { … }
void HttpStreamFactory::JobController::ReportAlternateProtocolUsage(
AlternateProtocolUsage alternate_protocol_usage,
bool is_google_host) const { … }
bool HttpStreamFactory::JobController::IsJobOrphaned(Job* job) const { … }
AlternateProtocolUsage
HttpStreamFactory::JobController::CalculateAlternateProtocolUsage(
Job* job) const { … }
int HttpStreamFactory::JobController::ReconsiderProxyAfterError(Job* job,
int error) { … }
bool HttpStreamFactory::JobController::IsQuicAllowedForHost(
const std::string& host) { … }
void HttpStreamFactory::JobController::SwitchToHttpStreamPool(
quic::ParsedQuicVersion quic_version) { … }
void HttpStreamFactory::JobController::OnPoolPreconnectsComplete(int rv) { … }
void HttpStreamFactory::JobController::CallOnSwitchesToHttpStreamPool(
HttpStreamKey stream_key,
AlternativeServiceInfo alternative_service_info,
quic::ParsedQuicVersion quic_version) { … }
}