Skip to content

Commit

Permalink
Add h5vcc.settings.set(HTTP3, 1/0) (#3541)
Browse files Browse the repository at this point in the history
Implements a persistent setting to enable or disable HTTP3 network
protocol(QUIC RFCv1) through h5vcc javascript API.

b/205134049
  • Loading branch information
johnxwork authored Jun 13, 2024
1 parent f664488 commit 183b0db
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cobalt/h5vcc/h5vcc_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
const char kMediaCodecBlockList[] = "MediaCodecBlockList";
const char kNavigatorUAData[] = "NavigatorUAData";
const char kQUIC[] = "QUIC";
const char kHTTP3[] = "HTTP3";

#if SB_IS(EVERGREEN)
const char kUpdaterMinFreeSpaceBytes[] = "Updater.MinFreeSpaceBytes";
Expand Down Expand Up @@ -81,15 +82,24 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
}

if (name.compare(kQUIC) == 0 && value.IsType<int32>()) {
if (!persistent_settings_) {
if (!persistent_settings_ || !network_module_) {
return false;
} else {
persistent_settings_->Set(network::kQuicEnabledPersistentSettingsKey,
base::Value(value.AsType<int32>() != 0));
// Tell NetworkModule (if exists) to re-query persistent settings.
if (network_module_) {
network_module_->SetEnableQuicFromPersistentSettings();
}
network_module_->SetEnableQuicFromPersistentSettings();
return true;
}
}

if (name.compare(kHTTP3) == 0 && value.IsType<int32>()) {
if (!persistent_settings_ || !network_module_) {
return false;
} else {
persistent_settings_->Set(network::kHttp3EnabledPersistentSettingsKey,
base::Value(value.AsType<int32>() != 0));
network_module_->SetEnableHttp3FromPersistentSettings();
return true;
}
}
Expand Down
27 changes: 27 additions & 0 deletions cobalt/network/network_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,32 @@ void NetworkModule::SetEnableQuicFromPersistentSettings() {
}
}

void NetworkModule::SetEnableHttp3FromPersistentSettings() {
// Called on initialization and when the persistent setting is changed.
if (options_.persistent_settings != nullptr) {
base::Value value;
options_.persistent_settings->Get(kHttp3EnabledPersistentSettingsKey,
&value);
bool enable_http3 = value.GetIfBool().value_or(false);
auto supported_version =
enable_http3
? net::DefaultSupportedQuicVersions()
: quic::ParsedQuicVersionVector{quic::ParsedQuicVersion::Q046()};
task_runner()->PostTask(
FROM_HERE, base::Bind(
[](URLRequestContext* url_request_context,
quic::ParsedQuicVersionVector supported_version) {
url_request_context->url_request_context()
->quic_context()
->params()
// Only allow the RFC version.
->supported_versions = supported_version;
},
base::Unretained(url_request_context_.get()),
std::move(supported_version)));
}
}

void NetworkModule::EnsureStorageManagerStarted() {
DCHECK(storage_manager_);
storage_manager_->EnsureStarted();
Expand Down Expand Up @@ -207,6 +233,7 @@ void NetworkModule::Initialize(const std::string& user_agent_string,
url_request_context_.get(), thread_.get());

SetEnableQuicFromPersistentSettings();
SetEnableHttp3FromPersistentSettings();
}

void NetworkModule::OnCreate(
Expand Down
2 changes: 2 additions & 0 deletions cobalt/network/network_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum ClientHintHeadersCallType : int32_t {
constexpr int32_t kEnabledClientHintHeaders = (kCallTypeLoader | kCallTypeXHR);

const char kQuicEnabledPersistentSettingsKey[] = "QUICEnabled";
const char kHttp3EnabledPersistentSettingsKey[] = "HTTP3Enabled";

class NetworkSystem;
// NetworkModule wraps various networking-related components such as
Expand Down Expand Up @@ -129,6 +130,7 @@ class NetworkModule : public base::CurrentThread::DestructionObserver {
void SetProxy(const std::string& custom_proxy_rules);

void SetEnableQuicFromPersistentSettings();
void SetEnableHttp3FromPersistentSettings();

// Adds the Client Hint Headers to the provided URLFetcher if enabled.
void AddClientHintHeaders(net::URLFetcher& url_fetcher,
Expand Down

0 comments on commit 183b0db

Please sign in to comment.