Skip to content

Commit

Permalink
Perma-launch Client Hint Headers (#1839)
Browse files Browse the repository at this point in the history
Remove dependency on persistent settings to control the addition of
headers.

b/285656784

(cherry picked from commit e901c3d)
  • Loading branch information
gbournou authored and anonymous1-me committed Oct 25, 2023
1 parent cc5d09b commit 64702c5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 41 deletions.
17 changes: 0 additions & 17 deletions cobalt/h5vcc/h5vcc_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
const char kMediaPrefix[] = "Media.";
const char kMediaCodecBlockList[] = "MediaCodecBlockList";
const char kNavigatorUAData[] = "NavigatorUAData";
const char kClientHintHeaders[] = "ClientHintHeaders";
const char kQUIC[] = "QUIC";

#if SB_IS(EVERGREEN)
Expand Down Expand Up @@ -81,22 +80,6 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
return true;
}

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

if (name.compare(kQUIC) == 0 && value.IsType<int32>()) {
if (!persistent_settings_) {
return false;
Expand Down
16 changes: 1 addition & 15 deletions cobalt/network/network_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,6 @@ void NetworkModule::SetEnableQuicFromPersistentSettings() {
}
}

void NetworkModule::SetEnableClientHintHeadersFlagsFromPersistentSettings() {
// Called on initialization and when the persistent setting is changed.
// If persistent setting is not set, will default to
// kCallTypeLoader | kCallTypeXHR.
if (options_.persistent_settings != nullptr) {
enable_client_hint_headers_flags_.store(
options_.persistent_settings->GetPersistentSettingAsInt(
kClientHintHeadersEnabledPersistentSettingsKey,
(kCallTypeLoader | kCallTypeXHR)));
}
}

void NetworkModule::EnsureStorageManagerStarted() {
DCHECK(storage_manager_);
storage_manager_->EnsureStarted();
Expand All @@ -143,8 +131,6 @@ void NetworkModule::Initialize(const std::string& user_agent_string,
http_user_agent_settings_.reset(new net::StaticHttpUserAgentSettings(
options_.preferred_language, user_agent_string));

SetEnableClientHintHeadersFlagsFromPersistentSettings();

#if defined(ENABLE_DEBUG_COMMAND_LINE_SWITCHES)
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();

Expand Down Expand Up @@ -244,7 +230,7 @@ void NetworkModule::OnCreate(base::WaitableEvent* creation_event) {

void NetworkModule::AddClientHintHeaders(
net::URLFetcher& url_fetcher, ClientHintHeadersCallType call_type) const {
if (enable_client_hint_headers_flags_.load() & call_type) {
if (kEnabledClientHintHeaders & call_type) {
for (const auto& header : client_hint_headers_) {
url_fetcher.AddExtraRequestHeader(header);
}
Expand Down
13 changes: 4 additions & 9 deletions cobalt/network/network_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace cobalt {
namespace network {

// Used to differentiate type of network call for Client Hint Headers.
// Values correspond to bit masks against |enable_client_hint_headers_flags_|.
// Values correspond to bit masks against |kEnabledClientHintHeaders|.
enum ClientHintHeadersCallType : int32_t {
kCallTypeLoader = (1u << 0),
kCallTypeMedia = (1u << 1),
Expand All @@ -59,11 +59,10 @@ enum ClientHintHeadersCallType : int32_t {
kCallTypeXHR = (1u << 5),
};

const char kQuicEnabledPersistentSettingsKey[] = "QUICEnabled";
// Determines which type of network calls should include Client Hint Headers.
constexpr int32_t kEnabledClientHintHeaders = (kCallTypeLoader | kCallTypeXHR);

// Holds bit mask flag, read into |enable_client_hint_headers_flags_|.
const char kClientHintHeadersEnabledPersistentSettingsKey[] =
"clientHintHeadersEnabled";
const char kQuicEnabledPersistentSettingsKey[] = "QUICEnabled";

class NetworkSystem;
// NetworkModule wraps various networking-related components such as
Expand Down Expand Up @@ -132,9 +131,6 @@ class NetworkModule : public base::MessageLoop::DestructionObserver {

void SetEnableQuicFromPersistentSettings();

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

// Adds the Client Hint Headers to the provided URLFetcher if enabled.
void AddClientHintHeaders(net::URLFetcher& url_fetcher,
ClientHintHeadersCallType call_type) const;
Expand All @@ -154,7 +150,6 @@ class NetworkModule : public base::MessageLoop::DestructionObserver {
std::unique_ptr<network_bridge::NetPoster> CreateNetPoster();

std::vector<std::string> client_hint_headers_;
starboard::atomic_int32_t enable_client_hint_headers_flags_;
std::unique_ptr<storage::StorageManager> storage_manager_;
std::unique_ptr<base::Thread> thread_;
std::unique_ptr<URLRequestContext> url_request_context_;
Expand Down

0 comments on commit 64702c5

Please sign in to comment.