#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
#include <memory>
#include "base/containers/contains.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "net/nqe/effective_connection_type.h"
#include "net/nqe/network_quality_estimator_params.h"
#include "services/network/public/cpp/client_hints.h"
#include "third_party/blink/public/common/client_hints/client_hints.h"
#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom-blink.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
#include "third_party/blink/renderer/platform/wtf/threading.h"
#include "third_party/blink/renderer/platform/wtf/wtf.h"
namespace blink {
EffectiveConnectionType;
namespace {
const base::TimeDelta kTypicalHttpRttEffectiveConnectionType
[static_cast<size_t>(WebEffectiveConnectionType::kMaxValue) + 1] = …;
const double kTypicalDownlinkMbpsEffectiveConnectionType
[static_cast<size_t>(WebEffectiveConnectionType::kMaxValue) + 1] = …;
}
NetworkStateNotifier& GetNetworkStateNotifier() { … }
NetworkStateNotifier::ScopedNotifier::ScopedNotifier(
NetworkStateNotifier& notifier)
: … { … }
NetworkStateNotifier::ScopedNotifier::~ScopedNotifier() { … }
NetworkStateNotifier::NetworkStateObserverHandle::NetworkStateObserverHandle(
NetworkStateNotifier* notifier,
NetworkStateNotifier::ObserverType type,
NetworkStateNotifier::NetworkStateObserver* observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: … { … }
NetworkStateNotifier::NetworkStateObserverHandle::
~NetworkStateObserverHandle() { … }
void NetworkStateNotifier::SetOnLine(bool on_line) { … }
void NetworkStateNotifier::SetWebConnection(WebConnectionType type,
double max_bandwidth_mbps) { … }
void NetworkStateNotifier::SetNetworkQuality(WebEffectiveConnectionType type,
base::TimeDelta http_rtt,
base::TimeDelta transport_rtt,
int downlink_throughput_kbps) { … }
void NetworkStateNotifier::SetNetworkQualityWebHoldback(
WebEffectiveConnectionType type) { … }
std::unique_ptr<NetworkStateNotifier::NetworkStateObserverHandle>
NetworkStateNotifier::AddConnectionObserver(
NetworkStateObserver* observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void NetworkStateNotifier::SetSaveDataEnabled(bool enabled) { … }
std::unique_ptr<NetworkStateNotifier::NetworkStateObserverHandle>
NetworkStateNotifier::AddOnLineObserver(
NetworkStateObserver* observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void NetworkStateNotifier::SetNetworkConnectionInfoOverride(
bool on_line,
WebConnectionType type,
std::optional<WebEffectiveConnectionType> effective_type,
int64_t http_rtt_msec,
double max_bandwidth_mbps) { … }
void NetworkStateNotifier::SetSaveDataEnabledOverride(bool enabled) { … }
void NetworkStateNotifier::ClearOverride() { … }
void NetworkStateNotifier::NotifyObservers(ObserverListMap& map,
ObserverType type,
const NetworkState& state) { … }
void NetworkStateNotifier::NotifyObserverOnTaskRunner(
MayBeDangling<NetworkStateObserver> observer,
ObserverType type,
const NetworkState& state) { … }
NetworkStateNotifier::ObserverListMap& NetworkStateNotifier::GetObserverMapFor(
ObserverType type) { … }
void NetworkStateNotifier::AddObserverToMap(
ObserverListMap& map,
NetworkStateObserver* observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void NetworkStateNotifier::RemoveObserver(
ObserverType type,
NetworkStateObserver* observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
String NetworkStateNotifier::EffectiveConnectionTypeToString(
WebEffectiveConnectionType type) { … }
double NetworkStateNotifier::GetRandomMultiplier(const String& host) const { … }
uint32_t NetworkStateNotifier::RoundRtt(
const String& host,
const std::optional<base::TimeDelta>& rtt) const { … }
double NetworkStateNotifier::RoundMbps(
const String& host,
const std::optional<double>& downlink_mbps) const { … }
std::optional<WebEffectiveConnectionType>
NetworkStateNotifier::GetWebHoldbackEffectiveType() const { … }
std::optional<base::TimeDelta> NetworkStateNotifier::GetWebHoldbackHttpRtt()
const { … }
std::optional<double>
NetworkStateNotifier::GetWebHoldbackDownlinkThroughputMbps() const { … }
void NetworkStateNotifier::GetMetricsWithWebHoldback(
WebConnectionType* type,
double* downlink_max_mbps,
WebEffectiveConnectionType* effective_type,
std::optional<base::TimeDelta>* http_rtt,
std::optional<double>* downlink_mbps,
bool* save_data) const { … }
}