xref: /aosp_15_r20/external/cronet/net/nqe/network_id.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_NQE_NETWORK_ID_H_
6 #define NET_NQE_NETWORK_ID_H_
7 
8 #include <string>
9 
10 #include "net/base/net_export.h"
11 #include "net/base/network_change_notifier.h"
12 
13 namespace net::nqe::internal {
14 
15 // NetworkID is used to uniquely identify a network.
16 // For the purpose of network quality estimation and caching, a network is
17 // uniquely identified by a combination of |type| and
18 // |id|. This approach is unable to distinguish networks with
19 // same name (e.g., different Wi-Fi networks with same SSID).
20 // This is a protected member to expose it to tests.
21 struct NET_EXPORT_PRIVATE NetworkID {
22   static NetworkID FromString(const std::string& network_id);
23 
24   NetworkID(NetworkChangeNotifier::ConnectionType type,
25             const std::string& id,
26             int32_t signal_strength);
27   NetworkID(const NetworkID& other);
28   ~NetworkID();
29 
30   bool operator==(const NetworkID& other) const;
31 
32   bool operator!=(const NetworkID& other) const;
33 
34   NetworkID& operator=(const NetworkID& other);
35 
36   // Overloaded to support ordered collections.
37   bool operator<(const NetworkID& other) const;
38 
39   std::string ToString() const;
40 
41   // Connection type of the network.
42   NetworkChangeNotifier::ConnectionType type;
43 
44   // Name of this network. This is set to:
45   // - Wi-Fi SSID if the device is connected to a Wi-Fi access point and the
46   //   SSID name is available, or
47   // - MCC/MNC code of the cellular carrier if the device is connected to a
48   //   cellular network, or
49   // - "Ethernet" in case the device is connected to ethernet.
50   // - An empty string in all other cases or if the network name is not
51   //   exposed by platform APIs.
52   std::string id;
53 
54   // Signal strength of the network. Set to INT32_MIN when the value is
55   // unavailable. Otherwise, must be between 0 and 4 (both inclusive). This may
56   // take into account many different radio technology inputs. 0 represents very
57   // poor signal strength while 4 represents a very strong signal strength. The
58   // range is capped between 0 and 4 to ensure that a change in the value
59   // indicates a non-negligible change in the signal quality.
60   //
61   // TODO(crbug.com/1495477): This should use std::optional instead of a magic
62   // value.
63   int32_t signal_strength;
64 };
65 
66 }  // namespace net::nqe::internal
67 
68 #endif  // NET_NQE_NETWORK_ID_H_
69