network_connection.cc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "net/quic/network_connection.h"
  5. #include "base/logging.h"
  6. #include "net/base/network_interfaces.h"
  7. namespace net {
  8. NetworkConnection::NetworkConnection() {
  9. NetworkChangeNotifier::AddIPAddressObserver(this);
  10. NetworkChangeNotifier::AddConnectionTypeObserver(this);
  11. OnIPAddressChanged();
  12. }
  13. NetworkConnection::~NetworkConnection() {
  14. NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
  15. NetworkChangeNotifier::RemoveIPAddressObserver(this);
  16. }
  17. void NetworkConnection::OnIPAddressChanged() {
  18. OnConnectionTypeChanged(NetworkChangeNotifier::GetConnectionType());
  19. }
  20. void NetworkConnection::OnConnectionTypeChanged(
  21. NetworkChangeNotifier::ConnectionType type) {
  22. DVLOG(1) << "Updating NetworkConnection's Cached Data";
  23. connection_type_ = type;
  24. connection_description_ = NetworkChangeNotifier::ConnectionTypeToString(type);
  25. if (connection_type_ != NetworkChangeNotifier::CONNECTION_UNKNOWN &&
  26. connection_type_ != NetworkChangeNotifier::CONNECTION_WIFI) {
  27. return;
  28. }
  29. // This function only seems usefully defined on Windows currently.
  30. WifiPHYLayerProtocol wifi_type = GetWifiPHYLayerProtocol();
  31. switch (wifi_type) {
  32. case WIFI_PHY_LAYER_PROTOCOL_NONE:
  33. // No wifi support or no associated AP.
  34. break;
  35. case WIFI_PHY_LAYER_PROTOCOL_ANCIENT:
  36. // An obsolete modes introduced by the original 802.11, e.g. IR, FHSS.
  37. connection_description_ = "CONNECTION_WIFI_ANCIENT";
  38. break;
  39. case WIFI_PHY_LAYER_PROTOCOL_A:
  40. // 802.11a, OFDM-based rates.
  41. connection_description_ = "CONNECTION_WIFI_802.11a";
  42. break;
  43. case WIFI_PHY_LAYER_PROTOCOL_B:
  44. // 802.11b, DSSS or HR DSSS.
  45. connection_description_ = "CONNECTION_WIFI_802.11b";
  46. break;
  47. case WIFI_PHY_LAYER_PROTOCOL_G:
  48. // 802.11g, same rates as 802.11a but compatible with 802.11b.
  49. connection_description_ = "CONNECTION_WIFI_802.11g";
  50. break;
  51. case WIFI_PHY_LAYER_PROTOCOL_N:
  52. // 802.11n, HT rates.
  53. connection_description_ = "CONNECTION_WIFI_802.11n";
  54. break;
  55. case WIFI_PHY_LAYER_PROTOCOL_AC:
  56. // 802.11ac
  57. connection_description_ = "CONNECTION_WIFI_802.11ac";
  58. break;
  59. case WIFI_PHY_LAYER_PROTOCOL_AD:
  60. // 802.11ad
  61. connection_description_ = "CONNECTION_WIFI_802.11ad";
  62. break;
  63. case WIFI_PHY_LAYER_PROTOCOL_AX:
  64. // 802.11ax
  65. connection_description_ = "CONNECTION_WIFI_802.11ax";
  66. break;
  67. case WIFI_PHY_LAYER_PROTOCOL_UNKNOWN:
  68. // Unclassified mode or failure to identify.
  69. break;
  70. }
  71. }
  72. } // namespace net