chromium/third_party/blink/renderer/platform/network/network_state_notifier.cc

/*
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#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 {

// Typical HTTP RTT value corresponding to a given WebEffectiveConnectionType
// value. Taken from
// https://cs.chromium.org/chromium/src/net/nqe/network_quality_estimator_params.cc.
const base::TimeDelta kTypicalHttpRttEffectiveConnectionType
    [static_cast<size_t>(WebEffectiveConnectionType::kMaxValue) + 1] =;

// Typical downlink throughput (in Mbps) value corresponding to a given
// WebEffectiveConnectionType value. Taken from
// https://cs.chromium.org/chromium/src/net/nqe/network_quality_estimator_params.cc.
const double kTypicalDownlinkMbpsEffectiveConnectionType
    [static_cast<size_t>(WebEffectiveConnectionType::kMaxValue) + 1] =;

}  // namespace

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) {}

// static
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 {}

}  // namespace blink