Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick PR #3979: Add disable_h2 and matching h5vcc.settings #3981

Merged
merged 1 commit into from
Aug 13, 2024
Merged
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
22 changes: 17 additions & 5 deletions cobalt/h5vcc/h5vcc_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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 kHTTP2[] = "HTTP2";
const char kHTTP3[] = "HTTP3";
const char kSkiaRasterizer[] = "SkiaRasterizer";

Expand All @@ -70,11 +71,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 @@ -100,6 +96,17 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
}
}

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;
Expand Down Expand Up @@ -153,6 +160,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
15 changes: 15 additions & 0 deletions cobalt/network/network_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ void NetworkModule::SetEnableQuicFromPersistentSettings() {
}
}

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) {
Expand Down Expand Up @@ -233,6 +247,7 @@ void NetworkModule::Initialize(const std::string& user_agent_string,
url_request_context_.get(), thread_.get());

SetEnableQuicFromPersistentSettings();
SetEnableHttp2FromPersistentSettings();
SetEnableHttp3FromPersistentSettings();
}

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 kHttp2EnabledPersistentSettingsKey[] = "HTTP2Enabled";
const char kHttp3EnabledPersistentSettingsKey[] = "HTTP3Enabled";

class NetworkSystem;
Expand Down Expand Up @@ -130,6 +131,7 @@ class NetworkModule : public base::CurrentThread::DestructionObserver {
void SetProxy(const std::string& custom_proxy_rules);

void SetEnableQuicFromPersistentSettings();
void SetEnableHttp2FromPersistentSettings();
void SetEnableHttp3FromPersistentSettings();

// Adds the Client Hint Headers to the provided URLFetcher if enabled.
Expand Down
3 changes: 3 additions & 0 deletions cobalt/network/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const char kDisableInAppDial[] = "disable_in_app_dial";
// Switch to disable use of the Quic network protocol.
const char kDisableQuic[] = "disable_quic";

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


} // namespace switches
} // namespace network
Expand Down
1 change: 1 addition & 0 deletions cobalt/network/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern const char kMaxNetworkDelayHelp[];
extern const char kDisableInAppDial[];
#endif // ENABLE_DEBUG_COMMAND_LINE_SWITCHES
extern const char kDisableQuic[];
extern const char kDisableHttp2[];

} // namespace switches
} // namespace network
Expand Down
27 changes: 20 additions & 7 deletions cobalt/network/url_request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ URLRequestContext::URLRequestContext(
quic::ParsedQuicVersionVector{quic::ParsedQuicVersion::Q046()};
url_request_context_builder->set_quic_context(std::move(quic_context));

base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
bool quic_enabled =
configuration::Configuration::GetInstance()->CobaltEnableQuic();
if (quic_enabled) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
quic_enabled = !command_line->HasSwitch(switches::kDisableQuic);
}
configuration::Configuration::GetInstance()->CobaltEnableQuic() &&
!command_line->HasSwitch(switches::kDisableQuic);
bool spdy_enabled = !command_line->HasSwitch(switches::kDisableHttp2);

url_request_context_builder->SetSpdyAndQuicEnabled(/*spdy_enabled=*/true,
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;

Expand Down Expand Up @@ -329,7 +329,20 @@ void URLRequestContext::SetProxy(const std::string& proxy_rules) {

void URLRequestContext::SetEnableQuic(bool enable_quic) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
url_request_context_->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);
}

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 @@ -60,6 +60,7 @@ class 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 @@ -373,6 +373,25 @@ void HttpNetworkSession::DisableQuic() {
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 @@ -315,6 +315,7 @@ class NET_EXPORT HttpNetworkSession {

#if defined(STARBOARD)
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
Loading