Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions net/http/http_network_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ void HttpNetworkSession::DisableQuic() {
params_.enable_quic = false;
}

#if BUILDFLAG(IS_COBALT)
bool HttpNetworkSession::UseQuicForUnknownOrigin() const {
return params_.use_quic_for_unknown_origins;
}
#endif

bool HttpNetworkSession::ShouldForceQuic(const url::SchemeHostPort& destination,
const ProxyInfo& proxy_info,
bool is_websocket) {
Expand Down
11 changes: 11 additions & 0 deletions net/http/http_network_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ struct NET_EXPORT HttpNetworkSessionParams {
// Enables QUIC support.
bool enable_quic = true;

#if BUILDFLAG(IS_COBALT)
// If true, request to an origin without recorded alt-svc info will
// try to establish both QUIC and TCP connections and use the faster one.
bool use_quic_for_unknown_origins = false;
#endif

// If non-empty, QUIC will only be spoken to hosts in this list.
base::flat_set<std::string> quic_host_allowlist;

Expand Down Expand Up @@ -303,6 +309,11 @@ class NET_EXPORT HttpNetworkSession : public base::PowerSuspendObserver {
// Disable QUIC for new streams.
void DisableQuic();

#if BUILDFLAG(IS_COBALT)
// Whether to try QUIC connection for origins without alt-svc on record.
bool UseQuicForUnknownOrigin() const;
#endif

// Returns true when QUIC is forcibly used for `destination`.
bool ShouldForceQuic(const url::SchemeHostPort& destination,
const ProxyInfo& proxy_info,
Expand Down
20 changes: 20 additions & 0 deletions net/http/http_stream_factory_job_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,26 @@ HttpStreamFactory::JobController::GetAlternativeServiceInfoInternal(
url::SchemeHostPort(original_url),
request_info.network_anonymization_key);
if (alternative_service_info_vector.empty()) {
#if BUILDFLAG(IS_COBALT)
// This block of code suggests QUIC connection for initial requests to a
// new host. This method is proven to provide performance benefit while still
// enabling Cobalt network module to fall back on TCP connection when QUIC
// fails or is too slow.
if (session_->IsQuicEnabled() && session_->UseQuicForUnknownOrigin()) {
url::SchemeHostPort origin(original_url);
#if defined(COBALT_BUILD_TYPE_GOLD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would port not be 443?

I also think it's dangerous to have qa and gold differ on this behavior. Prod could break if there's some issue with the prod-specific code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3514 I would assume for testing/debugging purposes -- @kaidokert do you remember the exact reasoning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is for mirroring the enforcing of https for gold builds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should at least enforce it to be a privileged port (<1024).

const int kDefaultQUICServerPort = 443;
if (origin.port() == kDefaultQUICServerPort) {
#endif
quic::ParsedQuicVersionVector versions = quic::AllSupportedVersions();
return AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
AlternativeService(NextProto::kProtoQUIC, origin.host(), origin.port()),
base::Time::Max(), versions);
#if defined(COBALT_BUILD_TYPE_GOLD)
}
#endif
}
#endif // BUILDFLAG(IS_COBALT)
return AlternativeServiceInfo();
}

Expand Down
4 changes: 4 additions & 0 deletions services/network/network_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,10 @@ URLRequestContextOwner NetworkContext::MakeURLRequestContext(
*base::CommandLine::ForCurrentProcess(), is_quic_force_disabled,
&session_params, quic_context->params());

#if BUILDFLAG(IS_COBALT)
session_params.use_quic_for_unknown_origins = true;
#endif

session_params.disable_idle_sockets_close_on_memory_pressure =
params_->disable_idle_sockets_close_on_memory_pressure;

Expand Down
Loading