diff options
Diffstat (limited to 'chromium/net/base/network_change_notifier.cc')
-rw-r--r-- | chromium/net/base/network_change_notifier.cc | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/chromium/net/base/network_change_notifier.cc b/chromium/net/base/network_change_notifier.cc index 387c83430fa..1a993852691 100644 --- a/chromium/net/base/network_change_notifier.cc +++ b/chromium/net/base/network_change_notifier.cc @@ -33,13 +33,11 @@ #if BUILDFLAG(IS_WIN) #include "net/base/network_change_notifier_win.h" -// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch -// of lacros-chrome is complete. -#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) +#elif BUILDFLAG(IS_LINUX) #include "net/base/network_change_notifier_linux.h" #elif BUILDFLAG(IS_APPLE) #include "net/base/network_change_notifier_mac.h" -#elif BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_ANDROID) +#elif BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) #include "net/base/network_change_notifier_posix.h" #elif BUILDFLAG(IS_FUCHSIA) #include "net/base/network_change_notifier_fuchsia.h" @@ -68,7 +66,7 @@ base::Lock& NetworkChangeNotifierCreationLock() { class MockNetworkChangeNotifier : public NetworkChangeNotifier { public: - MockNetworkChangeNotifier( + explicit MockNetworkChangeNotifier( std::unique_ptr<SystemDnsConfigChangeNotifier> dns_config_notifier) : NetworkChangeNotifier( NetworkChangeCalculatorParams(), @@ -92,9 +90,6 @@ class MockNetworkChangeNotifier : public NetworkChangeNotifier { // static bool NetworkChangeNotifier::test_notifications_only_ = false; -// static -const NetworkChangeNotifier::NetworkHandle - NetworkChangeNotifier::kInvalidNetworkHandle = -1; NetworkChangeNotifier::NetworkChangeCalculatorParams:: NetworkChangeCalculatorParams() = default; @@ -192,33 +187,37 @@ class NetworkChangeNotifier::NetworkChangeCalculator class NetworkChangeNotifier::ObserverList { public: ObserverList() - : ip_address_observer_list_(new base::ObserverListThreadSafe< - NetworkChangeNotifier::IPAddressObserver>( - base::ObserverListPolicy::EXISTING_ONLY)), + : ip_address_observer_list_( + base::MakeRefCounted<base::ObserverListThreadSafe< + NetworkChangeNotifier::IPAddressObserver>>( + base::ObserverListPolicy::EXISTING_ONLY)), connection_type_observer_list_( - new base::ObserverListThreadSafe< - NetworkChangeNotifier::ConnectionTypeObserver>( + base::MakeRefCounted<base::ObserverListThreadSafe< + NetworkChangeNotifier::ConnectionTypeObserver>>( + base::ObserverListPolicy::EXISTING_ONLY)), + resolver_state_observer_list_( + base::MakeRefCounted<base::ObserverListThreadSafe< + NetworkChangeNotifier::DNSObserver>>( base::ObserverListPolicy::EXISTING_ONLY)), - resolver_state_observer_list_(new base::ObserverListThreadSafe< - NetworkChangeNotifier::DNSObserver>( - base::ObserverListPolicy::EXISTING_ONLY)), network_change_observer_list_( - new base::ObserverListThreadSafe< - NetworkChangeNotifier::NetworkChangeObserver>( + base::MakeRefCounted<base::ObserverListThreadSafe< + NetworkChangeNotifier::NetworkChangeObserver>>( base::ObserverListPolicy::EXISTING_ONLY)), max_bandwidth_observer_list_( - new base::ObserverListThreadSafe< - NetworkChangeNotifier::MaxBandwidthObserver>( + base::MakeRefCounted<base::ObserverListThreadSafe< + NetworkChangeNotifier::MaxBandwidthObserver>>( + base::ObserverListPolicy::EXISTING_ONLY)), + network_observer_list_( + base::MakeRefCounted<base::ObserverListThreadSafe< + NetworkChangeNotifier::NetworkObserver>>( base::ObserverListPolicy::EXISTING_ONLY)), - network_observer_list_(new base::ObserverListThreadSafe< - NetworkChangeNotifier::NetworkObserver>( - base::ObserverListPolicy::EXISTING_ONLY)), connection_cost_observer_list_( - new base::ObserverListThreadSafe< - NetworkChangeNotifier::ConnectionCostObserver>( + base::MakeRefCounted<base::ObserverListThreadSafe< + NetworkChangeNotifier::ConnectionCostObserver>>( base::ObserverListPolicy::EXISTING_ONLY)), default_network_active_observer_list_( - new base::ObserverListThreadSafe<DefaultNetworkActiveObserver>( + base::MakeRefCounted< + base::ObserverListThreadSafe<DefaultNetworkActiveObserver>>( base::ObserverListPolicy::EXISTING_ONLY)) {} ObserverList(const ObserverList&) = delete; @@ -316,10 +315,10 @@ std::unique_ptr<NetworkChangeNotifier> NetworkChangeNotifier::CreateIfNeeded( // service in a separate process. return std::make_unique<NetworkChangeNotifierPosix>(initial_type, initial_subtype); -#elif BUILDFLAG(IS_CHROMEOS_ASH) +#elif BUILDFLAG(IS_CHROMEOS) return std::make_unique<NetworkChangeNotifierPosix>(initial_type, initial_subtype); -#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) +#elif BUILDFLAG(IS_LINUX) return std::make_unique<NetworkChangeNotifierLinux>( std::unordered_set<std::string>()); #elif BUILDFLAG(IS_APPLE) @@ -329,7 +328,7 @@ std::unique_ptr<NetworkChangeNotifier> NetworkChangeNotifier::CreateIfNeeded( /*require_wlan=*/false); #else NOTIMPLEMENTED(); - return NULL; + return nullptr; #endif } @@ -467,7 +466,8 @@ void NetworkChangeNotifier::GetConnectedNetworks(NetworkList* network_list) { // static NetworkChangeNotifier::ConnectionType -NetworkChangeNotifier::GetNetworkConnectionType(NetworkHandle network) { +NetworkChangeNotifier::GetNetworkConnectionType( + handles::NetworkHandle network) { DCHECK(AreNetworkHandlesSupported()); return g_network_change_notifier ? g_network_change_notifier->GetCurrentNetworkConnectionType( @@ -476,12 +476,11 @@ NetworkChangeNotifier::GetNetworkConnectionType(NetworkHandle network) { } // static -NetworkChangeNotifier::NetworkHandle -NetworkChangeNotifier::GetDefaultNetwork() { +handles::NetworkHandle NetworkChangeNotifier::GetDefaultNetwork() { DCHECK(AreNetworkHandlesSupported()); return g_network_change_notifier ? g_network_change_notifier->GetCurrentDefaultNetwork() - : kInvalidNetworkHandle; + : handles::kInvalidNetworkHandle; } // static @@ -522,8 +521,9 @@ const char* NetworkChangeNotifier::ConnectionTypeToString( // static const internal::AddressTrackerLinux* NetworkChangeNotifier::GetAddressTracker() { - return g_network_change_notifier ? - g_network_change_notifier->GetAddressTrackerInternal() : NULL; + return g_network_change_notifier + ? g_network_change_notifier->GetAddressTrackerInternal() + : nullptr; } #endif @@ -568,29 +568,29 @@ NetworkChangeNotifier::ConnectionTypeFromInterfaceList( const NetworkInterfaceList& interfaces) { bool first = true; ConnectionType result = CONNECTION_NONE; - for (size_t i = 0; i < interfaces.size(); ++i) { + for (const auto& network_interface : interfaces) { #if BUILDFLAG(IS_WIN) - if (interfaces[i].friendly_name == "Teredo Tunneling Pseudo-Interface") + if (network_interface.friendly_name == "Teredo Tunneling Pseudo-Interface") continue; #endif #if BUILDFLAG(IS_APPLE) // Ignore link-local addresses as they aren't globally routable. // Mac assigns these to disconnected interfaces like tunnel interfaces // ("utun"), airdrop interfaces ("awdl"), and ethernet ports ("en"). - if (interfaces[i].address.IsLinkLocal()) + if (network_interface.address.IsLinkLocal()) continue; #endif // Remove VMware network interfaces as they're internal and should not be // used to determine the network connection type. - if (base::ToLowerASCII(interfaces[i].friendly_name).find("vmnet") != + if (base::ToLowerASCII(network_interface.friendly_name).find("vmnet") != std::string::npos) { continue; } if (first) { first = false; - result = interfaces[i].type; - } else if (result != interfaces[i].type) { + result = network_interface.type; + } else if (result != network_interface.type) { return CONNECTION_UNKNOWN; } } @@ -865,7 +865,7 @@ NetworkChangeNotifier::NetworkChangeNotifier( #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) const internal::AddressTrackerLinux* NetworkChangeNotifier::GetAddressTrackerInternal() const { - return NULL; + return nullptr; } #endif @@ -908,13 +908,12 @@ void NetworkChangeNotifier::GetCurrentConnectedNetworks( NetworkChangeNotifier::ConnectionType NetworkChangeNotifier::GetCurrentNetworkConnectionType( - NetworkHandle network) const { + handles::NetworkHandle network) const { return CONNECTION_UNKNOWN; } -NetworkChangeNotifier::NetworkHandle -NetworkChangeNotifier::GetCurrentDefaultNetwork() const { - return kInvalidNetworkHandle; +handles::NetworkHandle NetworkChangeNotifier::GetCurrentDefaultNetwork() const { + return handles::kInvalidNetworkHandle; } SystemDnsConfigChangeNotifier* @@ -975,7 +974,7 @@ void NetworkChangeNotifier::NotifyObserversOfDNSChange() { // static void NetworkChangeNotifier::NotifyObserversOfSpecificNetworkChange( NetworkChangeType type, - NetworkHandle network) { + handles::NetworkHandle network) { if (g_network_change_notifier && !NetworkChangeNotifier::test_notifications_only_) { g_network_change_notifier->NotifyObserversOfSpecificNetworkChangeImpl( @@ -1042,7 +1041,7 @@ void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl( void NetworkChangeNotifier::NotifyObserversOfSpecificNetworkChangeImpl( NetworkChangeType type, - NetworkHandle network) { + handles::NetworkHandle network) { switch (type) { case NetworkChangeType::kConnected: GetObserverList().network_observer_list_->Notify( |