#include "net/quic/network_connection.h"
#include "base/logging.h"
#include "net/base/network_interfaces.h"
namespace net {
NetworkConnection::NetworkConnection() {
NetworkChangeNotifier::AddIPAddressObserver(this);
NetworkChangeNotifier::AddConnectionTypeObserver(this);
OnIPAddressChanged();
}
NetworkConnection::~NetworkConnection() {
NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
void NetworkConnection::OnIPAddressChanged() {
OnConnectionTypeChanged(NetworkChangeNotifier::GetConnectionType());
}
void NetworkConnection::OnConnectionTypeChanged(
NetworkChangeNotifier::ConnectionType type) {
DVLOG(1) << "Updating NetworkConnection's Cached Data";
connection_type_ = type;
connection_description_ = NetworkChangeNotifier::ConnectionTypeToString(type);
if (connection_type_ != NetworkChangeNotifier::CONNECTION_UNKNOWN &&
connection_type_ != NetworkChangeNotifier::CONNECTION_WIFI) {
return;
}
WifiPHYLayerProtocol wifi_type = GetWifiPHYLayerProtocol();
switch (wifi_type) {
case WIFI_PHY_LAYER_PROTOCOL_NONE:
break;
case WIFI_PHY_LAYER_PROTOCOL_ANCIENT:
connection_description_ = "CONNECTION_WIFI_ANCIENT";
break;
case WIFI_PHY_LAYER_PROTOCOL_A:
connection_description_ = "CONNECTION_WIFI_802.11a";
break;
case WIFI_PHY_LAYER_PROTOCOL_B:
connection_description_ = "CONNECTION_WIFI_802.11b";
break;
case WIFI_PHY_LAYER_PROTOCOL_G:
connection_description_ = "CONNECTION_WIFI_802.11g";
break;
case WIFI_PHY_LAYER_PROTOCOL_N:
connection_description_ = "CONNECTION_WIFI_802.11n";
break;
case WIFI_PHY_LAYER_PROTOCOL_AC:
connection_description_ = "CONNECTION_WIFI_802.11ac";
break;
case WIFI_PHY_LAYER_PROTOCOL_AD:
connection_description_ = "CONNECTION_WIFI_802.11ad";
break;
case WIFI_PHY_LAYER_PROTOCOL_AX:
connection_description_ = "CONNECTION_WIFI_802.11ax";
break;
case WIFI_PHY_LAYER_PROTOCOL_UNKNOWN:
break;
}
}
}