network_id.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2016 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. #ifndef NET_NQE_NETWORK_ID_H_
  5. #define NET_NQE_NETWORK_ID_H_
  6. #include <string>
  7. #include "net/base/net_export.h"
  8. #include "net/base/network_change_notifier.h"
  9. namespace net::nqe::internal {
  10. // NetworkID is used to uniquely identify a network.
  11. // For the purpose of network quality estimation and caching, a network is
  12. // uniquely identified by a combination of |type| and
  13. // |id|. This approach is unable to distinguish networks with
  14. // same name (e.g., different Wi-Fi networks with same SSID).
  15. // This is a protected member to expose it to tests.
  16. struct NET_EXPORT_PRIVATE NetworkID {
  17. static NetworkID FromString(const std::string& network_id);
  18. NetworkID(NetworkChangeNotifier::ConnectionType type,
  19. const std::string& id,
  20. int32_t signal_strength);
  21. NetworkID(const NetworkID& other);
  22. ~NetworkID();
  23. bool operator==(const NetworkID& other) const;
  24. bool operator!=(const NetworkID& other) const;
  25. NetworkID& operator=(const NetworkID& other);
  26. // Overloaded to support ordered collections.
  27. bool operator<(const NetworkID& other) const;
  28. std::string ToString() const;
  29. // Connection type of the network.
  30. NetworkChangeNotifier::ConnectionType type;
  31. // Name of this network. This is set to:
  32. // - Wi-Fi SSID if the device is connected to a Wi-Fi access point and the
  33. // SSID name is available, or
  34. // - MCC/MNC code of the cellular carrier if the device is connected to a
  35. // cellular network, or
  36. // - "Ethernet" in case the device is connected to ethernet.
  37. // - An empty string in all other cases or if the network name is not
  38. // exposed by platform APIs.
  39. std::string id;
  40. // Signal strength of the network. Set to INT32_MIN when the value is
  41. // unavailable. Otherwise, must be between 0 and 4 (both inclusive). This may
  42. // take into account many different radio technology inputs. 0 represents very
  43. // poor signal strength while 4 represents a very strong signal strength. The
  44. // range is capped between 0 and 4 to ensure that a change in the value
  45. // indicates a non-negligible change in the signal quality.
  46. int32_t signal_strength;
  47. };
  48. } // namespace net::nqe::internal
  49. #endif // NET_NQE_NETWORK_ID_H_