Skip to content

Commit

Permalink
Add disable_h2 and matching h5vcc.settings (#3979)
Browse files Browse the repository at this point in the history
This adds a command-line switch `disable_h2` that disables the HTTP/2
protocol (spdy), and a matching `h5vcc.settings` parameter 'HTTP2' (with
backing by `PersistentSettings`) for run-time disabling of HTTP/2 and
spdy. Similar to 'QUIC' and 'HTTP3', the setting takes effect
immediately for new connections only.

This also ensures that when the command-line parameter `disable_quic` or
the new `disable_h2` is used, that that can not be overuled later with
`5vcc.settings` or from the corresponding `PersistentSetting`.

b/205134049

(cherry picked from commit 2ca4fc9)
  • Loading branch information
jellefoks authored and anonymous1-me committed Aug 13, 2024
1 parent 91918c2 commit 0f1f05a
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 5 deletions.
78 changes: 73 additions & 5 deletions cobalt/h5vcc/h5vcc_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
const char kMediaCodecBlockList[] = "MediaCodecBlockList";
const char kNavigatorUAData[] = "NavigatorUAData";
const char kQUIC[] = "QUIC";
<<<<<<< HEAD
=======
const char kHTTP2[] = "HTTP2";
const char kHTTP3[] = "HTTP3";
const char kSkiaRasterizer[] = "SkiaRasterizer";
>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))

#if SB_IS(EVERGREEN)
const char kUpdaterMinFreeSpaceBytes[] = "Updater.MinFreeSpaceBytes";
Expand All @@ -62,11 +68,6 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
return true;
}

if (set_web_setting_func_ && value.IsType<int32>() &&
set_web_setting_func_.Run(name, value.AsType<int32>())) {
return true;
}

if (name.rfind(kMediaPrefix, 0) == 0 && value.IsType<int32>()) {
return media_module_
? media_module_->SetConfiguration(
Expand All @@ -81,6 +82,68 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
}

if (name.compare(kQUIC) == 0 && value.IsType<int32>()) {
<<<<<<< HEAD
=======
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.
network_module_->SetEnableQuicFromPersistentSettings();
return true;
}
}

if (name.compare(kHTTP2) == 0 && value.IsType<int32>()) {
if (!persistent_settings_ || !network_module_) {
return false;
} else {
persistent_settings_->Set(network::kHttp2EnabledPersistentSettingsKey,
base::Value(value.AsType<int32>() != 0));
network_module_->SetEnableHttp2FromPersistentSettings();
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;
}
}

if (name.compare("cpu_usage_tracker_intervals") == 0 &&
value.IsType<std::string>() && value.AsType<std::string>().size() < 512) {
absl::optional<base::Value> config =
base::JSONReader::Read(value.AsType<std::string>());
browser::CpuUsageTracker::GetInstance()->UpdateIntervalsDefinition(
config.has_value() ? std::move(*config) : base::Value());
return true;
}
if (name.compare("cpu_usage_tracker_intervals_enabled") == 0 &&
value.IsType<int32>()) {
browser::CpuUsageTracker::GetInstance()->UpdateIntervalsEnabled(
value.AsType<int32>() != 0);
return true;
}
if (name.compare("cpu_usage_tracker_one_time_tracking") == 0 &&
value.IsType<int32>()) {
bool started = value.AsType<int32>() != 0;
if (started) {
browser::CpuUsageTracker::GetInstance()->StartOneTimeTracking();
} else {
browser::CpuUsageTracker::GetInstance()->StopAndCaptureOneTimeTracking();
}
return true;
}

if (name.compare(kSkiaRasterizer) == 0 && value.IsType<int32>()) {
>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))
if (!persistent_settings_) {
return false;
} else {
Expand All @@ -101,6 +164,11 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
return true;
}
#endif
if (set_web_setting_func_ && value.IsType<int32>() &&
set_web_setting_func_.Run(name, value.AsType<int32>())) {
return true;
}

return false;
}

Expand Down
48 changes: 48 additions & 0 deletions cobalt/network/network_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,49 @@ void NetworkModule::SetEnableQuicFromPersistentSettings() {
}
}

<<<<<<< HEAD
=======
void NetworkModule::SetEnableHttp2FromPersistentSettings() {
// Called on initialization and when the persistent setting is changed.
if (options_.persistent_settings != nullptr) {
base::Value value;
options_.persistent_settings->Get(kHttp2EnabledPersistentSettingsKey,
&value);
bool enable_http2 = value.GetIfBool().value_or(true);
task_runner()->PostTask(
FROM_HERE,
base::Bind(&URLRequestContext::SetEnableHttp2,
base::Unretained(url_request_context_.get()), enable_http2));
}
}

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)));
}
}

>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))
void NetworkModule::EnsureStorageManagerStarted() {
DCHECK(storage_manager_);
storage_manager_->EnsureStarted();
Expand Down Expand Up @@ -200,6 +243,11 @@ void NetworkModule::Initialize(const std::string& user_agent_string,
url_request_context_.get(), thread_.get());

SetEnableQuicFromPersistentSettings();
<<<<<<< HEAD
=======
SetEnableHttp2FromPersistentSettings();
SetEnableHttp3FromPersistentSettings();
>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))
}

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

const char kQuicEnabledPersistentSettingsKey[] = "QUICEnabled";
<<<<<<< HEAD
=======
const char kHttp2EnabledPersistentSettingsKey[] = "HTTP2Enabled";
const char kHttp3EnabledPersistentSettingsKey[] = "HTTP3Enabled";
>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))

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

