summaryrefslogtreecommitdiff
path: root/chromium/net/quic/network_connection.cc
blob: 9c36d366445df97ca35093867f2ff601054af22c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/quic/network_connection.h"

#include "base/logging.h"
#include "net/base/network_interfaces.h"

namespace net {

NetworkConnection::NetworkConnection()
    : connection_type_(NetworkChangeNotifier::CONNECTION_UNKNOWN),
      connection_description_(nullptr) {
  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;
  }

  // This function only seems usefully defined on Windows currently.
  WifiPHYLayerProtocol wifi_type = GetWifiPHYLayerProtocol();
  switch (wifi_type) {
    case WIFI_PHY_LAYER_PROTOCOL_NONE:
      // No wifi support or no associated AP.
      break;
    case WIFI_PHY_LAYER_PROTOCOL_ANCIENT:
      // An obsolete modes introduced by the original 802.11, e.g. IR, FHSS.
      connection_description_ = "CONNECTION_WIFI_ANCIENT";
      break;
    case WIFI_PHY_LAYER_PROTOCOL_A:
      // 802.11a, OFDM-based rates.
      connection_description_ = "CONNECTION_WIFI_802.11a";
      break;
    case WIFI_PHY_LAYER_PROTOCOL_B:
      // 802.11b, DSSS or HR DSSS.
      connection_description_ = "CONNECTION_WIFI_802.11b";
      break;
    case WIFI_PHY_LAYER_PROTOCOL_G:
      // 802.11g, same rates as 802.11a but compatible with 802.11b.
      connection_description_ = "CONNECTION_WIFI_802.11g";
      break;
    case WIFI_PHY_LAYER_PROTOCOL_N:
      // 802.11n, HT rates.
      connection_description_ = "CONNECTION_WIFI_802.11n";
      break;
    case WIFI_PHY_LAYER_PROTOCOL_UNKNOWN:
      // Unclassified mode or failure to identify.
      break;
  }
}

}  // namespace net