Skip to content

Commit

Permalink
Add disable_h2 and matching h5vcc.settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jellefoks committed Aug 13, 2024
1 parent 91918c2 commit f4cee50
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 7 deletions.
26 changes: 21 additions & 5 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 kHTTP2[] = "HTTP2";

#if SB_IS(EVERGREEN)
const char kUpdaterMinFreeSpaceBytes[] = "Updater.MinFreeSpaceBytes";
Expand All @@ -62,11 +63,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 Down Expand Up @@ -95,12 +91,32 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
}
}

if (name.compare(kHTTP2) == 0 && value.IsType<int32>()) {
if (!persistent_settings_) {
return false;
} else {
persistent_settings_->SetPersistentSetting(
network::kHttp2EnabledPersistentSettingsKey,
std::make_unique<base::Value>(value.AsType<int32>() != 0));
// Tell NetworkModule (if exists) to re-query persistent settings.
if (network_module_) {
network_module_->SetEnableHttp2FromPersistentSettings();
}
return true;
}
}

#if SB_IS(EVERGREEN)
if (name.compare(kUpdaterMinFreeSpaceBytes) == 0 && value.IsType<int32>()) {
updater_module_->SetMinFreeSpaceBytes(value.AsType<int32>());
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
14 changes: 14 additions & 0 deletions cobalt/network/network_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ void NetworkModule::SetEnableQuicFromPersistentSettings() {
}
}

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

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

SetEnableQuicFromPersistentSettings();
SetEnableHttp2FromPersistentSettings();
}

void NetworkModule::OnCreate(base::WaitableEvent* creation_event) {
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 @@ -63,6 +63,7 @@ enum ClientHintHeadersCallType : int32_t {
constexpr int32_t kEnabledClientHintHeaders = (kCallTypeLoader | kCallTypeXHR);

const char kQuicEnabledPersistentSettingsKey[] = "QUICEnabled";
const char kHttp2EnabledPersistentSettingsKey[] = "HTTP2Enabled";

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

void SetEnableQuicFromPersistentSettings();
void SetEnableHttp2FromPersistentSettings();

// Adds the Client Hint Headers to the provided URLFetcher if enabled.
void AddClientHintHeaders(net::URLFetcher& url_fetcher,
Expand Down
3 changes: 3 additions & 0 deletions cobalt/network/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const char kMaxNetworkDelayHelp[] =
// 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
} // 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
18 changes: 16 additions & 2 deletions cobalt/network/url_request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ URLRequestContext::URLRequestContext(

net::HttpNetworkSession::Params params;

base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
params.enable_http2 = !command_line->HasSwitch(switches::kDisableHttp2);
if (configuration::Configuration::GetInstance()->CobaltEnableQuic()) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
params.enable_quic = !command_line->HasSwitch(switches::kDisableQuic);
params.use_quic_for_unknown_origins = params.enable_quic;
}
Expand Down Expand Up @@ -283,7 +284,20 @@ void URLRequestContext::SetProxy(const std::string& proxy_rules) {

void URLRequestContext::SetEnableQuic(bool enable_quic) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
storage_.http_network_session()->SetEnableQuic(enable_quic);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
bool quic_commandline_enabled =
!command_line->HasSwitch(switches::kDisableQuic);
storage_.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);
storage_.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 @@ -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
15 changes: 15 additions & 0 deletions net/http/http_network_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,21 @@ 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);
} else {
if (next_protos_.back() == kProtoHTTP2) {
next_protos_.pop_back();
}
}
}

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
1 change: 1 addition & 0 deletions net/http/http_stream_factory_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ int HttpStreamFactory::Job::DoInitConnectionImpl() {
// actually need to preconnect any sockets, so we're done.
if (job_type_ == PRECONNECT)
return OK;
negotiated_protocol_ = kProtoHTTP2;
using_spdy_ = true;
next_state_ = STATE_CREATE_STREAM;
return OK;
Expand Down

0 comments on commit f4cee50

Please sign in to comment.