void SetEnableQuicFromPersistentSettings();
<<<<<<< HEAD
=======
void SetEnableHttp2FromPersistentSettings();
void SetEnableHttp3FromPersistentSettings();
>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))

// Adds the Client Hint Headers to the provided URLFetcher if enabled.
void AddClientHintHeaders(net::URLFetcher& url_fetcher,
Expand Down
7 changes: 7 additions & 0 deletions cobalt/network/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ const char kMaxNetworkDelayHelp[] =
// Switch to disable use of the Quic network protocol.
const char kDisableQuic[] = "disable_quic";

<<<<<<< HEAD
=======
// Switch to disable use of the HTTP/2 (SPDY) network protocol.
const char kDisableHttp2[] = "disable_h2";


>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))
} // namespace switches
} // namespace network
} // namespace cobalt
1 change: 1 addition & 0 deletions cobalt/network/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern const char kMaxNetworkDelay[];
extern const char kMaxNetworkDelayHelp[];
#endif // ENABLE_DEBUG_COMMAND_LINE_SWITCHES
extern const char kDisableQuic[];
extern const char kDisableHttp2[];

} // namespace switches
} // namespace network
Expand Down
34 changes: 34 additions & 0 deletions cobalt/network/url_request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ URLRequestContext::URLRequestContext(
// android devices.
SetQuicFlag(&FLAGS_quic_reloadable_flag_quic_enable_ack_decimation, true);

<<<<<<< HEAD
net::HostResolver::Options options;
options.max_concurrent_resolves = net::HostResolver::kDefaultParallelism;
options.max_retry_attempts = net::HostResolver::kDefaultRetryAttempts;
Expand Down Expand Up @@ -185,6 +186,22 @@ URLRequestContext::URLRequestContext(
params.enable_quic = !command_line->HasSwitch(switches::kDisableQuic);
params.use_quic_for_unknown_origins = params.enable_quic;
}
=======
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
bool quic_enabled =
configuration::Configuration::GetInstance()->CobaltEnableQuic() &&
!command_line->HasSwitch(switches::kDisableQuic);
bool spdy_enabled = !command_line->HasSwitch(switches::kDisableHttp2);

url_request_context_builder->SetSpdyAndQuicEnabled(spdy_enabled,
quic_enabled);

net::HttpNetworkSessionParams params;
params.enable_http2 = spdy_enabled;
params.enable_quic = quic_enabled;
params.use_quic_for_unknown_origins = quic_enabled;

>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))
#if defined(ENABLE_IGNORE_CERTIFICATE_ERRORS)
params.ignore_certificate_errors = ignore_certificate_errors;
if (ignore_certificate_errors) {
Expand Down Expand Up @@ -283,7 +300,24 @@ void URLRequestContext::SetProxy(const std::string& proxy_rules) {

void URLRequestContext::SetEnableQuic(bool enable_quic) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
<<<<<<< HEAD
storage_.http_network_session()->SetEnableQuic(enable_quic);
=======
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
bool quic_commandline_enabled =
!command_line->HasSwitch(switches::kDisableQuic);
url_request_context_->http_network_session()->SetEnableQuic(
enable_quic && quic_commandline_enabled);
}

void URLRequestContext::SetEnableHttp2(bool enable_http2) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
bool http2_commandline_enabled =
!command_line->HasSwitch(switches::kDisableHttp2);
url_request_context_->http_network_session()->SetEnableHttp2(
enable_http2 && http2_commandline_enabled);
>>>>>>> 2ca4fc9bd1b (Add disable_h2 and matching h5vcc.settings (#3979))
}

bool URLRequestContext::using_http_cache() { return using_http_cache_; }
Expand Down
1 change: 1 addition & 0 deletions cobalt/network/url_request_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class URLRequestContext : public net::URLRequestContext {
void SetProxy(const std::string& custom_proxy_rules);

void SetEnableQuic(bool enable_quic);
void SetEnableHttp2(bool enable_http2);

bool using_http_cache();

Expand Down
19 changes: 19 additions & 0 deletions net/http/http_network_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,25 @@ void HttpNetworkSession::ToggleQuic() {
void HttpNetworkSession::SetEnableQuic(bool enable_quic) {
params_.enable_quic = enable_quic;
}
void HttpNetworkSession::SetEnableHttp2(bool enable_http2) {
if (params_.enable_http2 == enable_http2) {
return;
}
params_.enable_http2 = enable_http2;

if (params_.enable_http2) {
next_protos_.push_back(kProtoHTTP2);
if (base::FeatureList::IsEnabled(features::kAlpsForHttp2)) {
// Enable ALPS for HTTP/2 with empty data.
application_settings_[kProtoHTTP2] = {};
}
} else {
if (next_protos_.back() == kProtoHTTP2) {
next_protos_.pop_back();
}
application_settings_.erase(kProtoHTTP2);
}
}

bool HttpNetworkSession::UseQuicForUnknownOrigin() const {
return params_.use_quic_for_unknown_origins;
Expand Down
1 change: 1 addition & 0 deletions net/http/http_network_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ class NET_EXPORT HttpNetworkSession {
void ToggleQuic();

void SetEnableQuic(bool enable_quic);
void SetEnableHttp2(bool enable_http2);

// Whether to try QUIC connection for origins without alt-svc on record.
bool UseQuicForUnknownOrigin() const;
Expand Down

0 comments on commit 0f1f05a

Please sign in to comment.