#include "net/base/network_change_notifier.h"
#include <limits>
#include <optional>
#include <string>
#include <unordered_set>
#include <utility>
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/observer_list.h"
#include "base/sequence_checker.h"
#include "base/strings/string_util.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "net/base/network_change_notifier_factory.h"
#include "net/base/network_interfaces.h"
#include "net/base/url_util.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_config_service.h"
#include "net/dns/system_dns_config_change_notifier.h"
#include "net/url_request/url_request.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_WIN)
#include "net/base/network_change_notifier_win.h"
#elif BUILDFLAG(IS_LINUX)
#include "net/base/network_change_notifier_linux.h"
#elif BUILDFLAG(IS_APPLE)
#include "net/base/network_change_notifier_apple.h"
#elif BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
#include "net/base/network_change_notifier_passive.h"
#elif BUILDFLAG(IS_FUCHSIA)
#include "net/base/network_change_notifier_fuchsia.h"
#endif
namespace net {
namespace {
NetworkChangeNotifier* g_network_change_notifier = …;
NetworkChangeNotifierFactory* g_network_change_notifier_factory = …;
base::Lock& NetworkChangeNotifierCreationLock() { … }
class MockNetworkChangeNotifier : public NetworkChangeNotifier { … };
}
bool NetworkChangeNotifier::test_notifications_only_ = …;
NetworkChangeNotifier::NetworkChangeCalculatorParams::
NetworkChangeCalculatorParams() = default;
class NetworkChangeNotifier::NetworkChangeCalculator
: public ConnectionTypeObserver,
public ConnectionCostObserver,
public IPAddressObserver { … };
class NetworkChangeNotifier::ObserverList { … };
class NetworkChangeNotifier::SystemDnsConfigObserver
: public SystemDnsConfigChangeNotifier::Observer { … };
void NetworkChangeNotifier::ClearGlobalPointer() { … }
NetworkChangeNotifier::~NetworkChangeNotifier() { … }
NetworkChangeNotifierFactory* NetworkChangeNotifier::GetFactory() { … }
void NetworkChangeNotifier::SetFactory(
NetworkChangeNotifierFactory* factory) { … }
std::unique_ptr<NetworkChangeNotifier> NetworkChangeNotifier::CreateIfNeeded(
NetworkChangeNotifier::ConnectionType initial_type,
NetworkChangeNotifier::ConnectionSubtype initial_subtype) { … }
NetworkChangeNotifier::ConnectionCost
NetworkChangeNotifier::GetConnectionCost() { … }
NetworkChangeNotifier::ConnectionType
NetworkChangeNotifier::GetConnectionType() { … }
NetworkChangeNotifier::ConnectionSubtype
NetworkChangeNotifier::GetConnectionSubtype() { … }
void NetworkChangeNotifier::GetMaxBandwidthAndConnectionType(
double* max_bandwidth_mbps,
ConnectionType* connection_type) { … }
double NetworkChangeNotifier::GetMaxBandwidthMbpsForConnectionSubtype(
ConnectionSubtype subtype) { … }
bool NetworkChangeNotifier::AreNetworkHandlesSupported() { … }
void NetworkChangeNotifier::GetConnectedNetworks(NetworkList* network_list) { … }
NetworkChangeNotifier::ConnectionType
NetworkChangeNotifier::GetNetworkConnectionType(
handles::NetworkHandle network) { … }
handles::NetworkHandle NetworkChangeNotifier::GetDefaultNetwork() { … }
SystemDnsConfigChangeNotifier*
NetworkChangeNotifier::GetSystemDnsConfigNotifier() { … }
bool NetworkChangeNotifier::IsDefaultNetworkActive() { … }
base::cstring_view NetworkChangeNotifier::ConnectionTypeToString(
ConnectionType type) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
AddressMapOwnerLinux* NetworkChangeNotifier::GetAddressMapOwner() { … }
#endif
#if BUILDFLAG(IS_FUCHSIA)
const internal::NetworkInterfaceCache*
NetworkChangeNotifier::GetNetworkInterfaceCache() {
return g_network_change_notifier
? g_network_change_notifier->GetNetworkInterfaceCacheInternal()
: nullptr;
}
#endif
bool NetworkChangeNotifier::IsOffline() { … }
bool NetworkChangeNotifier::IsConnectionCellular(ConnectionType type) { … }
NetworkChangeNotifier::ConnectionType
NetworkChangeNotifier::ConnectionTypeFromInterfaces() { … }
NetworkChangeNotifier::ConnectionType
NetworkChangeNotifier::ConnectionTypeFromInterfaceList(
const NetworkInterfaceList& interfaces) { … }
std::unique_ptr<NetworkChangeNotifier>
NetworkChangeNotifier::CreateMockIfNeeded() { … }
NetworkChangeNotifier::IPAddressObserver::IPAddressObserver() = default;
NetworkChangeNotifier::IPAddressObserver::~IPAddressObserver() = default;
NetworkChangeNotifier::ConnectionTypeObserver::ConnectionTypeObserver() =
default;
NetworkChangeNotifier::ConnectionTypeObserver::~ConnectionTypeObserver() =
default;
NetworkChangeNotifier::DNSObserver::DNSObserver() = default;
NetworkChangeNotifier::DNSObserver::~DNSObserver() = default;
NetworkChangeNotifier::NetworkChangeObserver::NetworkChangeObserver() = default;
NetworkChangeNotifier::NetworkChangeObserver::~NetworkChangeObserver() =
default;
NetworkChangeNotifier::MaxBandwidthObserver::MaxBandwidthObserver() = default;
NetworkChangeNotifier::MaxBandwidthObserver::~MaxBandwidthObserver() = default;
NetworkChangeNotifier::NetworkObserver::NetworkObserver() = default;
NetworkChangeNotifier::NetworkObserver::~NetworkObserver() = default;
NetworkChangeNotifier::ConnectionCostObserver::ConnectionCostObserver() =
default;
NetworkChangeNotifier::ConnectionCostObserver::~ConnectionCostObserver() =
default;
NetworkChangeNotifier::DefaultNetworkActiveObserver::
DefaultNetworkActiveObserver() = default;
NetworkChangeNotifier::DefaultNetworkActiveObserver::
~DefaultNetworkActiveObserver() = default;
void NetworkChangeNotifier::AddIPAddressObserver(IPAddressObserver* observer) { … }
void NetworkChangeNotifier::AddConnectionTypeObserver(
ConnectionTypeObserver* observer) { … }
void NetworkChangeNotifier::AddDNSObserver(DNSObserver* observer) { … }
void NetworkChangeNotifier::AddNetworkChangeObserver(
NetworkChangeObserver* observer) { … }
void NetworkChangeNotifier::AddMaxBandwidthObserver(
MaxBandwidthObserver* observer) { … }
void NetworkChangeNotifier::AddNetworkObserver(NetworkObserver* observer) { … }
void NetworkChangeNotifier::AddConnectionCostObserver(
ConnectionCostObserver* observer) { … }
void NetworkChangeNotifier::AddDefaultNetworkActiveObserver(
DefaultNetworkActiveObserver* observer) { … }
void NetworkChangeNotifier::RemoveIPAddressObserver(
IPAddressObserver* observer) { … }
void NetworkChangeNotifier::RemoveConnectionTypeObserver(
ConnectionTypeObserver* observer) { … }
void NetworkChangeNotifier::RemoveDNSObserver(DNSObserver* observer) { … }
void NetworkChangeNotifier::RemoveNetworkChangeObserver(
NetworkChangeObserver* observer) { … }
void NetworkChangeNotifier::RemoveMaxBandwidthObserver(
MaxBandwidthObserver* observer) { … }
void NetworkChangeNotifier::RemoveNetworkObserver(NetworkObserver* observer) { … }
void NetworkChangeNotifier::RemoveConnectionCostObserver(
ConnectionCostObserver* observer) { … }
void NetworkChangeNotifier::RemoveDefaultNetworkActiveObserver(
DefaultNetworkActiveObserver* observer) { … }
void NetworkChangeNotifier::TriggerNonSystemDnsChange() { … }
void NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests() { … }
void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
ConnectionType type) { … }
void NetworkChangeNotifier::NotifyObserversOfDNSChangeForTests() { … }
void NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(
ConnectionType type) { … }
void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeForTests(
double max_bandwidth_mbps,
ConnectionType type) { … }
void NetworkChangeNotifier::NotifyObserversOfConnectionCostChangeForTests(
ConnectionCost cost) { … }
void NetworkChangeNotifier::NotifyObserversOfDefaultNetworkActiveForTests() { … }
void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) { … }
NetworkChangeNotifier::NetworkChangeNotifier(
const NetworkChangeCalculatorParams& params
,
SystemDnsConfigChangeNotifier* system_dns_config_notifier ,
bool omit_observers_in_constructor_for_testing )
: … { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
AddressMapOwnerLinux* NetworkChangeNotifier::GetAddressMapOwnerInternal() { … }
#endif
#if BUILDFLAG(IS_FUCHSIA)
const internal::NetworkInterfaceCache*
NetworkChangeNotifier::GetNetworkInterfaceCacheInternal() const {
return nullptr;
}
#endif
NetworkChangeNotifier::ConnectionCost
NetworkChangeNotifier::GetCurrentConnectionCost() { … }
NetworkChangeNotifier::ConnectionSubtype
NetworkChangeNotifier::GetCurrentConnectionSubtype() const { … }
void NetworkChangeNotifier::GetCurrentMaxBandwidthAndConnectionType(
double* max_bandwidth_mbps,
ConnectionType* connection_type) const { … }
bool NetworkChangeNotifier::AreNetworkHandlesCurrentlySupported() const { … }
void NetworkChangeNotifier::GetCurrentConnectedNetworks(
NetworkList* network_list) const { … }
NetworkChangeNotifier::ConnectionType
NetworkChangeNotifier::GetCurrentNetworkConnectionType(
handles::NetworkHandle network) const { … }
handles::NetworkHandle NetworkChangeNotifier::GetCurrentDefaultNetwork() const { … }
SystemDnsConfigChangeNotifier*
NetworkChangeNotifier::GetCurrentSystemDnsConfigNotifier() { … }
bool NetworkChangeNotifier::IsDefaultNetworkActiveInternal() { … }
void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() { … }
void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() { … }
void NetworkChangeNotifier::NotifyObserversOfNetworkChange(
ConnectionType type) { … }
void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(
double max_bandwidth_mbps,
ConnectionType type) { … }
void NetworkChangeNotifier::NotifyObserversOfDNSChange() { … }
void NetworkChangeNotifier::NotifyObserversOfSpecificNetworkChange(
NetworkChangeType type,
handles::NetworkHandle network) { … }
void NetworkChangeNotifier::NotifyObserversOfConnectionCostChange() { … }
void NetworkChangeNotifier::NotifyObserversOfDefaultNetworkActive() { … }
void NetworkChangeNotifier::StopSystemDnsConfigNotifier() { … }
void NetworkChangeNotifier::NotifyObserversOfIPAddressChangeImpl() { … }
void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeImpl(
ConnectionType type) { … }
void NetworkChangeNotifier::NotifyObserversOfNetworkChangeImpl(
ConnectionType type) { … }
void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() { … }
void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl(
double max_bandwidth_mbps,
ConnectionType type) { … }
void NetworkChangeNotifier::NotifyObserversOfSpecificNetworkChangeImpl(
NetworkChangeType type,
handles::NetworkHandle network) { … }
void NetworkChangeNotifier::NotifyObserversOfConnectionCostChangeImpl(
ConnectionCost cost) { … }
void NetworkChangeNotifier::NotifyObserversOfDefaultNetworkActiveImpl() { … }
NetworkChangeNotifier::DisableForTest::DisableForTest()
: … { … }
NetworkChangeNotifier::DisableForTest::~DisableForTest() { … }
NetworkChangeNotifier::ObserverList& NetworkChangeNotifier::GetObserverList() { … }
}