Skip to content

Commit

Permalink
Make gQUIC a persistent setting. (#954)
Browse files Browse the repository at this point in the history
b/291668726

Change-Id: I606e8e15f8e5cf97960ecf3ef6f96f7e69fbd3b3
(cherry picked from commit d67ddde)
  • Loading branch information
briantting authored and anonymous1-me committed Jul 19, 2023
1 parent 3de69ab commit 3d0800e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 8 additions & 2 deletions cobalt/h5vcc/h5vcc_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,16 @@ bool H5vccSettings::Set(const std::string& name, int32 value) const {
}

if (name.compare(kQUIC) == 0) {
if (!network_module_) {
if (!persistent_settings_) {
return false;
} else {
network_module_->SetEnableQuic(value != 0);
persistent_settings_->SetPersistentSetting(
network::kQuicEnabledPersistentSettingsKey,
std::make_unique<base::Value>(value != 0));
// Tell NetworkModule (if exists) to re-query persistent settings.
if (network_module_) {
network_module_->SetEnableQuicFromPersistentSettings();
}
return true;
}
}
Expand Down
17 changes: 12 additions & 5 deletions cobalt/network/network_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,16 @@ void NetworkModule::SetProxy(const std::string& custom_proxy_rules) {
custom_proxy_rules));
}

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

void NetworkModule::SetEnableClientHintHeadersFlagsFromPersistentSettings() {
Expand Down Expand Up @@ -193,6 +198,8 @@ void NetworkModule::Initialize(const std::string& user_agent_string,
DCHECK(url_request_context_);
url_request_context_getter_ = new network::URLRequestContextGetter(
url_request_context_.get(), thread_.get());

SetEnableQuicFromPersistentSettings();
}

void NetworkModule::OnCreate(base::WaitableEvent* creation_event) {
Expand Down
4 changes: 3 additions & 1 deletion cobalt/network/network_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ enum ClientHintHeadersCallType : int32_t {
kCallTypeXHR = (1u << 5),
};

const char kQuicEnabledPersistentSettingsKey[] = "QUICEnabled";

// Holds bit mask flag, read into |enable_client_hint_headers_flags_|.
const char kClientHintHeadersEnabledPersistentSettingsKey[] =
"clientHintHeadersEnabled";
Expand Down Expand Up @@ -128,7 +130,7 @@ class NetworkModule : public base::MessageLoop::DestructionObserver {
#endif
void SetProxy(const std::string& custom_proxy_rules);

void SetEnableQuic(bool enable_quic);
void SetEnableQuicFromPersistentSettings();

// Checks persistent settings to determine if Client Hint Headers are enabled.
void SetEnableClientHintHeadersFlagsFromPersistentSettings();
Expand Down

0 comments on commit 3d0800e

Please sign in to comment.