chromium/net/http/http_server_properties_manager.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/http/http_server_properties_manager.h"

#include <algorithm>
#include <optional>
#include <utility>

#include "base/containers/adapters.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "net/base/features.h"
#include "net/base/host_port_pair.h"
#include "net/base/ip_address.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/port_util.h"
#include "net/base/privacy_mode.h"
#include "net/http/http_server_properties.h"
#include "net/third_party/quiche/src/quiche/quic/platform/api/quic_hostname_utils.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"

namespace net {

namespace {

// "version" 0 indicates, http_server_properties doesn't have "version"
// property.
const int kMissingVersion =;

// The version number of persisted http_server_properties.
const int kVersionNumber =;

// Persist at most 200 currently-broken alternative services to disk.
const int kMaxBrokenAlternativeServicesToPersist =;

const char kServerKey[] =;
const char kQuicServerIdKey[] =;
const char kNetworkAnonymizationKey[] =;
const char kVersionKey[] =;
const char kServersKey[] =;
const char kSupportsSpdyKey[] =;
const char kSupportsQuicKey[] =;
const char kQuicServers[] =;
const char kServerInfoKey[] =;
const char kUsedQuicKey[] =;
const char kAddressKey[] =;
const char kAlternativeServiceKey[] =;
const char kProtocolKey[] =;
const char kHostKey[] =;
const char kPortKey[] =;
const char kExpirationKey[] =;
const char kAdvertisedAlpnsKey[] =;
const char kNetworkStatsKey[] =;
const char kSrttKey[] =;
const char kBrokenAlternativeServicesKey[] =;
const char kBrokenUntilKey[] =;
const char kBrokenCountKey[] =;

// Utility method to return only those AlternativeServiceInfos that should be
// persisted to disk. In particular, removes expired and invalid alternative
// services. Also checks if an alternative service for the same canonical suffix
// has already been saved, and if so, returns an empty list.
AlternativeServiceInfoVector GetAlternativeServiceToPersist(
    const std::optional<AlternativeServiceInfoVector>& alternative_services,
    const HttpServerProperties::ServerInfoMapKey& server_info_key,
    base::Time now,
    const HttpServerPropertiesManager::GetCannonicalSuffix&
        get_canonical_suffix,
    std::set<std::pair<std::string, NetworkAnonymizationKey>>*
        persisted_canonical_suffix_set) {}

void AddAlternativeServiceFieldsToDictionaryValue(
    const AlternativeService& alternative_service,
    base::Value::Dict& dict) {}

// Fails in the case of NetworkAnonymizationKeys that can't be persisted to
// disk, like unique origins.
bool TryAddBrokenAlternativeServiceFieldsToDictionaryValue(
    const BrokenAlternativeService& broken_alt_service,
    base::Value::Dict& dict) {}

quic::QuicServerId QuicServerIdFromString(const std::string& str) {}

std::string QuicServerIdToString(const quic::QuicServerId& server_id) {}

// Takes in a base::Value::Dict, and whether NetworkAnonymizationKeys are
// enabled for HttpServerProperties, and extracts the NetworkAnonymizationKey
// stored with the `kNetworkAnonymizationKey` in the dictionary, and writes it
// to `out_network_anonymization_key`. Returns false if unable to load a
// NetworkAnonymizationKey, or the NetworkAnonymizationKey is non-empty, but
// `use_network_anonymization_key` is false.
bool GetNetworkAnonymizationKeyFromDict(
    const base::Value::Dict& dict,
    bool use_network_anonymization_key,
    NetworkAnonymizationKey* out_network_anonymization_key) {}

}  // namespace

////////////////////////////////////////////////////////////////////////////////
//  HttpServerPropertiesManager

HttpServerPropertiesManager::HttpServerPropertiesManager(
    std::unique_ptr<HttpServerProperties::PrefDelegate> pref_delegate,
    OnPrefsLoadedCallback on_prefs_loaded_callback,
    size_t max_server_configs_stored_in_properties,
    NetLog* net_log,
    const base::TickClock* clock)
    :{}

HttpServerPropertiesManager::~HttpServerPropertiesManager() {}

void HttpServerPropertiesManager::ReadPrefs(
    std::unique_ptr<HttpServerProperties::ServerInfoMap>* server_info_map,
    IPAddress* last_local_address_when_quic_worked,
    std::unique_ptr<HttpServerProperties::QuicServerInfoMap>*
        quic_server_info_map,
    std::unique_ptr<BrokenAlternativeServiceList>*
        broken_alternative_service_list,
    std::unique_ptr<RecentlyBrokenAlternativeServices>*
        recently_broken_alternative_services) {}

void HttpServerPropertiesManager::AddToBrokenAlternativeServices(
    const base::Value::Dict& broken_alt_svc_entry_dict,
    bool use_network_anonymization_key,
    BrokenAlternativeServiceList* broken_alternative_service_list,
    RecentlyBrokenAlternativeServices* recently_broken_alternative_services) {}

void HttpServerPropertiesManager::AddServerData(
    const base::Value::Dict& server_dict,
    HttpServerProperties::ServerInfoMap* server_info_map,
    bool use_network_anonymization_key) {}

bool HttpServerPropertiesManager::ParseAlternativeServiceDict(
    const base::Value::Dict& dict,
    bool host_optional,
    const std::string& parsing_under,
    AlternativeService* alternative_service) {}

bool HttpServerPropertiesManager::ParseAlternativeServiceInfoDictOfServer(
    const base::Value::Dict& dict,
    const std::string& server_str,
    AlternativeServiceInfo* alternative_service_info) {}

bool HttpServerPropertiesManager::ParseAlternativeServiceInfo(
    const url::SchemeHostPort& server,
    const base::Value::Dict& server_pref_dict,
    HttpServerProperties::ServerInfo* server_info) {}

void HttpServerPropertiesManager::ReadLastLocalAddressWhenQuicWorked(
    const base::Value::Dict& http_server_properties_dict,
    IPAddress* last_local_address_when_quic_worked) {}

void HttpServerPropertiesManager::ParseNetworkStats(
    const url::SchemeHostPort& server,
    const base::Value::Dict& server_pref_dict,
    HttpServerProperties::ServerInfo* server_info) {}

void HttpServerPropertiesManager::AddToQuicServerInfoMap(
    const base::Value::Dict& http_server_properties_dict,
    bool use_network_anonymization_key,
    HttpServerProperties::QuicServerInfoMap* quic_server_info_map) {}

void HttpServerPropertiesManager::WriteToPrefs(
    const HttpServerProperties::ServerInfoMap& server_info_map,
    const GetCannonicalSuffix& get_canonical_suffix,
    const IPAddress& last_local_address_when_quic_worked,
    const HttpServerProperties::QuicServerInfoMap& quic_server_info_map,
    const BrokenAlternativeServiceList& broken_alternative_service_list,
    const RecentlyBrokenAlternativeServices&
        recently_broken_alternative_services,
    base::OnceClosure callback) {}

void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs(
    const AlternativeServiceInfoVector& alternative_service_info_vector,
    base::Value::Dict& server_pref_dict) {}

void HttpServerPropertiesManager::SaveLastLocalAddressWhenQuicWorkedToPrefs(
    const IPAddress& last_local_address_when_quic_worked,
    base::Value::Dict& http_server_properties_dict) {}

void HttpServerPropertiesManager::SaveNetworkStatsToServerPrefs(
    const ServerNetworkStats& server_network_stats,
    base::Value::Dict& server_pref_dict) {}

void HttpServerPropertiesManager::SaveQuicServerInfoMapToServerPrefs(
    const HttpServerProperties::QuicServerInfoMap& quic_server_info_map,
    base::Value::Dict& http_server_properties_dict) {}

void HttpServerPropertiesManager::SaveBrokenAlternativeServicesToPrefs(
    const BrokenAlternativeServiceList& broken_alternative_service_list,
    size_t max_broken_alternative_services,
    const RecentlyBrokenAlternativeServices&
        recently_broken_alternative_services,
    base::Value::Dict& http_server_properties_dict) {}

void HttpServerPropertiesManager::OnHttpServerPropertiesLoaded() {}

}  // namespace net