forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetwork_connection.h
61 lines (48 loc) · 2.33 KB
/
network_connection.h
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
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_QUIC_NETWORK_CONNECTION_H_
#define NET_QUIC_NETWORK_CONNECTION_H_
#include "net/base/net_export.h"
#include "net/base/network_change_notifier.h"
namespace net {
// This class stores information about the current network type and
// provides a textual description of it.
class NET_EXPORT NetworkConnection
: public NetworkChangeNotifier::IPAddressObserver,
public NetworkChangeNotifier::ConnectionTypeObserver {
public:
NetworkConnection();
NetworkConnection(const NetworkConnection&) = delete;
NetworkConnection& operator=(const NetworkConnection&) = delete;
~NetworkConnection() override;
// Returns the underlying connection type.
NetworkChangeNotifier::ConnectionType connection_type() {
return connection_type_;
}
// Return a string equivalent of current connection type. Callers don't need
// to make a copy of the returned C-string value. If the connection type is
// CONNECTION_WIFI, then we'll tease out some details when we are on WiFi, and
// hopefully leave only ethernet (with no WiFi available) in the
// CONNECTION_UNKNOWN category. This *might* err if there is both ethernet,
// as well as WiFi, where WiFi was not being used that much. Most platforms
// don't distinguish Wifi vs Etherenet, and call everything CONNECTION_UNKNOWN
// :-(. Fo non CONNECTIION_WIFI, this returns the C-string returned by
// NetworkChangeNotifier::ConnectionTypeToString.
const char* connection_description() { return connection_description_; }
// NetworkChangeNotifier::IPAddressObserver methods:
void OnIPAddressChanged() override;
// NetworkChangeNotifier::ConnectionTypeObserver methods:
void OnConnectionTypeChanged(
NetworkChangeNotifier::ConnectionType type) override;
private:
// Cache the connection type to avoid calling the potentially expensive
// NetworkChangeNotifier::GetConnectionType() function.
NetworkChangeNotifier::ConnectionType connection_type_ =
NetworkChangeNotifier::CONNECTION_UNKNOWN;
// Cache the connection description string to avoid calling the expensive
// GetWifiPHYLayerProtocol() function.
const char* connection_description_ = nullptr;
};
} // namespace net
#endif // NET_QUIC_NETWORK_CONNECTION_H_